Hi everyone,
As always I'm stuck with a new issue, this time, regarding the use of the event: EVENT_COMPLETE dispatched when an Movie Clip ends.
My problem is this: I have this animation of an eraser in my game class (BonecosDesenho) that is called by another .lua when an obstacle in my game is touched by the player. After the eraser's animation ends, i want to remove it from the screen, as it will happen again and again.
How can I do that? I found on the API that when a movie clip ends it dispatches the 'event_complete' event. I thought it was perfect for me, but I'm having too much trouble understanting where should I put the listener and how to manage the removal of the animation from the screen, as its created by a function and somehow when I tried to use removeChild it said that my container for the movie clip was null...
Any help would be deeply appreciated!
This is the function that creates the animation and put it where the obstacle is:
function BonecosDesenho:animaBorracha(eventx, eventy)
local borrachaApagando = TexturePack.new(
"images/Minigames/Bonecos/Desenho/Sprite Sheets/EraserSS.txt",
"images/Minigames/Bonecos/Desenho/Sprite Sheets/EraserSS.png")
self.borracha = MovieClip.new({
{1,3,Bitmap.new(borrachaApagando:getTextureRegion("Eraser1.png"))},
{4,6,Bitmap.new(borrachaApagando:getTextureRegion("Eraser2.png"))},
{7,9,Bitmap.new(borrachaApagando:getTextureRegion("Eraser3.png"))},
{10,12,Bitmap.new(borrachaApagando:getTextureRegion("Eraser4.png"))},
{13,15,Bitmap.new(borrachaApagando:getTextureRegion("Eraser3a.png"))},
{14,16,Bitmap.new(borrachaApagando:getTextureRegion("Eraser2a.png"))},
{17,19,Bitmap.new(borrachaApagando:getTextureRegion("Eraser1a.png"))},
{20,22,Bitmap.new(borrachaApagando:getTextureRegion("Eraser5.png"))},
{23,25,Bitmap.new(borrachaApagando:getTextureRegion("Eraser1b.png"))},
{26,28,Bitmap.new(borrachaApagando:getTextureRegion("Eraser2b.png"))},
{29,31,Bitmap.new(borrachaApagando:getTextureRegion("Eraser3b.png"))},
{32,34,Bitmap.new(borrachaApagando:getTextureRegion("Eraser6.png"))},
{35,37,Bitmap.new(borrachaApagando:getTextureRegion("Eraser7.png"))},
{38,40,Bitmap.new(borrachaApagando:getTextureRegion("Eraser8.png"))}
})
self.borracha:setStopAction(40)
self.contBorracha = self.borracha
self:addChild(self.contBorracha)
self.contBorracha:setX(_G.enemy:getX()-50)
self.contBorracha:setY(eventy-140)
self.contBorracha:setVisible(true)
end |
And this is the function that calls it on the other .lua I mentioned:
function bDobstaculos:apagaInimigo(event, flag)
flag = isTouched
if enemy:hitTestPoint(event.x, event.y) and flag == true then
self:getParent():animaBorracha(event.x, event.y)
self.fixture = nil;
b2World:destroyBody(self.body);
self.body = nil;
self:removeEventListener(Event.ENTER_FRAME, self.onEnterFrame, self);
self:getParent():removeChild(self);
end
isTouched = nil
end |
Comments
Add this inside animaBorracha method
Likes: AxlFlame
Ultimate Games on Appstore
Ultimate Games on Google Play
Now that I see the solution I feel a little embarassed, haha. I had a hard time understanting where should I put the listeners and using events properly.
Anyways, thanks again!