My question is how can I click a button and make a sprite start moving?
Sprite Code:
local instance = sprite.newSprite(set);
instance.x = display.contentWidth/70
physics.addBody(instance, {bounce = 0.2, friction = .1, radius = 30})
instance.name = "sprite"
instance:play();
transition.to( instance, { time=15000, x = 1100 } )
Play Button:
local playbutton = display.newImage( "play.png" )
playbutton.x = display.stageWidth / 1.195
playbutton.y = display.stageHeight / 4.7
playbutton.active = false
local function buttonTouched(e) if e.phase == "began" then
e.target.alpha = .5
end if e.phase == "ended" then
e.target.alpha = 1 print("Replay button was touched.")
end
end
playbutton:addEventListener( "touch", buttonTouched )
playbutton:addEventListener('tap', playbutton)
Right now the Play button doesn’t do anything and when I relaunch the simulator the sprite automatically starts its course across the screen. I’d like to be able to launch the simulator and click the play button and then have the sprite start its course.
Any help would be appreciated.
Thanks,
Andrew [import]uid: 72845 topic_id: 12576 reply_id: 312576[/import]
[import]uid: 72845 topic_id: 12576 reply_id: 46232[/import]