Wow! That's got to hurt... :clap:
That's what I'm talking about! Your simple code example clearly demonstrates the potential to create dynamically changing animations on the fly relative to user input, powerful stuff that opens up so many possibilities.
I didn't realize I could call spine.Animation like that. This technique should certainly work to aim my cannon, I'll be playing with it today.
I'm still hitting a wall resetting a non-looping animation's "time". When I run the main.lua posted below, which plays non-looping animations sequentially, it demonstrates the need to reset "time".
Yesterday I spent quite a bit of time trying to figure out how the Corona runtimes work and figured either the "time" or "duration" were the variables that needed to be reset to solve my issue.
Just to clarify, your Corona lua runtimes are above my coding level, although I am able to partially follow some of it.
I was able to manually reset the "duration" value to insure it was "0", I am not exactly sure how the code runs, so in case it wasn't seeing the declaration <local duration = 0> in SkeletonJson.lua because "loop = false", but that didn't work.
Frankly, there are so many instances of "time" throughout the code, I have no idea where to reset it manually after a non-looping animation completes it's last frame.
If you find time, could you modify the main.lua posted below so it resets the "time" and works properly. This would be an good example for others to review also as I would think other users will run into this issue.
Nate wrote:
You can detect if an animation is complete by checking if the time is >= animation.duration.
I see what you are suggesting here and I should be able to code the function to keep track of an animations playing time, if I stumble, I'll ask for help.
I'm also wondering if it is possible to add more bones to the <spine.Animation.RotateTimeline.new()> call in your example code. Let's say I wanted to rotate the "right shoulder" at the same time the "head" rotates. I tried several modifications to your example code, but can't get it to work.
---
modified main.lua
local spine = require "spine.spine"
local walkAnimation
---
Optional attachment resolver customizes where images are loaded. Eg, could use an image sheet.
local attachmentResolver = spine.AttachmentResolver.new()
function attachmentResolver:createImage (attachment)
return display.newImage("data/" .. attachment.name .. ".png")
end
local json = spine.SkeletonJson.new(attachmentResolver)
json.scale = 1
local skeletonData = json:readSkeletonDataFile("data/spineboy-skeleton.json")
walkAnimation = json:readAnimationFile(skeletonData, "data/spineboy-walk.json")
local function startSnapHead()
local timeline = spine.Animation.RotateTimeline.new()
timeline.boneIndex = skeletonData:findBoneIndex("head")
timeline:setKeyframe(0, 0, 0)
---
This is: keyframeIndex, time, angle
timeline:setKeyframe(1, 1.5, 90)
local timelines = {}
table.insert(timelines, timeline)
walkAnimation = spine.Animation.new(timelines, timeline:getDuration())
end
timer.performWithDelay(3000, startSnapHead)
timer.performWithDelay(6000, function() walkAnimation = json:readAnimationFile(skeletonData, "data/spineboy-walk.json") end)
timer.performWithDelay(9000, startSnapHead)
---
local walkAnimation = json:readAnimationFile(skeletonData, "data/spineboy-jump.json")
---
Optional second parameter can be the group for the Skeleton to use. Eg, could be an image group.
local skeleton = spine.Skeleton.new(skeletonData)
skeleton.x = 150
skeleton.y = 325
skeleton.flipX = false
skeleton.flipY = false
skeleton.debug = true
---
Omit or set to false to not draw debug lines on top of the images.
skeleton:setToBindPose()
Runtime:addEventListener("enterFrame", function (event)
walkAnimation:apply(skeleton, event.time / 1000, false)
---
true == loop infinitely / false == 1x loop
skeleton:updateWorldTransform()
end)
I've integrated my new Spine iBot into my app, if you'd like to see what I've been working on and how the cannon is being used take a look at this video I just made previewing the New Super iBot! It could be the first integration of Spine in an iOS app built with Corona SDK.
You've got to realize, I had zero animation experience 5 days ago before I found Spine and I've never used sprites either!
http://www.youtube.com/watch?v=WzrTfJ8ndf8
Thanks for the help,
Nail