Hello, I am new to Corona and experimenting with my first app. I am trying to construct a simple app to implement a ball that bounces around inside a circular boundary. I am using the Corona game in 8 minutes tutorial as a starting point and have the following code so far:
[lua]–> Add physics engine
local physics = require(“physics”)
physics.start()
–> Set gravity to act “down”
physics.setGravity(0, 9.8)
–> Add circular boundary
local circleRadius = display.contentWidth/2
local circleBoundary = display.newCircle(display.contentWidth/2, display.contentHeight/2, circleRadius)
circleBoundary:setFillColor(255,255,255, 255)
–> Turn circle boundary into physics body
physics.addBody(circleBoundary, “static”, {bounce = 0.2})
–> Add ball image
local ball = display.newImage(“ball.png”)
ball.x = circleBoundary.contentWidth/2
ball.y = circleBoundary.contentHeight/3
–> Turn ball into physics body
physics.addBody(ball, {bounce = 0.8})
–> Hide status bar
display.setStatusBar(display.HiddenStatusBar)[/lua]
When run, the ball drops down into the area of the circular boundary then bounces up past the top of the circular boundary and stops.
The behavior I am trying to affect is as follows:
- the ball bounces off the inner perimeter of the circular boundary
- the ball stays contained within the circular boundary
Questions:
- is this behavior possible with the physics engine?
- is there any sample code that shows how to affect the desired behavior?
I have searched the site and forums but could not find anything – hence my query. Any pointers are appreciated!
[import]uid: 1855 topic_id: 4740 reply_id: 304740[/import]