Okay, every time this animation gets me in trouble, maybe I am not able to understand how to handle it properly.
It's only the dummy code:
The problem is that I am able to see my first Image of bird as well as second (that are part of animation) on the screen when I jump, one below and other one above at the point of jump.This is really funny, but what's wrong? Any idea?
--in Play.lua
function Play:init()
self.anim =
{
Bitmap.new(pack:getTextureRegion("flappy1.png", true)),
Bitmap.new(pack:getTextureRegion("flappy2.png",true)),
}
self:addEventListener(Event.ENTER_FRAME,self.whenEntersFrame,self)
self: addEventListener(Event.TOUCHES_BEGIN, self.whenTouched, self)
self: addEventListener(Event.TOUCHES_END, self.whenuntouched, self)
end
function Play: whenEntersFrame()
self.subframe = self.subframe + 1
//some code to change value of self.frame
self.myAnim = self.anim[self.frame]
self:addChild(self.myAnim)
end
function Play: whenTouched()
self.touchStarted= true
x,y = self.myAnim:getPosition()
if self.touchStarted then
speed = -60
self.touchStarted = false
end
y = y + speed;
self.myAnim:setPosition(x,y)
end
Comments
the correct way would be not to move self.myAnim, because you are only moving the image, but move the whole Player class by setting self:setPosition(x, y)
that way, either of the images added to the class will be moved, so you can do your animation yourself
Recommended way would be actually using MovieClip