I’m trying to make it so when I click on an image the character moves his lips move like he’s talking for like each specific word that he says. I have separate images for each word I just don’t know how to make it change Thank you for all the help!!
You would add an onTouch event listener on the character, make any if statements there (if necessary) and then just change its sprites, but, you would have to set up multiple sprite animations:
local sequences_runningCat = {
– first sequence (consecutive frames)
{
name = “normalRun”,
start = 1,
count = 8,
time = 800,
loopCount = 0
},
– next sequence (non-consecutive frames)
{
name = “fastRun”,
frames = { 1,3,5,7 },
time = 400,
loopCount = 0
},
}
–Notice how there are two here.
Thank you! I looked at that guide and tried to do it but it wouldn’t work. The image would be put on the top-left side of the screen and no animation would happen :/
Well, you would have to show me your code. Also, look here:
https://docs.coronalabs.com/api/event/touch/index.html
This will help you figure out the touch function.
splay.setStatusBar( display.HiddenStatusBar ) local sheetOptions = { width = 242, height = 312, numFrames = 2 } local sheet\_mysprite = graphics.newImageSheet( "mysprite.png", sheetOptions ) -- sequences table local sequences\_mysprite = { { name = "normaltalk", start = 1, count = 2, time = 800, loopCount = 4 }, { name = "fasttalk", frames = { 1,2 }, time = 400, loopCount = 2 }, } local mysprite = display.newSprite( sheet\_mysprite, sequences\_mysprite ) -- sprite listener function local function spriteListener( event ) local mysprite = event.target -- "event.target" references the sprite if ( event.phase == "ended" ) then thisSprite:setSequence( "normaltalk" ) -- switch to "fastRun" sequence thisSprite:play() -- play the new sequence end end -- add the event listener to the sprite mysprite:addEventListener( "sprite", spriteListener )
I’m not sure what’s going on but it puts my sprite at the top left of the screen and I get no animation :/
Wait a minute, I will provide you with an example.
thank you
Good luck.
thank you so much :)
Hope this helps. Feel free to break apart the code and adapt it to what you are doing. Sorry, it took a while, I am 13 and I wouldn’t call myself “knowledgeable” in Lua and Corona SDK.
This is perfect extremely helpful thank you soo much!! I just have one last question how would I add a touch event listener to the sprite so it begins when I touch an object and I have a total of 4 objects.
Well, in order to do that, you would have to add the touch listener to the objects, not to the sprite, then you would just set the sprite to begin playing its animation.
If you want 4 objects, you would do:
local objects = {} local object local i local function onObjectTouch( event ) if ( event.phase == "ended" ) then soldier:setSequence("speedWalk") soldier:play() end return true end for i = 1, 4 do object = display.newRect(100, i \* 75, 50, 50) object = objects[i] end objects[i].touch = onObjectTouch objects[i]:addEventListener( "touch", objects[i] )
I figured it out, took me a while but I messed around with the code and it worked Thank you for the help though! I really appreciate it!
Your welcome.
You would add an onTouch event listener on the character, make any if statements there (if necessary) and then just change its sprites, but, you would have to set up multiple sprite animations:
local sequences_runningCat = {
– first sequence (consecutive frames)
{
name = “normalRun”,
start = 1,
count = 8,
time = 800,
loopCount = 0
},
– next sequence (non-consecutive frames)
{
name = “fastRun”,
frames = { 1,3,5,7 },
time = 400,
loopCount = 0
},
}
–Notice how there are two here.
Thank you! I looked at that guide and tried to do it but it wouldn’t work. The image would be put on the top-left side of the screen and no animation would happen :/
Well, you would have to show me your code. Also, look here:
https://docs.coronalabs.com/api/event/touch/index.html
This will help you figure out the touch function.
splay.setStatusBar( display.HiddenStatusBar ) local sheetOptions = { width = 242, height = 312, numFrames = 2 } local sheet\_mysprite = graphics.newImageSheet( "mysprite.png", sheetOptions ) -- sequences table local sequences\_mysprite = { { name = "normaltalk", start = 1, count = 2, time = 800, loopCount = 4 }, { name = "fasttalk", frames = { 1,2 }, time = 400, loopCount = 2 }, } local mysprite = display.newSprite( sheet\_mysprite, sequences\_mysprite ) -- sprite listener function local function spriteListener( event ) local mysprite = event.target -- "event.target" references the sprite if ( event.phase == "ended" ) then thisSprite:setSequence( "normaltalk" ) -- switch to "fastRun" sequence thisSprite:play() -- play the new sequence end end -- add the event listener to the sprite mysprite:addEventListener( "sprite", spriteListener )
I’m not sure what’s going on but it puts my sprite at the top left of the screen and I get no animation :/
Wait a minute, I will provide you with an example.
thank you