Beginner question ?

hi,

I try to move a sprite with some arrow paint on screen. Works perfectly using “touch” eventlistener, but i should release the touch, and push again.

I want to make the same think, but without release. If the player press the right arrow and stay on it (without release), i want the sprite go on right.

I search in all corona example, search in a lot of tutos on Youtube, look a lot of API functions, but i find nothing about it.

Someone can say me what i should use for coding it ?

Thank you :slight_smile:

You will probably want to use a timer inside the “began” phase of the touch.  Then every X milliseconds move the sprite.

I try again my little code using “touch”, i do it like it :

local vaisseau=display.newImage("fusee16x32.png",100,100) local gauche=display.newImage("gauche.png",0,464) local bas=display.newImage("bas.png",16,464) local droite=display.newImage("droite.png",32,464) local haut=display.newImage("haut.png",16,448) function gauche:touch() if(vaisseau.x\>8) then vaisseau.x=vaisseau.x-4 end end function bas:touch() if(vaisseau.y\<display.contentHeight-16) then vaisseau.y=vaisseau.y+4 end end function droite:touch() if(vaisseau.x\<display.contentWidth-8) then vaisseau.x=vaisseau.x+4 end end function haut:touch() if(vaisseau.y\>16) then vaisseau.y=vaisseau.y-4 end end gauche:addEventListener("touch",gauche) bas:addEventListener("touch",bas) droite:addEventListener("touch",droite) haut:addEventListener("touch",haut)

It works if i clic on an arrow and don’t release it, but when i clic, i should stay 1 seconde, he move after this second.

I don’t know why he doesn’t start immediatly ?

maybe you can try this

 

function gauche:touch(event) if (event.phase == "began") then if(vaisseau.x\>8) then vaisseau.x=vaisseau.x-4 end end end

let me know if it worked.

You will probably want to use a timer inside the “began” phase of the touch.  Then every X milliseconds move the sprite.

I try again my little code using “touch”, i do it like it :

local vaisseau=display.newImage("fusee16x32.png",100,100) local gauche=display.newImage("gauche.png",0,464) local bas=display.newImage("bas.png",16,464) local droite=display.newImage("droite.png",32,464) local haut=display.newImage("haut.png",16,448) function gauche:touch() if(vaisseau.x\>8) then vaisseau.x=vaisseau.x-4 end end function bas:touch() if(vaisseau.y\<display.contentHeight-16) then vaisseau.y=vaisseau.y+4 end end function droite:touch() if(vaisseau.x\<display.contentWidth-8) then vaisseau.x=vaisseau.x+4 end end function haut:touch() if(vaisseau.y\>16) then vaisseau.y=vaisseau.y-4 end end gauche:addEventListener("touch",gauche) bas:addEventListener("touch",bas) droite:addEventListener("touch",droite) haut:addEventListener("touch",haut)

It works if i clic on an arrow and don’t release it, but when i clic, i should stay 1 seconde, he move after this second.

I don’t know why he doesn’t start immediatly ?

maybe you can try this

 

function gauche:touch(event) if (event.phase == "began") then if(vaisseau.x\>8) then vaisseau.x=vaisseau.x-4 end end end

let me know if it worked.