Advertisement
Guest User

spineLua bad perfomance

a guest
Nov 25th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.97 KB | None | 0 0
  1. local spine = require "spine-gideros.spine"
  2.  
  3. local function loadSkeleton(atlasFile, jsonFile, x, y, scale, animation, skin)
  4.     local imageLoader = function (path)
  5.         local paint = { type = "image", filename = "data/" .. path }
  6.         return paint
  7.     end
  8.  
  9.     -- load the atlas
  10.     local atlas = spine.TextureAtlas.new(spine.utils.readFile("data/" .. atlasFile), imageLoader)
  11.  
  12.     -- load the JSON and create a Skeleton from it
  13.     local json = spine.SkeletonJson.new(spine.AtlasAttachmentLoader.new(atlas))
  14.     json.scale = scale
  15.     local skeletonData = json:readSkeletonDataFile("data/" .. jsonFile)
  16.     local skeleton = spine.Skeleton.new(skeletonData)
  17.     skeleton.flipY = true -- Corona's coordinate system has its y-axis point downwards
  18.     skeleton.group:setPosition(x,y)
  19.  
  20.     -- Set the skin if we got one
  21.     if skin then skeleton:setSkin(skin) end
  22.  
  23.     -- create an animation state object to apply animations to the skeleton
  24.     local animationStateData = spine.AnimationStateData.new(skeletonData)
  25.     animationStateData.defaultMix = 0.2
  26.     local animationState = spine.AnimationState.new(animationStateData)
  27.  
  28.     -- set a name on the group of the skeleton so we can find it during debugging
  29.     skeleton.group.name = jsonFile
  30.  
  31.     animationState:setAnimationByName(0, animation, true)
  32.     -- return the skeleton an animation state
  33.     return { skeleton = skeleton, state = animationState }
  34. end
  35.  
  36. local allSpineLuaObjects={}
  37.  
  38. local function spawnSpineLuaObject()
  39.     allSpineLuaObjects[#allSpineLuaObjects+1]=loadSkeleton("rooster.atlas", "rooster.json", random(0,160,570),random(0,160,1100), 1, "rooster_run_anim")
  40. end
  41.  
  42. stage:addEventListener(Event.ENTER_FRAME, function(event)
  43.         local delta = event.deltaTime
  44.         for i=1,#allSpineLuaObjects do
  45.             allSpineLuaObjects[i].state:update(delta)
  46.             allSpineLuaObjects[i].state:apply(allSpineLuaObjects[i].skeleton)
  47.             allSpineLuaObjects[i].skeleton:updateWorldTransform()
  48.         end
  49. end)
  50.  
  51.  
  52. for i=1,10 do
  53.     spawnSpineLuaObject() --I'm getting only 22fps on a decent phone hardware :(
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement