Adding event listeners to sprites

Hi Everyone,

I have a sprite packed in Spriteloq and I would like to add an event listener to it in the game. For example, while the sprite is going through its animations, I'd like to be able to drag it around the screen.

I tried the following, which does not work:

1
2
3
4
5
6
7
-- create spritegroup instance above, then the following
local function dragSprite(event)
    mySprite.x = event.x
    mySprite.y = event.y
end
 
mySprite:addEventListener("touch", dragSprite)

Look at the the DragMeMultiTouch sample code. It's self-explanatory for moving display objects around on screen. Have a look and see if that is what you need.

-David

Yes as David said.

Look at the Interface/DragMe sample in the Corona Sample Code.

views:1554 update:2011/11/14 9:16:56
corona forums © 2003-2011