Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------
- --dispatchEvent
- -----------------------
- --[[
- I have a scenario where i have a indicator that will change its image based on the score until the score is 1000 and the indicator shows full health in form of an image
- --]]
- local scoreImg = display.newImage( "image.png" )
- local myListener = function( event )
- if event.name == "health" and event.type == "low" then
- scoreImg.image = "image2.png"
- end
- return scoreImg
- end
- image:addEventListener( "myEventType", myListener )
- -- in side an if closure where I check the score I put i.e.
- ---------Just an example of use inside a function ----------------
- local function checkScore()
- if ( score > 500 and score < 750 ) then
- local event = { name="health", type="low" }
- scoreImg:dispatchEvent( event )
- elseif ( score > 750 and score < 900 ) then
- --whatever.....
- end
- end
- Runtime:addEventListener( "enterFrame", checkScore )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement