Hello Community, I need the ball doesn’t collide with other balls, and if I add Right and Left Walls, when the balls collides with them, they get remove. Here’s my code:
[code]
–Hide Status Bar
display.setStatusBar ( display.HiddenStatusBar )
–Physics Setup
local physics = require “physics”
physics.start ()
physics.setGravity ( 0, 9.8 )
physics.setScale ( 80 )
physics.setDrawMode ( “normal” )
–Variables
local wScreen = display.contentWidth
local hScreen = display.contentHeight
local mRandom = math.random
local staticObject = { density = 2, friction = 0.3, bounce = 0.4 }
local ballObject = { density = 0.8, friction = 0.3, bounce = 0.6, radius = 12 }
–Objects
local background
local ball
local floor
–Functions
local startScreen = {}
local spawnBalls = {}
local removeBalls = {}
–Main Function
local function main ()
startScreen ()
end
–Initial Screen
function startScreen ()
background = display.newImage ( “background.png” )
background:setReferencePoint ( display.CenterReferencePoint )
background.x = wScreen * 0.5
background.y = hScreen * 0.5
floor = display.newRect ( 0, hScreen, wScreen, 1 )
physics.addBody ( floor, “static”, staticObject )
end
–Spawn Ball
function spawnBalls:tap ()
ball = display.newImage ( “Ball.png” )
ball:setReferencePoint ( display.CenterReferencePoint )
ball.x = mRandom ( 40, wScreen - 40 )
ball.y = mRandom ( 40, hScreen - 40 )
physics.addBody ( ball, ballObject )
end
–Listener
Runtime:addEventListener ( “tap”, spawnBalls )
main () [import]uid: 81091 topic_id: 17923 reply_id: 317923[/import]
[import]uid: 52491 topic_id: 17923 reply_id: 68545[/import]