No responses yet, but i am interested to see if this is the right way to approach spine sprite runtime control.
I looked though the corona runtimes and noticed that you can add the skeleton to a corona group when creating a new skeleton. See below code.
What i would like to solve now is allow an individual limb to be controlled by a touch event. Eg make a leg rotate at hip. Does anyone have any suggestions how to reference specific limb of skeleton for touch events?
The following code allows the spine character now to be dragged around the screen.
local json = spine.SkeletonJson.new()
local skeletonData = json:readSkeletonDataFile("goblin.json")
---
add the skeleton to a touchable data file
---
the key here is to create a new displaygroup in corona
local skelGroup = display.newGroup()
local skeleton = spine.Skeleton.new(skeletonData,skelGroup )
---
touch listener function
function skelGroup:touch( event )
if event.phase == "began" then
self.markX = self.x
---
store x location of object
self.markY = self.y
---
store y location of object
elseif event.phase == "moved" then
local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY
self.x, self.y = x, y
---
move object based on calculations above
end
return true
end
---
make 'skeleton' listen for touch events
skelGroup:addEventListener( "touch", skelGroup )