Firstly, I’d like to thank you all for providing the wealth of information about corona and its application particularly for those of us who are new to developing app games. I have sifted through the forums and online tutorials and cannot get passed a current blockade. Any help would be greatly appreciated.
I am trying to make balls bounce off of eachother at a constant rate. I copied the sample code from “collision filter” for physics and found that this created 3 identical versions of each ball equating to 6 balls on my screen (i only uploaded 2 so far) and they only bounce off some balls then quickly come to a static bounce at the bottom of the screen whereby they no longer move up down left or right but instead bounce a little in place. I have a lot of different balls that I want to put into this game and have them spawn randomly each time a user chooses the right ball corresponding to a hint that i provide at the top of the screen therefore keeping a constant set number of balls on the screen. Here is what i have so far
local centerX = display.contentCenterX
local centerY = display.contentCenterY
local _W = display.contentWidth
local _H = display.contentHeight
local physics = require(“physics”)
physics.start()
physics.setScale( 60 )
display.setStatusBar( display.HiddenStatusBar )
local background = display.newImageRect( “background.png”, 360, 570 )
background.x = display.contentCenterX
background.y = display.contentCenterY
display.setDefault( “anchorX”, 0.0 ) – default to TopLeft anchor point for new objects
display.setDefault( “anchorY”, 0.0 )
borderCollisionFilter = { categoryBits = 1, maskBits = 6 } – collides with (4 & 2) only
borderBodyElement = { friction=0.4, bounce=0.8, filter=borderCollisionFilter }
local borderTop = display.newRect( 0, 0, 320, 1 )
borderTop:setFillColor( 0, 0, 0, 0) – make invisible
physics.addBody( borderTop, “static”, borderBodyElement )
local borderBottom = display.newRect( 0, 479, 320, 1 )
borderBottom:setFillColor( 0, 0, 0, 0) – make invisible
physics.addBody( borderBottom, “static”, borderBodyElement )
local borderLeft = display.newRect( 0, 1, 1, 480 )
borderLeft:setFillColor( 0, 0, 0, 0) – make invisible
physics.addBody( borderLeft, “static”, borderBodyElement )
local borderRight = display.newRect( 319, 1, 1, 480 )
borderRight:setFillColor( 0, 0, 0, 0) – make invisible
physics.addBody( borderRight, “static”, borderBodyElement )
local red = {}
local blue = {}
local redCollisionFilter = { categoryBits = 2, maskBits = 3 } – collides with (2 & 1) only
local blueCollisionFilter = { categoryBits = 4, maskBits = 5 } – collides with (4 & 1) only
local redBody = { density=0.2, friction=0, bounce=0.95, radius=43.0, filter=redCollisionFilter }
local blueBody = { density=0.2, friction=0, bounce=0.95, radius=43.0, filter=blueCollisionFilter }
for i = 1,4 do
red[i] = display.newImage( “blueball.png”, (80*i)-60, 50 + math.random(20) )
physics.addBody( red[i], redBody )
red[i].isFixedRotation = true
blue[i] = display.newImage( “redball.png”, (80*i)-60, 250 + math.random(20) )
physics.addBody( blue[i], blueBody )
blue[i].isFixedRotation = true
end
-Thanks in advance for your attention. Looking forward to your replies
