Created
April 9, 2013 01:01
-
-
Save tangzero/5342036 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
system = require("spine-hp/system") | |
spine = require("spine-hp/spine") | |
local width, height = 640, 480 | |
MOAISim.openWindow("MOAI and Spine", width, height) | |
local viewport = MOAIViewport.new() | |
viewport:setSize(width, height) | |
viewport:setScale(width, -height) | |
local layer = MOAILayer2D.new() | |
layer:setViewport(viewport) | |
MOAISim.pushRenderPass(layer) | |
local attachmentLoader = spine.AttachmentLoader.new() | |
function attachmentLoader:createImage(attachment) | |
local deck = MOAIGfxQuad2D.new() | |
deck:setTexture("data/" .. attachment.name .. ".png") | |
deck:setUVRect(0, 0, 1, 1) | |
local prop = MOAIProp.new() | |
prop:setDeck(deck) | |
layer:insertProp(prop) | |
function prop:setSize(width, height) | |
deck:setRect(0, 0, width, height) | |
self:setPiv(width / 2, height / 2, 0) | |
end | |
function prop:setPos(x, y) | |
prop:setLoc(x + attachment.width / 2, y + attachment.height / 2, 0) | |
end | |
return prop | |
end | |
local json = spine.SkeletonJson.new(attachmentLoader) | |
json.scale = 1 | |
local skeletonData = json:readSkeletonDataFile("data/spineboy.json") | |
skeleton = spine.Skeleton.new(skeletonData) | |
skeleton.x = 0 | |
skeleton.y = 200 | |
skeleton.flipX = false | |
skeleton.flipY = false | |
skeleton:setToBindPose() | |
local animationStateData = spine.AnimationStateData.new(skeletonData) | |
animationStateData:setMix("walk", "jump", 0.2) | |
animationStateData:setMix("jump", "walk", 0.2) | |
local animationState = spine.AnimationState.new(animationStateData) | |
animationState:setAnimation("walk", true) | |
local main = MOAIThread.new() | |
main:run(function() | |
while true do | |
animationState:update(MOAISim.getStep()) | |
animationState:apply(skeleton) | |
skeleton:updateWorldTransform() | |
if animationState.current.name == "jump" and animationState.currentTime > animationState.current.duration then | |
animationState:setAnimation("walk", true) | |
end | |
coroutine.yield() | |
end | |
end) | |
MOAIInputMgr.device.mouseLeft:setCallback(function(down) | |
if down and animationState.current.name ~= "jump" then | |
animationState:setAnimation("jump") | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment