Game Development Reference
In-Depth Information
Using Transition Functions
Next, we'll look at some transitions . These are handy functions that help us modify the visible
attributes of an object and provide us with the illusion of animation.
Note
In the world of Adobe Flash, these types of transitions are called tweens .
Transitioning an object is similar to moving an object to a new position over a period of time. In the
earlier example of the bouncing ball, we could have used transitions; however, transitions require a
The following code colors this ball red, makes it grow as it moves, and makes it fade in as it appears,
like the morning sun.
local ball = display.newCircle ( 160, 480, 50 )
ball:setFillColor(255,255,0)
ball.alpha = 0.5
ball:scale(0.5,0.5)
transition.to ( ball, {time=2000, y = 80, alpha = 1, xScale = 1.2, yScale = 1.2})
We can use a transition to scroll some text on the screen:
local theText = display.newText("Hello, hope you are enjoying your journey with Lua so far",0,440)
theText.x = theText.contentWidth
transition.to(theText,{time=8000, x = -theText.contentWidth})
--
You will see the text scrolling at the bottom of the screen. Also notice that the other transitions go
about at their own speeds irrespective of the scrolling text. In short, they do not affect each other. You
can have multiple transitions on the screen at the same time, independent of each other.
In a game, if we use transitions, we also need to also know when they have completed, because
we might want to do something when the transition is finished. With the transition function, there
are two parameters that we can use to carry out specific actions when the transitions start and end.
These are aptly named onStart and onComplete .
 
Search WWH ::




Custom Search