Game Development Reference
In-Depth Information
bar.height = 8 * counter
bar:setReferencePoint(display.BottomLeftReferencePoint)
bar.y=300
theText.text = counter
end
--
Runtime:addEventListener ( "enterFrame", move )
Runtime:addEventListener ( "tap", toggleMove )
Figure 8-13.
The health bar on the device (or simulator), with the value displayed
Notice that the bar starts to bob, increasing at first and then decreasing. The health bar bobs to
demonstrate how an object can be modified each time the
enterFrame
function is called. This can
be used for animation, such as changing the location of the object on the screen or changing the
dimensions of the object.
Animating Using enterFrame
As shown in Figure
8-14
, we can use
enterFrame
to move an object on the screen. In Chapter 4, you
learned about constraining an object to a particular dimension on the screen. We are definitely not in