I wrote my first game in late 1984 using AppleSoft BASIC. A couple years later I was writing commercial games in 65C02/65C816 assembly language.
I am NOT a newbie.
But apparently I’m not used to the EASE you young whippersnappers have in how you do things these days – set up a block below the screen and watch for a collision?!
Awesome idea!
In Roly-Polies HD I needed to watch for the RP (Roly-Poly, of course) to drop off the screen and I used a different system – set up a timer for that RP which checked every 150 ms to see whether he was off the screen or not.
To be fair, I also needed to check to see whether he was still moving (he can get stuck in some places and then must self-destruct) so I couldn’t use the “block below the screen” method, but it’s still a cool way to do it. (I also needed to record the path of the RP which is why I checked every 150ms instead of a longer period of time.)
In case someone wants to know at least one way that an old geezer might do it, here’s the pertinent code:
[lua]PeaStandard = display.newImage(“images/Pea-Standard.png”)
PeaStandard.x = event.x
PeaStandard.y = 30
physics.addBody(PeaStandard,“dynamic”, {density=1, bounce=.1, friction = 1, radius = 18})
local function isPeaMoving()
– see if it’s offscreen, if so, just delete it.
if PeaStandard.x < -20 or PeaStandard.x > 1024 or PeaStandard.y < -10 or PeaStandard.y > 768 then
timer.cancel ( PeaStandard.tmr )
display.remove(PeaStandard)
return
end
– other code here to record path and see if RP was still moving
end
PeaStandard.tmr = timer.performWithDelay(150, isPeaMoving, 0)[/lua]
Just remember if you do something like this to cancel the timer before you destroy the object. Bad things happen if you don’t do that.
Also, a “real programmer” wouldn’t hard code the values for the edges of the screen. *ahem* Use variables, kids, they’re your friends.
Jay
[import]uid: 9440 topic_id: 24743 reply_id: 103822[/import]