Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Why SpineLua perfomance is so bad in my test project?
Started by ogoji Nov 25 2018 03:38 AM

No replies to this topic
spine animation
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

ogoji

[GLOBAL: userInfoPane.html]
ogoji
  • Observer

  • 1 posts
  • Corona SDK

Hey guys!
 
I've just tested Spine animation, due to extremely low perfomance it looks literally UNUSABLE (I'm not even sure if anybody from Corona users could ever use SpineLua in any actual project)
I'm getting only 22fps when I spawn just 10 objects (on a pretty good hardware, most of android users have much slower phones)
With such extremely low perfomance we can have maybe one or two Spine objects on stage, not more.
It's literally hundred times slower than traditional frame-based animation.

Can you pls check my simple code snippet? Maybe something in my code is extremely inefficient?
My project resolution: 1280x720, I've attached my spine atlas&png&json to the post.
local spine = require "spine-gideros.spine"

function loadSkeleton(atlasFile, jsonFile, x, y, scale, animation, skin)
	-- to load an atlas, we need to define a function that returns
	-- a Corona paint object. This allows you to resolve images
	-- however you see fit
	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.x = x
	skeleton.group.y = 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 the skeleton invisible
	skeleton.group.isVisible = false

	-- set a name on the group of the skeleton so we can find it during debugging
	skeleton.group.name = jsonFile

	-- set some event callbacks
	animationState.onStart = function (entry)
		print(entry.trackIndex.." start: "..entry.animation.name)
	end
	animationState.onInterrupt = function (entry)
		print(entry.trackIndex.." interrupt: "..entry.animation.name)
	end
	animationState.onEnd = function (entry)
		print(entry.trackIndex.." end: "..entry.animation.name)
	end
	animationState.onComplete = function (entry)
		print(entry.trackIndex.." complete: "..entry.animation.name)
	end
	animationState.onDispose = function (entry)
		print(entry.trackIndex.." dispose: "..entry.animation.name)
	end
	animationState.onEvent = function (entry, event)
		print(entry.trackIndex.." event: "..entry.animation.name..", "..event.data.name..", "..event.intValue..", "..event.floatValue..", '"..(event.stringValue or "").."'")
	end
	
  if atlasFile == "spineboy.atlas" then
    animationStateData:setMix("walk", "jump", 0.4)		
		animationStateData:setMix("jump", "run", 0.4);
		animationState:setAnimationByName(0, "walk", true)
		local jumpEntry = animationState:addAnimationByName(0, "jump", false, 3)
		animationState:addAnimationByName(0, "run", true, 0)
  elseif atlasFile == "raptor.atlas" then
		--skeleton.vertexEffect = spine.JitterEffect.new(5, 5)
		skeleton.vertexEffect = swirl
		animationState:setAnimationByName(0, animation, true)
	else
    animationState:setAnimationByName(0, animation, true)
  end

	-- 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", math.random(160,570),math.random(160,1100), 1, "rooster_run_anim")
end

Runtime:addEventListener("enterFrame", 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





[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: spine, animation