Hi all,
I’ve got a card game in the works, and I’m trying to work on a system that will make a square frame move to a selected die to highlight it.
I put a listener on each die, so that when a die is touched, it’s supposed to move the frame to positions die.x and die.y, die1.x and die1.y, etc… However, if I define the listener first, it won’t recognize the die’s coordinates, since they’re not defined yet. And if I define the die first, it won’t recognize the listener as that hasn’t been defined yet.
I’ve been reading up on passing parameters but I’m still unsure as to how to make this particular setup work (as you can see I use Director). If anyone could point me in the right direction I’d appreciate it. Thanks very much.
Here’s the code I had:
[code]local function dieRead(event)
if event.phase == “ended” then
dieFrame.x=die.x
dieFrame.y=die.y
end
end
local die = sprite.newSprite( diceSet )
die.x = 55
die.y = 55
die.value=1
die:prepare(“die”)
die:addEventListener( “touch”, dieRead )
local dieFrame = display.newImage(“dieframe.png”)
dieFrame.x = 222
dieFrame.y = 222
localGroup:insert(dieFrame)
…
die:addEventListener(“touch”,dieRead)[/code] [import]uid: 144359 topic_id: 31437 reply_id: 331437[/import]