Hello,
I’m trying to develop a small rpg game and I am having some problems when launching the character animation taking steps and moving the character.
The problem comes when I press the button and keep it pressed, the character moves until I release the button, but the animation that must do, only played once.
I want that for every two frames to advance the character, the animation be shown.
The code is as follows:
local options =
{
width = 44,
height = 44,
numFrames = 12
}
local buttonPressed = false
local mySheet = graphics.newImageSheet( "imagenes/ic\_example.png", options )--Declaramos la animación y le damos una imagen
--Animación de imagenes consecutivas:
--Animación de imagenes no consecutivas:
local sequenceData = {
{ name = "arriba",
frames = { 10,11,12}, --Especificamos el orden de los indices del frame de la animación.
time = 500,
loopCount = 1
}, --Si queremos definar mas secuencias, ponemos una coma aqui y ponemos la siguiente secuencia en una subtabla.
{ name = "abajo",
frames = { 1,2,3},
time = 500,
loopCount = 1
}
}
local animation = display.newSprite( mySheet, sequenceData )--declaramos la animación
--posicionamos la animación en el centro del mapa y procedemos a su movimiento
--Animación arriba:
animation.x = display.contentWidth/2 --center the sprite horizontally
animation.y = display.contentHeight/2 --center the sprite vertically
--animación abajo:
---------------------------------------------| BOTON ADELANTE |-------------------------------------
local botonalante = display.newImage("imagenes/botonalante.png")
botonalante.x = display.contentWidth / 2 --Posiciona el boton en el centro orizontal de la pantalla
botonalante.y = display.contentHeight -130 --Posiciona el boton a 75 pixels en vertical
function moveradelante( event )
-- Move up
if buttonPressed then
animation:setSequence( "arriba" )
animation:play()
animation.y = animation.y - 2
end
buttonPressed=false -- Whithout that the character advance, but the animations won't reproduce
end
--timer.performWithDelay(10000, moveradelante,1)
--timer.performWithDelay( 1000, function()
-- hello\_world( "first", "second" )
--end, 1 )
function botonalante:touch(event)
if event.phase == "began" then
buttonPressed = true
elseif event.phase == "ended" then
buttonPressed = false
end
return true
end
botonalante:addEventListener("touch", botonalante)
--Runtime:addEventListener("enterFrame", moveCharacter)
Runtime:addEventListener("enterFrame", moveradelante)
if I have not explained well let me know that, my English is quite good even.
Thank you very much ^ ^
[import]uid: 156044 topic_id: 35155 reply_id: 335155[/import]