Touch of Puzzle Piece

is it possible touch puzzle piece and move any where in simulator…please help me out [import]uid: 87661 topic_id: 17537 reply_id: 317537[/import]

Yes it is :slight_smile:

Assuming you want to drag the puzzle piece, you’d do something like this;

[lua]local function movePiece (event)
puzzlepiece.x = event.x
puzzlepiece.y = event.y
end
puzzlepiece:addEventListener(“touch”, movePiece)[/lua]

That assumes your object is called puzzlepiece, if not you’d change that accordingly.

Make sense?

Peach :slight_smile: [import]uid: 52491 topic_id: 17537 reply_id: 66650[/import]

alwaysom,

Please edit your post using [text][lua][/text] before your code and [text][/lua][/text] after your code block. It will make it more readable to help you out.

-David
[import]uid: 96411 topic_id: 17537 reply_id: 66731[/import]

Which line is error reportedly on?

Have added lua tags.

Peach :slight_smile: [import]uid: 52491 topic_id: 17537 reply_id: 66863[/import]

Don’t define your function with two parameters. When startDrag gets called, the event that gets caught will go into the first parameter, in this case “self”.

You don’t need self. Use event.target instead.

Edit: to be more clear, the event caught will go into the first parameter, so that the second parameter “event” will be nil, causing the error. You want event to be the only parameter to that function, and if you need access to the puzzle piece object itself you can find it in event.target. [import]uid: 70391 topic_id: 17537 reply_id: 66877[/import]

hey peach pellen
thanks for replay but i am doing from different way but it is giving error like

I am getting an error…
attempt to index local ‘event’ a nil value
[lua]local function startDrag( self, event )
if isReady then
if event.phase == “began” then
display.getCurrentStage():setFocus( self )
self.isFocus = true
finalPiece = lastPiece

check=true
elseif self.isFocus then
if event.phase == “moved” then

– moved phase code here
finalPiece = lastPiece

check=true

if shadowOn then
finalShadow = lastShadow
end
if finalPiece then
Xposition = finalPiece.x
Yposition = finalPiece.y
if shadowOn then
finalShadow.isVisible = true
finalShadow:toFront()
XSposition = finalShadow.x
YSposition = finalShadow.y
end

finalPiece:toFront()

transition.to(finalPiece , { time =500 , xScale = 1.0 , yScale = 1.0 } )

if shadowOn then
transition.to( finalShadow , { time =500 , xScale = 1.0 , yScale = 1.0 } )
end
end

if isDragging and finalPiece then
finalPiece.x = event.x
finalPiece.y = event.y
if shadowOn then
finalShadow.x = event.x
finalShadow.y = event.y
end
end

elseif event.phase == “cancelled” or event.phase == “ended” then
display.getCurrentStage():setFocus( nil )
self.isFocus = nil
isDragging = false
isSelected = false

if finalPiece and check then
transition.to( finalPiece , { time =500 , x = Xposition , y = Yposition , xScale = .45 , yScale = .45 } )
else
transition.to( finalPiece , { time =500 , xScale = 1 , yScale = 1 } )
end
if finalShadow and check then
finalShadow.isVisible = false
transition.to( finalShadow , { time =500 , x=XSposition , y = YSposition, xScale = .45 , yScale = .45 } )
else
transition.to( finalShadow , { time =500 , xScale = 1 , yScale = 1 } )
end
end
end

return true
end
end[/lua]

*Edit: Lua tags added by Peach. [import]uid: 87661 topic_id: 17537 reply_id: 66661[/import]