Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local physics = require('physics')
- physics.start()
- physics.setGravity(0, 0)
- local image = display.newImageRect( "testimage.png" ,40,40)
- _H = display.contentHeight
- _W = display.contentWidth
- image.x = 40
- image.y = 40
- local isheld = false
- local isheld2 = false
- physics.addBody(image)
- local widget = require( "widget" )
- -- Function to handle button events
- local function goRight(event)
- if ( "began" == event.phase ) then
- isheld = true
- end
- if ( "ended" == event.phase or "cancelled" == event.phase) then
- isheld = false
- end
- end
- local function goLeft(event)
- if ( "began" == event.phase or "moved" == event.phase ) then
- isheld2 = true
- end
- if ( "ended" == event.phase or "cancelled" == event.phase) then
- isheld2 = false
- end
- end
- -- loop to handle moving
- local function move( event )
- if (isheld) then
- image.x = image.x + 3
- end
- if (isheld2) then
- image.x = image.x - 3
- end
- end
- -- button widgets
- local button1 = widget.newButton
- {
- left = 100,
- top = 400,
- id = "button1",
- onEvent = goRight,
- defaultFile = "testimage.png"
- }
- local button2 = widget.newButton
- {
- left = 50,
- top = 400,
- id = "button1",
- onEvent = goLeft,
- defaultFile = "testimage.png"
- }
- Runtime:addEventListener( "enterFrame", move)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement