Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Essential calls for new 'Spine' plugin #enhancement #451

Open
Apollo144 opened this issue Oct 31, 2018 · 8 comments
Open

Essential calls for new 'Spine' plugin #enhancement #451

Apollo144 opened this issue Oct 31, 2018 · 8 comments

Comments

@Apollo144
Copy link
Contributor

Hi guys! IMO these calls are extremely important and essential:

SpineSprite:setSkin/getSkin()
SpineSprite:setSpeed/getSpeed()
SpineSprite:getAnimation()
SpineSprite:stopAnimation()
changeItem() --change or hide an image or an item that is attached to a slot
SpineSprite:hideBone/showBone()
Event.ANIMATION_START
Event.ANIMATION_STOP

Thx!

@Apollo144 Apollo144 changed the title Essential calls for new 'Spine' plugin Essential calls for new 'Spine' plugin #enhancement Nov 15, 2018
@hgy29
Copy link
Contributor

hgy29 commented Nov 26, 2018

StopAnimation already exists, you just have to set an emoty(nil) animation.

For other calls, can someone give me their possible implantation for lua based spine, to save me the need of learning spine internals myself ?

@Apollo144
Copy link
Contributor Author

@hgy29 sure!
That's how these calls look like in SpineLua runtime:

local char=loadSkeleton("character.atlas", "character.json", xPos, yPos, scale, "animation_name")

char.skeleton:setSkin("skin_name")
char.skeleton:setAttachment("slot_name","attached_image_name")

--I didn't find how animation speed is changed, probably it's inside 'AnimationState.lua':
function AnimationState:trackEntry (trackIndex, animation, loop, last)
--...
entry.timeScale = 1
entry.mixTime = 0
--...
end

Many thanks!

@Apollo144
Copy link
Contributor Author

P. S. yep, I've checked 'timeScale=1' param, we can change animation speed with it

"loadSkeleton" function from original Corona example with Event callbacks and TimeScale*2:

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: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

	--[[ 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]]

    animationState:setAnimationByName(0, animation, true).timeScale=2
	-- return the skeleton an animation state
	return { skeleton = skeleton, state = animationState }
end


@hgy29
Copy link
Contributor

hgy29 commented Nov 26, 2018

thanks, I will add more methods based on that. It seems like spine runtime doesn't have getters, only setters, so I will only implement setXXX calls. Anyway it is faster to store the values at lua side than to rely on a getter to fetch them.

hgy29 added a commit that referenced this issue Nov 26, 2018
@Apollo144
Copy link
Contributor Author

thanks, I will add more methods based on that. It seems like spine runtime doesn't have getters, only setters, so I will only implement setXXX calls. Anyway it is faster to store the values at lua side than to rely on a getter to fetch them.

YOU'RE AWESOME!!!!

@hgy29
Copy link
Contributor

hgy29 commented Dec 4, 2018

docs for upcoming version: https://wiki.giderosmobile.com/index.php/Spine

@Apollo144
Copy link
Contributor Author

Apollo144 commented Dec 5, 2018

docs for upcoming version: https://wiki.giderosmobile.com/index.php/Spine

Awesome!!
p. s. btw there's one tiny issue: when error occurs in 'SpineC' plugin, player silently crashes without printing anything to console. For example if we define non-existing json, app will crash:
local spineObj=SpineSprite.new("data/non-existing.json","data/idle_anim.atlas")
Probably it would be good if some info was printed, at least we will know the potential cause of the crash.

@hgy29
Copy link
Contributor

hgy29 commented Dec 5, 2018

Yes, I probably forgot some error checking. I will fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants