Hello,
I don’t understand why this simpliest snippet lag :
It’s just a Character(a square) who move from left to right and an animation under the cursor ???
It’s lag only when my function CursorAnim() is activated, it’s an naimation who appears under my cursor.
When i comment this function CursorAnim() my Character move with no lag.
Could you explain to me what i’m doing wrong ?
Here I put the image (bouttonanim.png) resolution :100/100pixels here :
http://imgur.com/fyDBmr4
and there is the snippet without images except the buttonanim.png if you want to test my main.lua :
--NECESSARY local mathr = math.random local oRemove = display.remove --GROUP local myGroupBackground = display.newGroup() local myGroupCharacter = display.newGroup() local myGroupCursor = display.newGroup() --CHARACTER------------------------------------------------------------------------------------------- Character = display.newRect( myGroupCharacter,100,100,100,100 ) Character.x = 100 Character.y = 100 Character.xScale=1 Character.yScale =1 Character.myId = 1 Background = display.newRect( myGroupBackground,100,100,100,100 ) Background.x = 100 Background.y = 100 Background:setFillColor(1,0,1) Background.xScale=8 Background.yScale =8 Background.myId = 2 --DISPLACEMENT ON CHARACTER------------------------------- local function nextSide() transition.to(Character, {time=800, x=0}) end local function firstSide() transition.to(Character, {time=800, x=200, onComplete=nextSide}) end local function displacementOnMyCharacter() firstSide() end timer.performWithDelay(1600,displacementOnMyCharacter,-1) --ANIMATION ON CURSOR------------------------------------------------------------------------------ local function CursorAnim(d) --anim on cursor local CursorAnim = display.newImageRect( myGroupCursor, "bouttonanim.png", 180, 180) CursorAnim.x = d.x CursorAnim.y= d.y CursorAnim.xScale=0.6 CursorAnim.yScale=0.6 CursorAnim.alpha=1 local CursorAnim2 = display.newImageRect( myGroupCursor, "bouttonanim.png", 180, 180) CursorAnim2.x = d.x CursorAnim2.y= d.y CursorAnim2.xScale=0.8 CursorAnim2.yScale=0.8 CursorAnim2.alpha=0.2 local function removeCursorAnim() oRemove(CursorAnim) CursorAnim=nil end local function removeCursorAnim2() oRemove(CursorAnim2) CursorAnim2=nil end transition.to(CursorAnim, { time=150, x=CursorAnim.x, y=CursorAnim.y, yScale=0.3, xScale=0.3, alpha=0.5, onComplete=removeCursorAnim}) transition.to(CursorAnim2, {time=150, x=CursorAnim2.x, y=CursorAnim2.y, yScale=0.3, xScale=0.3, alpha=0.01, onComplete=removeCursorAnim2}) end --LISTENER ------------------------------------------------------------------------------------------- local function conditions(k) if k == 1 then print("character touched", "it's the number", k) elseif k == 2 then print("background touched") end --if end --conditions local function tapOnCharacter(event) if event.phase == "ended" then CursorAnim(event) target = event.target for k=1,2 do if target.myId == (k) then conditions(k) end --if end --if end -- for return true end Character:addEventListener("touch", tapOnCharacter) Background:addEventListener("touch", tapOnCharacter)