How to create a rectangle in the screen border?

Hello,

I am very newbie to Corona and I am trying to create a bouncing ball game. For that I need to draw a rectangle towards the sides of the screen - ie, want to create a border to the screen - and the ball will be following the gravity and bounce a little and will change its direction up on user’s touches.

I want to know how to create a rectangle exactly at the screen border. I am getting confusion about the width and height of the screen. Also when I set the height & width in the build via config.lua, the size of the ball got reduced and still the rectangle didn’t come up clearly. Not sure what is happening.

Anybody please help…

This is my config.lua contains:

application = {

    content = {

        width = 768,

        height = 1280, 

        --scale = “letterBox”,

        fps = 60,

        

        --[[

        imageSuffix = {

            ["@2x"] = 2,

        }

        --]]

    }

}

This is what my main.lua contains:

local physics = require(“physics”)

physics.start()

print( "Model = "…system.getInfo( “model” ))

–[[local space = display.newRect(160, 160, 1500, 1300)–, 300, 500 )

space.strokeWidth = 3

space:setFillColor( 0.2 )

space:setStrokeColor( 1, 1, 0 ) 

physics.addBody( space, “static”, {density=1, friction=0, bounce=0} )

]]

local ball = display.newImage(“ball.png”)

ball.x=160; ball.y=150; ball.rotation=1;

physics.addBody(ball, {density=1, friction=0.5, bounce=.5})

count=0

local myGrav = {}

local dir = {“up”, “down”, “left”, “right”}

myGrav[1]={ 0,  -1} – N

myGrav[2]={ 1,   0} – E

myGrav[3]={ 0,   1} – S

myGrav[4]={-1,   0} – W

myGrav[5]={ 1,  -1} – NE

myGrav[6]={ 1,   1} – SE

myGrav[7]={-1,  -1} – NW

myGrav[8]={-1,   1} – SW

local function changeDirection( event )

    if (event.phase == “began”) then

        local count1 = math.random(#myGrav)

        print(“value cnt=”…count…" and cnt1="…count1)

        if  (count1 == count) then

            repeat

                count1 = math.random(#myGrav)    

            until (count ~= count1)

        end

        count=count1

        local xGrav = myGrav[count][1]; yGrav=myGrav[count][2]

        print (“cnt=”…count…",xGrav="…xGrav…", yGrav="…yGrav)

        ball:setLinearVelocity( xGrav*120, yGrav*120)

        physics.setGravity( xGrav, yGrav)

    end

    return true

end

– space:addEventListener(“touch”, changeDirection)

NOTE: 

The above print will display “Model = Droid” and a ball will be drawn which will fall freely down (which is fine). However if I uncomment whatever commented above, a yellow line comes at around two third part of the screen and the ball goes upwards. My plan is whenever the user touches the bottom part of the screen, the balls direction should change. Pls help me!

Here is the most up-to-date reource list for Corona SDK tutorials. It’s the best place to start when beginning to learn Corona.

http://www.tandgapps.co.uk/resources/coronalabs-resources/

Regarding your question of screen sizes and resolutions, it would be best to take a look at the config.lua tutorials, to get an idea about how best to utilize config files. Specifically to your situation, the higher the numbers go, the higher the resolution, the smaller the objects will appear to the end user. 

Hey, I know you :slight_smile:

In addition to the tutorials mentioned above, check out the sample code that comes with Corona.

In particular, the SampleCode/Physics/ShapeTumbler example.    

Here is the most up-to-date reource list for Corona SDK tutorials. It’s the best place to start when beginning to learn Corona.

http://www.tandgapps.co.uk/resources/coronalabs-resources/

Regarding your question of screen sizes and resolutions, it would be best to take a look at the config.lua tutorials, to get an idea about how best to utilize config files. Specifically to your situation, the higher the numbers go, the higher the resolution, the smaller the objects will appear to the end user. 

Hey, I know you :slight_smile:

In addition to the tutorials mentioned above, check out the sample code that comes with Corona.

In particular, the SampleCode/Physics/ShapeTumbler example.