Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Unexpected behaviour in sceneManager — Gideros Forum

Unexpected behaviour in sceneManager

simransimran Member
edited June 2014 in General questions
Hello,

I am using SceneManager and I have the same background on start scene as well as second level scene.
Here is piece of code:
Now, the problem is that in my second screen "plays", I have many objects on this level, but I want only one of them to move up and down on touch, the object is taken from texture pack and is basically an animation:

If i do self:getPosition and self:setPosition, all the objects in this level change their position, how do I change position of only self.anim[frame] when the user touches the screen?
--in Play.lua
self.anim =
{

Bitmap.new(pack:getTextureRegion("flappy1.png", true)),
Bitmap.new(pack:getTextureRegion("flappy2.png",true)),
}
and then something like this :
self:addChild(self.anim[1])


self: addEventListener(Event.TOUCHES_BEGIN, self.whenTouched, self)
self: addEventListener(Event.TOUCHES_END, self.whenuntouched, self)


function Play: whenTouched()
x,y= self:getPosition()
self:setPosition(x, y-20)
end
function Play: whenuntouched()
x, y= self:getPosition()
self:setPosition(x, y+20)
print("down")
end

Comments

  • something like this should work for you
    --in Play.lua
    self.anim = 
    {
     
    Bitmap.new(pack:getTextureRegion("flappy1.png", true)),
    Bitmap.new(pack:getTextureRegion("flappy2.png",true)),
    }
    and then something like this :
     
    local self.myAnim = self.anim[1] ---here is change
    self:addChild(self.myAnim)
     
     
    self: addEventListener(Event.TOUCHES_BEGIN, self.whenTouched, self)
    self: addEventListener(Event.TOUCHES_END, self.whenuntouched, self)
     
     
    function Play: whenTouched()
    x,y= self.myAnim:getPosition()---here is change
    self.myAnim:setPosition(x, y-20)---here is change
    end
    function Play: whenuntouched()
    x, y= self.myAnim:getPosition()---here is change
    self.myAnim:setPosition(x, y+20)---here is change
    print("down")
    end
    basically create reference for self.anim[1] and make any further operation on it instead of self as self may contain other bitmaps in it also
  • ar2rsawseenar2rsawseen Maintainer
    Is there any reason you two have same avatars? :)
  • No but i like this baby so i copied that

    :)
  • simransimran Member
    @hgvyas123: It did work, but the problem is when I do self.anim:getPosition() and self.anim:setPosition(), the output is not what it should be , it's an animation so only the current frame on display should be set to that position.
Sign In or Register to comment.