Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local spine = require "spine-gideros.spine"
- local function loadSkeleton(atlasFile, jsonFile, x, y, scale, animation, skin)
- local imageLoader = function (path)
- local paint = { type = "image", filename = "data/" .. path }
- return paint
- end
- -- load the atlas
- local atlas = spine.TextureAtlas.new(spine.utils.readFile("data/" .. atlasFile), imageLoader)
- -- load the JSON and create a Skeleton from it
- local json = spine.SkeletonJson.new(spine.AtlasAttachmentLoader.new(atlas))
- json.scale = scale
- local skeletonData = json:readSkeletonDataFile("data/" .. jsonFile)
- local skeleton = spine.Skeleton.new(skeletonData)
- skeleton.flipY = true -- Corona's coordinate system has its y-axis point downwards
- skeleton.group:setPosition(x,y)
- -- Set the skin if we got one
- if skin then skeleton:setSkin(skin) end
- -- create an animation state object to apply animations to the skeleton
- local animationStateData = spine.AnimationStateData.new(skeletonData)
- animationStateData.defaultMix = 0.2
- local animationState = spine.AnimationState.new(animationStateData)
- -- set a name on the group of the skeleton so we can find it during debugging
- skeleton.group.name = jsonFile
- animationState:setAnimationByName(0, animation, true)
- -- return the skeleton an animation state
- return { skeleton = skeleton, state = animationState }
- end
- local allSpineLuaObjects={}
- local function spawnSpineLuaObject()
- allSpineLuaObjects[#allSpineLuaObjects+1]=loadSkeleton("rooster.atlas", "rooster.json", random(0,160,570),random(0,160,1100), 1, "rooster_run_anim")
- end
- stage:addEventListener(Event.ENTER_FRAME, function(event)
- local delta = event.deltaTime
- for i=1,#allSpineLuaObjects do
- allSpineLuaObjects[i].state:update(delta)
- allSpineLuaObjects[i].state:apply(allSpineLuaObjects[i].skeleton)
- allSpineLuaObjects[i].skeleton:updateWorldTransform()
- end
- end)
- for i=1,10 do
- spawnSpineLuaObject() --I'm getting only 22fps on a decent phone hardware :(
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement