@delta … I believe Corona caches stuff anyway. Having it “destroyed” does not mean it is free’d anyway.
@DiabeticGames … You may just use one “display.newGroup()” for all bullets and iterate through them. Similar to deleting items in the group you should iterate backwards over this group so if you remove one the indexing does not get wrong. The “display.newGroup()” has “numElements” instead of “#obj” for getting the count. The remaining stuff can be accessed like an table (array).
I am a big fan of using “newGroup()” for creating groups and hierarchy.
And remember: You can extend any object with you own info … just by adding it…
Some “freeform” example should go like this:
bullets=display.newGroup()
-- add a bullet (or multiple)
local bullet=display.newImage("bullet.png")
bullet.x=123
bullet.y=123
bullet.fadecounter=66 -- 2 seconds lifetime
bullet.damage\_type='elemental' -- hehe
bullet.move\_x=0.5 // move distance per frame
bullet.move\_y=-1.2 // move distance per frame
bullets:insert(bullet)
--- later (called from enterFrame Event Handler) ---
-- calculate how many "frames" happened since last call
frames = (system.getTimer() - lasttimer) / 33
-- iterating all the "bullets"
for n=bullets.numElements,1,-1 do
local b=bullets[n]
-- move it
b.x=b.x+frames\*b.move\_x
b.y=b.y+frames\*b.move\_y
b.fadecounter=b.fadecounter-frames
if b.fadecounter\<=0 or (b.x\>=320 and b.x\<=0) or (b.y\>=480 or b.y\<=0) then
b:removeSelf() -- bullet is gone...
-- or: b.parent:remove(b)
-- or: bullets:remove(b)
-- or: bullets:remove(n)
elsif hittest(b,t) then
if b.damage\_type == t.armor\_type
t.health=t.health-100
else
t.health=t.health-500
end
if t.health \<= 0 then
t:explode()
end
b:removeSelf() -- bullet is gone..
end
end
LOL … I wanna write an old school shooter NOW …
Hope that makes sense… [import]uid: 6928 topic_id: 1374 reply_id: 3813[/import]