Hi Nate, Hector for your posts, and any others who can help,
Firstly I hope adding onto this thread helps
I supported and bought spine in the first kickstarter, cos it looked awesome, so i have to say well done to the esoteric
team on creating and building on it. Second i use corona sdk as my coding environment, i was new to
game coding and corona has helped me learn alot. I realise theres other platforms but for now corona works for me.
I have been wanting to use spine to create in game animations, but i have been creating games with
physics simulation. As a result i have struggled to integrate the two. With the advent of bounding boxes
and some better lua support for meshes and other features i wanted to have another go at using spine in my game
animation.
I am sure i am not alone in corona sdk land.
Would you or your team please be able to take some time out of your busy schedule to help answer some of my questions
I am happy to post a few links back in the corona forums to spread your solutions if that helps too.
Use cases involving spine boy using box2d physics bodies and spine animation.
Use case 1: Walking
How can i use spine animation to move bounding box physics objects based on spine animation?
Use case 2:
If the skeleton falls i want to disable any spine animation, remove the joints, or runtime enter frame event restrictions, so that the skeleton breaks apart and the body parts/part breaks off and tumbles using physics.
Use case 3:
Can this skeleton react to collisions from other objects eg a cannon ball and topple over.
Use case 4:
Can we make the object a ragdoll, by applying joints, and have the spine skeleton joints react to physics. If so,
how do we find the correctly bone attachment points? Can we restrict joint mobility movement, eg cant bend an elbow backwards?
how do i traverse the pine skeleton to create these joints, eg ensuring i am
connecting the skeleton bones correctly and that they are aligned correctly (to prevent spine and box2D conflicting)?
heres the corona reference for joints if needed.
https://docs.coronalabs.com/guide/physics/physicsJoints/index.html#pivot local pivotJoint =
physics.newJoint( "pivot", bodyA, bodyB, anchor_x, anchor_y ) what would be the method to create a
joint using bones
Posts that i have been reading that see to to provide soem good fodder are: but no solution yet.
corona
[Corona] Help to position bounding box on a bone
Corona SDK: Example on using atlas and Bounding box
[Corona]How to make a bone follow a physics bounding Box
Performance issue in corona SDK
other
BB position like in SPINE
good code - cant quite get it to work
Box2D Controlled Character Movement
Make Spine character's parts follow box2d Bodies
Also heres my code attempt and resulting inverted and mis-scaled bounding boxes. image included as well.
Its my understanding that the errors might possibly have to do with my worldtransform calculations, or a difference in y axis sign between spine and corona.
I would really appreciate your, and anybody elses, assistance to get me over this conceptual hurdle i (an most likely others) face.
Thanks
Kadlugan aka Nick
PS As i understand the lua runtime is going through a revamp as we speak, feel free to comment how or if this has an effect.
---
This example shows simple usage of displaying a skeleton with queued animations.
local spine = require "spine-corona.spine"
local physics = require "physics"
physics.setDrawMode(
---
"normal" )
"hybrid" )
---
"debug" )
physics.start( true ); physics.setGravity( 0, 10 )
local rootDir = "examples/myExamples/spineboyPhysics/"
local json = spine.SkeletonJson.new()
json.scale = 0.4
---
so it fits on screen
local skeletonData = json:readSkeletonDataFile(rootDir .. "spineboy.json")
local skeleton = spine.Skeleton.new(skeletonData)
---
local sprites = spine.GetAtlasSprites( "examples/myExamples/spineboyPhysics/spineboy.atlas" )
local sprites = spine.GetAtlasSprites( rootDir .. "spineboy.atlas" )
sprites.ATLAS_HELPER_setup(skeleton)
skeleton.group.x = display.contentWidth * 0.5
---
skeleton.group.y = display.contentHeight * 0.9
skeleton.group.y = display.contentHeight * 0.5
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.debugAabb = true
skeleton:setToSetupPose()
local bounds = spine.SkeletonBounds.new()
---
AnimationStateData defines crossfade durations between animations.
local stateData = spine.AnimationStateData.new(skeletonData)
stateData:setMix("walk", "jump", 0.2)
stateData:setMix("jump", "run", 0.2)
---
AnimationState has a queue of animations and can apply them with crossfading.
local state = spine.AnimationState.new(stateData)
---
state:setAnimationByName(0, "test")
state:setAnimationByName(0, "walk", true)
---
state:addAnimationByName(0, "jump", false, 3)
---
state:addAnimationByName(0, "run", true, 0)
state.onStart = function (trackIndex)
---
print(trackIndex.." start: "..state:getCurrent(trackIndex).animation.name)
end
state.onEnd = function (trackIndex)
---
print(trackIndex.." end: "..state:getCurrent(trackIndex).animation.name)
end
state.onComplete = function (trackIndex, loopCount)
---
print(trackIndex.." complete: "..state:getCurrent(trackIndex).animation.name..", "..loopCount)
end
state.onEvent = function (trackIndex, event)
---
print(trackIndex.." event: "..state:getCurrent(trackIndex).animation.name..", "..event.data.name..", "..event.intValue..", "..event.floatValue..", '"..(event.stringValue or "").."'")
end
---
bounds:update(skeleton, true)
local bbPolygons = {}
local worldVertices = {}
for i, bb in ipairs(bounds.boundingBoxes) do
local bbName = bb.name
local boneName = string.sub(bb.name, 4)
---
name format eg "torso" from "bb-torso"
---
I would prefer a more direct way of finding attachment to slot to bone reference
---
Is there one?
print(bbName, boneName)
local bone = skeleton:findBone(boneName)
local attachment = skeleton:getAttachment (bbName, bbName)
---
local attachment = bone:getLoadedAttachment()
---
is this function possible, to avoid name format fudge above
---
or can i get it frome a slot search.
---
what is the best way
local vertices = attachment.vertices
---
where do i use this.
---
attachment:computeWorldVertices (skeleton.x, skeleton.y, bone, worldVertices)
local polygon = display.newPolygon(skeleton.group, 0, 0, vertices)
polygon:setFillColor(1, 0, 0, 1)
polygon.strokeWidth = 1
polygon:setStrokeColor(1, 0, 0, 1)
---
to make it easier to access the various elements later?? or is there a better way
polygon.attachment = attachment
polygon.bone = bone
polygon.vertices = vertices
---
Do i need to manipulate these vertices to flip their
---
y position
---
add the physics body
physics.addBody(polygon, "static", {shape=vertices})
table.insert(bbPolygons, polygon)
end
local lastTime = 0
Runtime:addEventListener("enterFrame", function (event)
---
Compute time in seconds since last frame.
local currentTime = event.time / 1000
local delta = currentTime - lastTime
lastTime = currentTime
---
Update the state with the delta time, apply it, and update the world transforms.
state:update(delta)
state:apply(skeleton)
skeleton:updateWorldTransform()
---
update the bounding box polygons
for i, polygon in ipairs(bbPolygons) do
---
polygon.attachment:computeWorldVertices (skeleton.x, skeleton.y, polygon.bone, worldVertices)
---
is this needed each frame?? Can i use it to fix my problems with orientations?
---
Update the bounding boxes position
polygon.x = skeleton.x + polygon.bone.worldX
polygon.y = skeleton.y + polygon.bone.worldY
polygon.rotation = polygon.bone.worldRotation
polygon.xScale = polygon.bone.worldScaleX
polygon.yScale = polygon.bone.worldScaleY
end
end)