• Runtimes
  • Creating Spine Animations and Touch Control Corona

Related Discussions
...

Hi All,

I am struggling to control spine runtime skeletons in corona SDK

I can create the character from the demo code, but want to interact with object, eg manipulate whole character or limbs with touch events. But i cant figure out how to. Can someone please help?

heres my code so far


---

 heres the character creation 
local json = spine.SkeletonJson.new()
local skeletonData = json:readSkeletonDataFile("goblin.json")
local skeleton = spine.Skeleton.new(skeletonData)



---

 if i want to move then whole skeleton i tried the following



---

 touch listener function
function skeleton: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 skeleton:addEventListener( "touch", skeleton ) --- How would i reference an individual limb and move that wit a touch event local rightLeg = skeleton:findBone("right upper leg")

your help would be much appreciated
Nick

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 )

Thanks Nate. I have, but i am just trying to integrate into corona lua and get my head around it. For instance, if i want to do touch control of a limb, is there anything special i need to do to update the skeleton bone - eg calling render each time etc. I havent yet got my code compiling so i cant post anything yet

An animation just edits the bones' local SRT, the same as you might do for procedural animation. You can apply the animation, then edit the bone's further, and do everything else as normal.