Codes a bit mad…
Few helpful hints though…
-
Draw 4 rectangles outside of the viewable area and use those to detect and kill any bullets thats go off screen. Use collision tables so only the bullets and the walls interact as otherwise it would stop other objects passing through the walls.
-
Construct your objects so that do not rely on loops and functions where you don’t need to. For instance the bullet should contain all the code that controls the bullet.
The idea here is you create a standard Corona object, pass it to the physics engine and ignore it until it triggers an event.
Heres a non tested example
[code]
– New Bullet
local function newBullet()
– New Bullet
local bullet = display.newImageRect()
– Physics Settings
local collisionFilter = { categoryBits = 4 , maskBits = 9 }
local physicsSettings = { density = 1 , friction = 1 , bounce = 1 , filter = collisionFilter }
– Add Physics
physics.addBody( bullet , physicsSettings )
– Is Hit Function
bullet.isHit = function()
– Play Explosion
playExplosion( bullet.x , bullet.y )
– Remove Physics
bullet:removeSelf()
– Cleanup
bullet = nil
end
– Destroy Function
bullet.destroy = function()
– Remove Physics
bullet:removeSelf()
– Cleanup
bullet = nil
end
– Return Bullet
return bullet
end
[/code] [import]uid: 5354 topic_id: 15588 reply_id: 57609[/import]