Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
How to update position of an animation properly — Gideros Forum

How to update position of an animation properly

simransimran Member
edited June 2014 in General questions
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

Sign In or Register to comment.