How to change dinamically a texture in a Spine skeleton
-
Hi guys,
As i'm trying to add skeletal animation support for my latest game, I stumbled upon an old problem.
Basically, I'd like to have different characters, but have them use the same weapons/items, something like:
skeleton.arm.texture = custom_atlas.weapon1_region.texture
I can change the skin of the characters toggling skins but my idea was to replace the texture by code.
Changing skins is possible by doing
SetAttachment()
, but that means I'd need to put the weapons on all character atlases.I understand that it could be possible by using
AtlasAttachmentLoader()
, however, I can't seem to find a proper example for Haxe.This would also be needed in case I add customization support. To manually pick and replace a character's features, such as the head or a hat, like:
skeleton2.head.texture = custom_atlas4.head_region.texture
Any tip on this would be greatly appreciated!
-
Well, after some fiddling, looks like I somewhat found something that should work (from http://esotericsoftware.com/forum/Changing-Skins-Dynamically-In-Game-1131)...
I modified that snippet to get something like this...
var spineAtlas:Atlas = new Atlas(Assets.getText("assets/spineboy.atlas"), new FlixelTextureLoader("assets/")); var region:AtlasRegion = spineAtlas.findRegion("torso"); var attachment:RegionAttachment = new RegionAttachment("newhead"); attachment.rendererObject = region; var scaleX:Float = region.page.width / nextPOT(region.page.width); var scaleY:Float = region.page.height / nextPOT(region.page.height); attachment.setUVs(region.u * scaleX, region.v * scaleY, region.u2 * scaleX, region.v2 * scaleY, region.rotate); attachment.regionOffsetX = region.offsetX; attachment.regionOffsetY = region.offsetY; attachment.regionWidth = region.width; attachment.regionHeight = region.height; attachment.regionOriginalWidth = region.originalWidth; attachment.regionOriginalHeight = region.originalHeight; skeleton.setAttachment("right-arm", "newhead");
...is supposed to do something like this...
... but crashes at runtime.