hello,
i am currently trying to make a group of fish fly down in groups of five.
My Problem is that i am canceling the fish in two places. The first place is in collision. When a collision touches the penguin it deletes. As in my code, you can see that i tried to cancel the following transition. The second place is in the transition. Once it completes its transition it deletes it!
Here is my code,
function createFish () -- every 5 seconds this is called
randomstart = math.random(0,\_W) --- randomstart is where the starting x coordinate is for the set of fish
function startFish() -- in the 5 seconds this is called 5 times for 5 fishes to spawn
randomnumber2 = math.random(0,30) -- randomnumber2 is a random number for every single fish so they don't all spawn in a straight line.
fishey= display.newImageRect("fish.png", 45, 32) -- spaws fish
fishey.x = randomstart + randomnumber2
fishey.y = -50
physics.addBody(fishey) --- adds physics to fish
fisheyMove = transition.to(fishey, { time=2000, y=\_H + 150, ---moves the fish
onComplete = function(self) --- moves the fish
self.parent:remove(self); ----moves the fish
self = nil; --- moves the fish
end
})
fishey.collision = function(self, event) --- collision statement
if(event.phase == "began") then -- if collision begins...
if(event.other.type == "penguin") then -- and collides with the penguin then
audio.play(chew) --- play the sound
self:removeSelf()
self = nil
transition.cancel(fisheyMove) -- trys to cancel the fish
end
end
end
fishey:addEventListener("collision", fishey)
end
timer.performWithDelay(100, startFish, 5 )
end
timer.performWithDelay(100, createFish, -1 )
Thanks for looking!
[import]uid: 24708 topic_id: 25376 reply_id: 325376[/import]
