Skip to content Skip to sidebar Skip to footer

How To Make Multiple Objects Bounce Around In Corona Sdk

Hey guys I am new to Corona sdk and would like some help with make some balls to bounce around the screen randomly, I don't know the code for this so could someone give me a piece

Solution 1:

All you have to do is to implement physics. Here is the tutorial : http://developer.coronalabs.com/content/game-edition-box2d-physics-engine

Solution 2:

You need to apply physics in your game.

Try this sample code, it has walls and a ball.

_W = display.contentWidth
_H = display.contentHeight

local physics = require("physics")
physics.start()
physics.setGravity(0,0) --To make everything float, zero gravity--Lets add wallslocal left_wall = display.newRect(0,0,1,_H)
physics.addBody(left_wall,"static")

local right_wall = display.newRect(_W-1,0,2,_H)
physics.addBody(right_wall,"static")

local top_wall = display.newRect(0,0,_W,2)
physics.addBody(top_wall,"static")

local bottom_wall = display.newRect(0,_H,_W,2)
physics.addBody(bottom_wall,"static")

local ball = display.newCircle(math.random(100,_W-100),math.random(100,_H-100),10)
physics.addBody(ball,"dynamic",{bounce = 1, friction = 0})
ball:setLinearVelocity(900,1500)

Post a Comment for "How To Make Multiple Objects Bounce Around In Corona Sdk"