Hi everyone.
I’ve got a question regarding transition.to() or transition.from() and the best approach to implementing it.
I have a player object with a transition.to assigned inside its move method. It’s a simple move up, down, left and right job. There’s also a local function which is called when the transition is complete.
local function finishedMoving( obj ) print("Finished Moving") print(obj.status) end function player:move(direction, xDir, yDir) self.spriteSheet:setSequence(direction) transition.to( self.spriteSheet, { time=self.speed, delta=true, x=(64\*xDir), y=(64\*yDir), onComplete=finishedMoving } ) self.spriteSheet:play() end
As you can see, I’m passing three variables to the move method, a string (which is also the name of the spritesheet sequences for my player.spritesheet, and an x and y direction which is essentially -1, 0 or +1.
This all works as expected. But when the object is passed to the finishedMoving function, it’s passing player.spritesheet. And I want to be able to tell what player properties such as player.status when it has completed its transition.
So ideally, in the transition.to() I should be passing self (which is the player object) as the target. This would work perfectly, but then the character just plays his sequence and doesn’t move.
Any ideas? I’m really stuck on this one.
Thanks in advance.
Michael