How to make a circular boundary?

Hello guys, I’ve started tweaking with Corona Sdk yesterday evening and I’m loving it. I’m trying to code a simple game in which a ball bounces into a circular boundary but I don’t know how to do that. I’ve seen a post on the forum which suggests making a boundary with many little segments which approximate the circle but seems really difficult to me. Is there any other option? Thank you in advance!

Hi.  Do you mean, you want a object inside a circle and bouncing off the inner-edges of the circle?

i.e. Sort of like Circle Pong bouncing mechanics?

https://play.google.com/store/apps/details?id=com.perlagotchiapps.squashpong&hl=en

Following video is NOT circle pong, but I think it demonstrates what you are asking, if not please tell us or clarify some more:

https://www.youtube.com/watch?v=6aIKZs-_XSQ

Yeah, exactly like this. 

https://www.youtube.com/watch?v=ayc2HApxOkg&feature=youtu.be

Here is a sample that bounces that way:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/SSK2/forums_help/circlePongBounce.zip

require "ssk2.loadSSK" \_G.ssk.init( {} ) local physics = require "physics" physics.start() physics.setGravity(0,0) physics.setDrawMode("hybrid") local ballRadius = 50 local ball = ssk.display.newImageRect( nil, centerX, centerY, "rg256.png", { size = ballRadius \* 2 }, { radius = ballRadius, bounce = 1, friction = 0 } ) local ringRadius = 300 local ring = ssk.display.newCircle( nil, centerX, centerY, { radius = ringRadius, stroke = \_W\_, strokeWidth = 8, fill = \_T\_ } ) ring.alpha = 0.2 local body = { chain = {}, connectFirstAndLastChainVertex = true, bounce = 1, friction = 0 } local points = 50 local angle = 0 local dpa = 360/points for i = 1, points do local vec = ssk.math2d.angle2Vector( (i-1) \* dpa, true ) vec = ssk.math2d.scale( vec, ringRadius ) body.chain[#body.chain+1] = vec.x body.chain[#body.chain+1] = vec.y end physics.addBody( ring, "static", body ) ball:setLinearVelocity( math.random( 300, 450), math.random( -200, 200 ) )

It is written with SSK2, but you can figure out the important bits by looking at the code.

Thank you very much, in the meantime I came to the same code conclusion but with mini circles instead of segments. Do you think physics will be the same?

  1. You don’t need to quote me when responding.  Just respond.  Quotes should be reserved for short things you want to pay particular attention to in your response.

  2. I don’t have any idea what you mean by mini-circles.  Be more precise and give a short example, -OR- reference the exact docs for the features you are talking about, -OR- at least list the names and details of the feature you are talking about.

Note: My example doesn’t use segments.  It uses a chain-body.

Hi.  Do you mean, you want a object inside a circle and bouncing off the inner-edges of the circle?

i.e. Sort of like Circle Pong bouncing mechanics?

https://play.google.com/store/apps/details?id=com.perlagotchiapps.squashpong&hl=en

Following video is NOT circle pong, but I think it demonstrates what you are asking, if not please tell us or clarify some more:

https://www.youtube.com/watch?v=6aIKZs-_XSQ

Yeah, exactly like this. 

https://www.youtube.com/watch?v=ayc2HApxOkg&feature=youtu.be

Here is a sample that bounces that way:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/SSK2/forums_help/circlePongBounce.zip

require "ssk2.loadSSK" \_G.ssk.init( {} ) local physics = require "physics" physics.start() physics.setGravity(0,0) physics.setDrawMode("hybrid") local ballRadius = 50 local ball = ssk.display.newImageRect( nil, centerX, centerY, "rg256.png", { size = ballRadius \* 2 }, { radius = ballRadius, bounce = 1, friction = 0 } ) local ringRadius = 300 local ring = ssk.display.newCircle( nil, centerX, centerY, { radius = ringRadius, stroke = \_W\_, strokeWidth = 8, fill = \_T\_ } ) ring.alpha = 0.2 local body = { chain = {}, connectFirstAndLastChainVertex = true, bounce = 1, friction = 0 } local points = 50 local angle = 0 local dpa = 360/points for i = 1, points do local vec = ssk.math2d.angle2Vector( (i-1) \* dpa, true ) vec = ssk.math2d.scale( vec, ringRadius ) body.chain[#body.chain+1] = vec.x body.chain[#body.chain+1] = vec.y end physics.addBody( ring, "static", body ) ball:setLinearVelocity( math.random( 300, 450), math.random( -200, 200 ) )

It is written with SSK2, but you can figure out the important bits by looking at the code.

Thank you very much, in the meantime I came to the same code conclusion but with mini circles instead of segments. Do you think physics will be the same?

  1. You don’t need to quote me when responding.  Just respond.  Quotes should be reserved for short things you want to pay particular attention to in your response.

  2. I don’t have any idea what you mean by mini-circles.  Be more precise and give a short example, -OR- reference the exact docs for the features you are talking about, -OR- at least list the names and details of the feature you are talking about.

Note: My example doesn’t use segments.  It uses a chain-body.