Hi Ansca,
I am programming a word game, but with some physics twists. So whenever you find the word bed, it spawns a bed. A cannon also shoots balls out of it. So I wanted the ball to disappear once it collided with the bed. So I put this code in:
[lua]
local function cat()
local flame = display.newImage(“flame.gif”, 422, 68);
transition.to(flame, {time=500, alpha=0});
local ball = display.newImage(“meteor.png”, 430, 65)
ball.yScale = 0.5;
ball.xScale = 0.5;
ball.myName = “ball”;
physics.addBody(ball, “static”, {density=0.4, friction=0.5, bounce=0.1, radius=15});
–ball.collision = coll;
–ball:addEventListener(“collision”, ball);
–lett:insert(ball);
local function fall()
local function falla()
transition.to(ball, {x=ball.x-215, y=ball.y+50, time=900});
end
transition.to(ball, {x=ball.x-50, time=250, onComplete=falla});
end
transition.to(ball, {x=ball.x-215, y=ball.y-50, time=900, onComplete=fall});
–physics.setGravity(-7, -5);
–timer.performWithDelay(650, gchange, 1);
end
timer.performWithDelay( math.random(7000, 12000), cat, 0);
local function onLocalCollision( self, event )
if ( self.myName == “bed” ) and (event.other.myName == “ball”) then
ball:removeSelf();
end
end
[/lua]