– this is as bare-bones as I could make it for you. I would recommend using
– spriteSheets because as you progress, animations will ostensibly
– contain more frames and a spritesheet is far more efficient. That said… the
– below code should work
– START CODE ----------------------------------------------------------------------------------
– start by creating an image. I have two images in the same directory as the
– main.lua file (image1.png and image2.png)
myImage = display.newImage( “image1.png” )
– set the x,y location of the image.
myImage.x = 100; myImage.y = 100
– this function gets called on “touch” and that association is made
– in the function below: Runtime:addEventListener(“touch”,touchScreen)
local function touchScreen(event, self) – “event” is a critical parameter
– there are multiple phases of a touch event, we are going to use “began”,
– the initial part of the event and “ended” the last part of the event.
if event.phase == “began” then
– (THE USER JUST TOUCHED THE MOBILE DEVICE SCREEN)
– remove the active instance of the image
myImage:removeSelf( )
– create a new image (i.e. the throw state)
myImage = display.newImage( “image2.png” )
– move the image slightly to the right as requested
myImage.x = 150; myImage.y = 100
elseif event.phase == “ended” then
– (THE USER JUST RELEASED THE MOBILE DEVICE SCREEN)
– remove the active instance of the image
myImage:removeSelf( )
– create a new image (i.e. the default state)
myImage = display.newImage( “image1.png” )
– move the image back to the original, resting state
myImage.x = 100; myImage.y = 100
end
end
– add a listener so the touchScreen function is called when the user
– touches the screen
Runtime:addEventListener(“touch”,touchScreen)
– END CODE ----------------------------------------------------------------------------------