Make a Circle
To make a circle in Corona SDK we use the function newCircle of the display object. This function takes three parameters in this order.:
- the x coordinate for the center
- the y coordinate for the center
- the circle’s radius
config.lua
First let’s make a config file to set the screen size.
application = { content = { width = 320, height = 480, scale = "zoomEven" } }
main.lua
Now lets work on the main.lua file. We can store the circle in a variable and use that variable later to change other properties of that circle like color for example.
Let’s make a circle called “circle_variable_name” with the center at (160,240) and a radius of 50.
--local nameofcircle = display.newCircle( x-cordinate, y-cordinate, radius )
local circle_variable_name = display.newCircle(160,240,50)
The default color of the circle is white, let’s change the color to red using the setFillColor function. The setFillColor function also needs three parameters which range from 0 to 250 in this order:
- amount of red
- amount of green
- and amount of blue
--nameofcircle:setFillColor(Red,Green,Blue)
circle_variable_name:setFillColor(250, 0, 0)
The full code for the circle is this
local circle_variable_name = display.newCircle(160,240,50)
circle_variable_name:setFillColor(250, 0, 0)
We can also add a stroke, and color to that stroke, to the circle just created with these two functions
--nameofcircle.strokeWidth = any_interger
circle_variable_name.strokeWidth = 3
--nameofcircle:setStrokeColor(Red,Green,Blue)
circle_variable_name:setStrokeColor(0,250,0)
The full code for the circle is
local circle_variable_name = display.newCircle(160,240,50)
circle_variable_name:setFillColor(250, 0, 0)
circle_variable_name.strokeWidth = 3
circle_variable_name:setStrokeColor(0,250,0)
Now to create more than one circle you simply create different variable names like in the following example
local circle = display.newCircle(160,240,50)
circle:setFillColor(100,190,0)
local circle1 = display.newCircle(100,150,30)
circle1:setFillColor(100,90,190)
local circle2 = display.newCircle(160,400,90)
circle2:setFillColor(250,30,190)