Reputation: 1
I already found a similar question on this website but the answers didn't really help. I'm creating a game on Solar2d /Corona sdk and I'm trying to create multiple objects that bounce around the screen and even collide with each other changing the direction (just like in real life). I'm having a few issues... I tried to create some walls but I just see white lines and my objects can go past them since they only cover half the width and half the height. here is the code I used (I found it somewhere on the internet):
local leftWall = display.newRect (0, 0, 1, display.contentHeight);
local rightWall = display.newRect (display.contentWidth, 0, 1, display.contentHeight);
local ceiling = display.newRect (0, 0, display.contentWidth, 1);
local bottom = display.newRect (0, display.contentHeight, display.contentWidth, 1);
How can I set the edges of the screen as boundaries? And since I want to create several copies of the same object should I create them individually or as a group?
I'm new to the website so if I made any mistake I'm sorry!
Upvotes: 0
Views: 356
Reputation: 125
You should use the physics library of Solar2D. (Call it with local physics = require( "physics" )
). Then make all those walls into physics bodies using
physics.addBody( leftWall, "static", { --[[all other parameters]] } )
physics.addBody( rightWall, "static", { --[[all other parameters]] } )
physics.addBody( ceiling, "static", { --[[all other parameters]] } )
physics.addBody( bottom, "static", { --[[all other parameters]] } )
For the parameters you might want to read the documentation
Also I suggest to use display.newLine instead of display.newRect and make it very thin. It is definitely easier to manage and the code that I wrote up here doesn't change at all
Upvotes: 0