@Horace:
Thats really awesome stuff. How does that help me to remove the bullets after they are shot and still on the screen? Or does it?
8)
here’s my rub:
local function shoot (event)
local ball = display.newCircle( killer1.x, killer1.y, 20 )
ball.myName = “ball”
physics.addBody( ball, “dynamic”, { density=2, friction=0, bounce=0.2 } )
–local angle = (cannon.rotation-90)*0.0174532925 --covert to radians /// THIS ONLY SHOOT AT THE ANGLE OF THE CANNON
–local a, b = math.cos(angle)*500, math.sin(angle)*500
ball:applyLinearImpulse((ball.x - event.x)*-0.5, (ball.y - event.y)* -0.5, ball.x, ball.y) --CHANGE NEGATIVE NUMBERS TO SUIT
– ball:applyLinearImpulse( a,b, ball.x ,ball.y )
ball.linearDamping = 0; – use this to damp e.g. apply opposite force (decelerate)
end
Runtime:addEventListener(“tap”, shoot)
—collision reporting for force or other events
function onLocalPreCollision( event, self)
– This new event type fires shortly before a collision occurs, so you can use this if you want
– to override some collisions in your game logic. For example, you might have a platform game
– where the character should jump “through” a platform on the way up, but land on the platform
– as they fall down again.
– Note that this event is very “noisy”, since it fires whenever any objects are somewhat close!
print( "preCollision: " … self.myName … " is about to collide with " … event.other.myName )
end
function onLocalPostCollision( event, self)
– This new event type fires only after a collision has been completely resolved. You can use
– this to obtain the calculated forces from the collision. For example, you might want to
– destroy objects on collision, but only if the collision force is greater than some amount.
if ( event.force > .000001) then
print( "postCollision force: " … event.force … ", friction: " … event.friction )
ball.parent:remove( ball )
local currentScore = getScore()
currentScore = currentScore + 300
setScore( currentScore )
– After ignore further collisions
self:removeEventListener( “postCollision”, self )
end
end
ball.preCollision = onLocalPreCollision
ball:addEventListener( “preCollision”, ball )
ball.postCollision = onLocalPostCollision
ball:addEventListener( “postCollision”, ball )
-----end collision reporting------ [import]uid: 7346 topic_id: 21800 reply_id: 108209[/import]