How to add a border for android

HI, I was wondering how you would add a border all around the screen so, an object does not leave the screen. thanks

Hi @mejon,

I think you will need to be more specific to receive help from the community or staff. What is the object? How is it moving? Are you using physics? Why is this only intended for Android?

Take care,

Brent

 

 

Hi Brent,

I am trying to get used to corona. I made a simple bubble game with 2 bubbles and added physics to the bubbles @ 9.81 gravity. But as the bubbles collide the bounce of each other outside the screen. So i was wondering how do you prevent objects ( like the bubbles) from disappearing from the view? Can you make a border using display.newRect to prevent objects from leaving the screen?

thanks

You need to create walls, in short use display.newRect and then use addBody “static” on the new rect this will keep it from bouncing outside screen.

You will need to make sure you position the x/y/w/h correctly like

–right wall

w = 20

h = display.contentHeight

x = (display.contentWidth - 20)

y = 0

etc. and so forth

 

 

It does not seem to work! The top part of the screen works but the bottom half does not work.

http://i.gyazo.com/7eaab3362fe9682b92ff610938c9ce1e.png

You need to either fix your anchorX, anchorY values to 0, 0

OR account for the center (which is better idea)

for example y = (display.contentHeight * .5) etc. and so forth. you will also need to account for the green footer.

Regarding your white line just either say.

object.alpha = 0

or

object:setFillColor(1,1,1,0) -->Last value being the alpha.

would the rightwall look like this: local rightWall = display.newRect( display.contentWidth - 1, 0, display.contentHeight * .5, display.contentHeight ) ? If not, what would it look like?

close, hard to type code on iphone but try this.

local rightWall = display.newRect((display.contentWidth - 10, (display.contentHeight * .5), 20, (display.contentHeight))

I seem to get a Runtime Error! should I change this: local rightWall = display.newRect((display.contentWidth - 10, (display.contentHeight * .5), 20, (display.contentHeight)) to this: local rightWall = display.newRect((display.contentWidth - 10), (display.contentHeight * .5), 20, (display.contentHeight))

Yep looks like I missed the closing ) on the first value, iphone has a funny way about saying what is right or wrong with a word etc.

the bottom parts of the screen still do not have walls, only the top parts! use rightWall.anchorX = 0 ?

you will need to play around with it as i don’t have access to your code or your config file to see what you have going on.

anchorX would do it but i think all you need to do is add a * .5 to your first x value

local rightWall = display.newRect(((display.contentWidth * .5) - 10), (display.contentHeight * .5), 20, (display.contentHeight)) 

Seems to work now! Would it work if I do this for the ceiling as well as the leftWall? thanks

local leftWall = display.newRect(((display.contentWidth * .5) - 10), (display.contentHeight * .5), 20, (display.contentHeight)) (Would this work for left border)

local ceiling= display.newRect(((display.contentWidth * .5) - 10), (display.contentHeight * .5), 20, (display.contentHeight)) (Would this work for top border)

Yes the same logic works for all (BUT)

you have to change the position of the left walls X and change the x/y/w/h of the ceiling 

so left wall would be something like.

local leftWall = display.newRect(10, (display.contentHeight * .5), 20, (display.contentHeight)) 

ceiling would be something like

local ceiling= display.newRect(-(display.contentWidth * .5),10, (display.contentWidth), 20) 

might need to play with it but i think you have the general idea

thanks borders seem to be working!

Hi @mejon,

I think you will need to be more specific to receive help from the community or staff. What is the object? How is it moving? Are you using physics? Why is this only intended for Android?

Take care,

Brent

 

 

Hi Brent,

I am trying to get used to corona. I made a simple bubble game with 2 bubbles and added physics to the bubbles @ 9.81 gravity. But as the bubbles collide the bounce of each other outside the screen. So i was wondering how do you prevent objects ( like the bubbles) from disappearing from the view? Can you make a border using display.newRect to prevent objects from leaving the screen?

thanks

You need to create walls, in short use display.newRect and then use addBody “static” on the new rect this will keep it from bouncing outside screen.

You will need to make sure you position the x/y/w/h correctly like

–right wall

w = 20

h = display.contentHeight

x = (display.contentWidth - 20)

y = 0

etc. and so forth

 

 

It does not seem to work! The top part of the screen works but the bottom half does not work.

http://i.gyazo.com/7eaab3362fe9682b92ff610938c9ce1e.png

You need to either fix your anchorX, anchorY values to 0, 0

OR account for the center (which is better idea)

for example y = (display.contentHeight * .5) etc. and so forth. you will also need to account for the green footer.

Regarding your white line just either say.

object.alpha = 0

or

object:setFillColor(1,1,1,0) -->Last value being the alpha.