Game Development Reference
In-Depth Information
Parameters
While in interactive running mode, you might want to be able to change some of the code on the fly
to see how it will alter the output. For example, say you want to alter the stroke width or the radius of
a circle. Rather than setting that in the code and running it again, you can use the parameter sliders
to alter it on the fly.
Parameters can be created using the
parameter
function. The
parameter
function takes three arguments:
the
name
of the parameter, the
starting
range, and the
end
range. The name of the parameter is also the
name of the global variable, which can be accessed in the code. Here's an example:
parameter("Radius", 1, 10)
setup
function. The
parameter
function allows for the
iparameter
function allows for
parameter("Radius", 100, 500)
iparameter("BlueAmount", 0, 255)
background(10,10,20)
stroke(255)
fill(255,0,BlueAmount)
strokeWidth(1)
ellipseMode(RADIUS)
ellipse(0,0,Radius, Radius)
end
Now when we run the code, we can adjust the radius of the ellipse that we draw and also modify the
blue color amount. This allows the color to change from Red to Magenta.
Note
You can add a fourth argument to the
parameter
or the
iparameter
function that sets the
initial value of the global variable.
Drawing with Codea
Since Codea is a GUI-based framework, we'll focus on the
draw
function, which enables us to create
graphics.
On the Codea drawing surface, the screen is refreshed, or rather drawn, over 60 times a second.
However, there is no certainty that the
draw
function will be called 60 times per second, as this is
dependent on the time the code inside of
draw
takes to complete and return.