smithsun

Hello there
In my game project i am interesting in having both the power of sprites and spine.
Meaning, I would like to apply an image/sprite sheet to be located like an attachment through
my game's lua code, on a bone --> I want it to follow and rotate with that bone.

E.g:
I create a spine animation using bones and body parts, but i want to animate the face details (eyes, brows, mouth etc.)
using a sprite sheet from within the corona code.

I know I can use spine for this by adding different images attached to a slot and then keying them,
but I want for e.g. the face's details animation to be separated from the body so I can randomly
activate those animations at runtime, regardless of the animations the body uses.
Also, what happens if i want to load many of those small animations and scroll between them. (sprite sheets can do that)

Is there a way i can do that using spine? if not is there away i can do what i asked?
It is kind of very important to me the use of such way to do that, any help or suggestion will be highly appreciated.
smithsun
  • Postovi: 6

jpoag

What you want to do is to replace self:createImage(attachment) on the skeleton instance. The goblins example shows:
local skeleton = spine.Skeleton.new(skeletonData)
function skeleton:createImage (attachment)
return display.newImage("examples/goblins/images/" .. attachment.name .. ".png")
end
But you should be able to use any DisplayObject derived class:
local skeleton = spine.Skeleton.new(skeletonData)
function skeleton:createImage (attachment)
if attachment and attachment.name == "replace_me" then return display.newSprite() end
return display.newImage("examples/goblins/images/" .. attachment.name .. ".png")
end
jpoag

Kickstarter 2 backer
  • Postovi: 154

smithsun

that is interesting, but how do i refer to that image again after i set it, later in the code, so i can change what animation is played with that attachment?
thanks again
smithsun
  • Postovi: 6

jpoag

Well, don't use a static lookup, use a table that you can change. I think if a table doesn't have a particular key, a lookup attempt will be nil. Or, since it's Lua, change out the whole function on the instance during runtime.
if attachment and mySprites[attachment.name] then return mySprites[attachment.name] end
Also, if you're hot swapping the image/attachment, you need to invalidate the cache for that slot or the whole skeleton. The skeleton has an images{} table keyed to the slot for the attachment! but I think if you drop the whole table it will be rebuilt the next update.
skeleton.images={}
jpoag

Kickstarter 2 backer
  • Postovi: 154

smithsun

O.K I will try that.
Thank you .

---

Working like magic!
Thanks jpoag.
smithsun
  • Postovi: 6


Natrag na Runtimes