STATIC BORDER

Hi I made a game where when you tap the screen the player jumps but then it goes of the screen how can I make it so when it gets to the edges of the screen it bounces back in?

Create invisible walls using display.newRect().  I’m assuming your using physics here.  Add them as physics bodies of a type static an then set them to invisible:

-- create a five point high wall the width of the screen position at top: local roof = display.newRect(display.contentCenterX, 0, display.contentWidth, 5) -- make it a static physics body physics.addBody( roof, "static", { friction=0.5, bounce=0.3 } )

That will prevent your character from going off the top of the screen.  Add side walls and a floor as necessary.

Rob

but how do you make just walls

The post above makes a basic wall. If you want a floor, build a display.newRect() at the bottom of the screen.  Side walls? Make it tall and thin and place it at the side. The code above works.

Now if you want your wall to be a graphic, you would use display.newImageRect() to load an image instead of display.newRect().

Rob

Create invisible walls using display.newRect().  I’m assuming your using physics here.  Add them as physics bodies of a type static an then set them to invisible:

-- create a five point high wall the width of the screen position at top: local roof = display.newRect(display.contentCenterX, 0, display.contentWidth, 5) -- make it a static physics body physics.addBody( roof, "static", { friction=0.5, bounce=0.3 } )

That will prevent your character from going off the top of the screen.  Add side walls and a floor as necessary.

Rob

but how do you make just walls

The post above makes a basic wall. If you want a floor, build a display.newRect() at the bottom of the screen.  Side walls? Make it tall and thin and place it at the side. The code above works.

Now if you want your wall to be a graphic, you would use display.newImageRect() to load an image instead of display.newRect().

Rob