The physics and the remaining game functions need to be initialized to run the game. All game actions need to be delayed until the help screen has left the stage.
gameInit()
, which will hold the physics properties and activate the display objects on the stage:local gameInit = function() physics.start( true ) physics.setGravity( 0, 9.8 ) drawBackground() createPowerShot() createPanda() createStars() hud()
Runtime
event listener, using "touch"
for onScreenTouch()
:Runtime:addEventListener( "touch", onScreenTouch )
gameInit()
:local roundTimer = timer.performWithDelay( 10000, function() startNewRound(); end, 1 ) local gameTimer = timer.performWithDelay( 10000, function() startTimer(); end, 1 ) end gameInit()
All the code is completed! Run the game in the simulator and see for yourself how it works. Make sure to check for any typos in your code if errors occur.
The round is initialized through gameInit()
. The physics engine and the remaining functions are run at this time. The event listener for onScreenTouch()
is added as well. The startNewRound()
and startTimer()
functions initiate 10 seconds after launching the application through timer.performWithDelay
.
Q1. What is the proper way to pause the animation of an image sheet?
object:stop()
object:pause()
object:dispose()
Q2. How do you make an animation sequence loop forever?
local sequenceData =
{
name="run", start=1, count=5, time=100, loopCount=1
}
local sequenceData =
{
name="run", start=1, count=5, time=100, loopCount=0
}
local sequenceData =
{
name="run", start=1, count=5, time=100, loopCount=-1
}
local sequenceData =
{
name="run", start=1, count=5, time=100, loopCount=100
}
Q3. How do you create a new image sheet?
myCharacter = display.newSprite(sequenceData)
myCharacter = display.newSprite(imageSheet, sequenceData)
myCharacter = sprite.newSpriteSheet("myImage.png", frameWidth, frameHeight)