Drag and drop the loqSprite object in the crown

I am new to using loqSprite, I try to drag the loqSprite sprite object, but it cannot be executed, however it only calls its listener once, and then after no touch list is called, it doesn’t even give any errors, the sprite is playing. I also thought that maybe my drag / drop function might be a mistake, but when I tried the same drag and drop function (movePen ()) on the Sprint inbult corona object, it works fine. what I’m missing, I don’t know. Can someone please help me .... below is a code snippet. thanks

local function movePen(event) local targetObj= event.target; if event.phase == 'began' then display.getCurrentStage():setFocus(targetObj); targetObj.isFocus = true; targetObj.y = event.y; elseif event.phase == 'moved' then targetObj.x = event.x; targetObj.y = event.y; elseif event.phase == 'ended' then display.getCurrentStage():setFocus(nil); targetObj.isFocus = false; end return true; end --end of touch/move function local spriteFactoryForPen = loqsprite.newFactory('penAnimation') local penSpriteAnim = spriteFactoryForPen:newSpriteGroup('pen_write') penSpriteAnim.x = 100 penSpriteAnim.y = 200 local function spriteEvent (e) --listener to play in loop if(e.phase == "end") then penSpriteAnim:play() end end -- end of sprit event function penSpriteAnim:addEventListener("touch", movePen); -- adding listener to move pen object penSpriteAnim:addEventListener("sprite", spriteEvent) -- adding listener to play in loop penSpriteAnim:play('pen_write') -- playing pen Sprite 
+4
source share
1 answer

First of all, there is no need to call penSpriteAnim: play () in a loop. Since it will automatically play in a loop until you call the penSpriteAnim: pause () function.

For your touch listener, you must declare the entire local variable at the top of the page. I'm not sure about this, but hope it works. Because lua compiles from top to bottom.

0
source

Source: https://habr.com/ru/post/1439116/


All Articles