I have been working on a board game type project with drag and drop properties and I have created this class for the pieces of the game. I have programmed it to move but the picture will not move when I drag. What do I need to change?
[lua]Piece = {}
function Piece:new(name , x, y, spaces, board)
self.piece = display.newImage(name, x, y)
self.x = x
self.y = y
self.canMove = true
self.board = board
self.spaces = spaces
return piece
end
function Piece:touch(event)
if self.canMove == true then
if event.phase == “began” then
print(“it worked”)
self.piece.markX = self.piece.x
self.piece.markY = self.piece.y
elseif event.phase == “moved” then
local x = (event.x - event.xStart) + self.piece.markX
local y = (event.y - event.yStart) + self.piece.markY
self.piece.x = x
self.piece.y = y
elseif event.phase == “ended” then
print(“end”)
if(Piece:canPlace() == true) then
print( “ta da” )
Piece:place()
else
Piece:removeSelf()
end
end
end
return true
end[/lua]
Don’t worry about the print statements. Those are just to know if the touch is being recognized. Also I did not include the coding for the place() and canPlace() methods. Assume they work. My problem is getting the image to move.