I need help on testing to see which direction a touch event is moving. If it is moving right, I want the character to move right, if it is moving left, I want the character to move left, and if it is moving up, I want the character to jump. Any ideas? Thanks. Here is the code for the file (dashes are around the lines that have the code that I need help on):
–
– level1.lua
local storyboard = require(“storyboard”)
local scene = storyboard.newScene()
local widget = require “widget”
– BEGINNING OF YOUR IMPLEMENTATION
– NOTE: Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.
local physics = require(“physics”)
physics.start()
motionx = 0
speed = 2
function scene:createScene( event )
local group = self.view
– display a background1 image
local background = display.newImageRect(“Images/Level1.png”, dW,dH*1.2, true)
background.anchorX = 0
background.anchorY = 0
background.x, background.y = 160, 240
group:insert(background)
local ground1 = display.newImageRect(“Images/Ground1.png”, dW, 90, true)
ground1.x, ground1.y = dW*0.5, 480
group:insert(ground1)
physics.addBody(ground1, “static”, {friction=0.5,bounce=0})
ground1:setReferencePoint(display.BottomLeftReferencePoint)
local ground2 = display.newImageRect(“Images/Ground2.png”, dW, 90, true)
ground2.x, ground2.y = dW*0.5, 480
group:insert(ground2)
physics.addBody(ground2, “static”, {friction=0.5,bounce=0})
ground2:setReferencePoint(display.BottomLeftReferencePoint)
local character = display.newImage(“Images/Character.png”, 20, 20)
character.x, character.y = 40, 400
group:insert(ground1)
physics.addBody(character, “dynamic”, {friction=0.5, bounce=0.3})
self.character = character
group:addEventListener(“touch”, self)
function scene:touch(e)
local phase = e.phase
--if(phase == ‘moved’) then
--code to determine whether moving right
motionx = speed*2
character.x = character.x + motionx
end
if(phase == ‘ended’) then
motionx = 0
end
end
end