Jump to content

[SOLVED] Wrong Spriter In-game Image


Recommended Posts

I've created two sets of trinket-like items: toys and plushies.

First I made the toys, for which I made a single Spriter project with all of them and created a generic generation function for the prefabs.
These work 100%.

Then I made a copy of this file for the plushies and created a new Spriter project for them in a similar fashion.
For some reason, only the first item in the plushies list (bunny) has the correct image when dropped on the ground.
The second item (elephant) has the image of the bunny, and the rest are invisible.
This is despite the fact that there is absolutely no special treatment for any of them.
I.e. the code simply has a list of IDs, of which "bunny", "elephant" and "fox" are three, and the Spriter project has an entity for each plush with its name and an "idle" animation with the still image.

Here is a screenshot with three plushies and three toys, both in the inventory and on the ground:

Problem.thumb.jpg.ec1a7eb3531a7a0b330be9a653c6fd87.jpg

You can see the name of the second bunny on the floor is "Plush Elephant", which in the inventory does show up as an elephant (second item on the left).
And here is a screenshot of the Spriter project.

5ba063ab3e92e_Problem-Spriter.thumb.jpg.1195f7c4980da2df1123f461c2230036.jpg

I have closed the Spriter project, deleted the anim file, exited the game, invoked the autocompiler manually, saw it export the plushies, ran the game again and checked once more and it's still like this, so I know for sure that what I'm seeing in-game represents the current state of the code and the Spriter project.

All the inventory images work fine, the names are good, just the images for when the items are on the ground are wrong in this weird fashion.

And once again, I use the same exact mechanism for the toys and they work just fine.
I'm really stumped here.

Here is the code for the plushies (plushies.lua):

local PLUSHNAMES =
{
	bunny = "Plush Bunny",
	elephant = "Plush Elephant",
	fox = "Plush Fox",
	kitty = "Plush Kitty",
	lion = "Plush Lion",
	puppy = "Plush Puppy",
	raccoon = "Plush Raccoon",
	trex = "Plush T-Rex",
	turkey = "Plush Turkey",
}


local assets =
{
	Asset("ANIM", "anim/plushies.zip"),
}

for id, name in pairs(PLUSHNAMES) do
	local prefabid = "plush_"..id
	table.insert(assets, Asset("ATLAS", "images/inventoryimages/"..prefabid..".xml"))
	table.insert(assets, Asset("IMAGE", "images/inventoryimages/"..prefabid..".tex"))
end


local function MakePlush(id, name)
	local prefabid = "plush_"..id
	
	local function fn()
		local inst = CreateEntity()
		
		inst.entity:AddTransform()
		inst.entity:AddAnimState()
		inst.entity:AddSoundEmitter()
		inst.entity:AddNetwork()
		
		MakeInventoryPhysics(inst)
		
		inst.AnimState:SetBank(id)
		inst.AnimState:SetBuild("plushies")
		inst.AnimState:PlayAnimation("idle")
		
		inst:AddTag("plush")
		
		inst.entity:SetPristine()
		
		if not TheWorld.ismastersim then
			return inst
		end
		
		inst:AddComponent("inspectable")
		
		inst:AddComponent("inventoryitem")
		inst.components.inventoryitem.atlasname = "images/inventoryimages/"..prefabid..".xml"
		
		MakeHauntableLaunchAndSmash(inst)
		
		return inst
	end
	
	STRINGS.NAMES[string.upper(prefabid)] = name
	
	return Prefab(prefabid, fn, assets, prefabs)
end

local ret = {}
for id, name in pairs(PLUSHNAMES) do
	table.insert(ret, MakePlush(id, name))
end

return unpack(ret)

 

And for reference, here is the code for the toys (toys.lua):

local TOYNAMES =
{
	cube = "Rubik's Cube",
	ball = "Toy Ball",
	-- legopieces = "Lego Pieces", -- Commented out for manual insertion as a repairer
	vroom = "Toy Car",
	tablet = "Tablet",
	bucket = "Bucket and Shovel",
	duck = "Rubber Duck",
	frisbee = "Frisbee",
	armymen = "Army Men",
}


local assets =
{
	Asset("ANIM", "anim/toys.zip"),
}

for id, name in pairs(TOYNAMES) do
	local prefabid = "toy_"..id
	table.insert(assets, Asset("ATLAS", "images/inventoryimages/"..prefabid..".xml"))
	table.insert(assets, Asset("IMAGE", "images/inventoryimages/"..prefabid..".tex"))
end


local function MakeToy(id, name, repairer)
	local prefabid = "toy_"..id
	
	local function fn()
		local inst = CreateEntity()
		
		inst.entity:AddTransform()
		inst.entity:AddAnimState()
		inst.entity:AddSoundEmitter()
		inst.entity:AddNetwork()
		
		MakeInventoryPhysics(inst)
		
		inst.AnimState:SetBank(id)
		inst.AnimState:SetBuild("toys")
		inst.AnimState:PlayAnimation("idle")
		
		inst:AddTag("molebait")
		inst:AddTag("cattoy")
		inst:AddTag("toy")
		
		inst.entity:SetPristine()
		
		if not TheWorld.ismastersim then
			return inst
		end
		
		inst:AddComponent("inspectable")
		inst:AddComponent("stackable")
		inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM
		
		inst:AddComponent("inventoryitem")
		inst.components.inventoryitem.atlasname = "images/inventoryimages/"..prefabid..".xml"
		
		if repairer then
			inst:AddComponent("repairer")
			inst.components.repairer.repairmaterial = MATERIALS.PLASTIC
			inst.components.repairer.healthrepairvalue = TUNING.REPAIR_CUTSTONE_HEALTH
		end
		
		MakeHauntableLaunchAndSmash(inst)
		
		return inst
	end
	
	STRINGS.NAMES[string.upper(prefabid)] = name
	
	return Prefab(prefabid, fn, assets, prefabs)
end

local ret = {}
for id, name in pairs(TOYNAMES) do
	table.insert(ret, MakeToy(id, name))
end

table.insert(ret, MakeToy("legopieces", "Lego Pieces", true))

return unpack(ret)

 

Any help would be greatly appreciated.
Thanks in advance.

Link to comment
Share on other sites

There are two solutions for this. The first method is to create a Spriter project for each different plushie. The second, and my preferred, method is to create separate animations for each plushie in one Spriter project.

For the first method, you need to separate them into nine Spriter projects for each plushie. Assume that you name them as bunny.scml, elephant.scml, fox.scml, and so on. You'll have to replace this part of fn() :

inst.AnimState:SetBank(id)
inst.AnimState:SetBuild(id)
inst.AnimState:PlayAnimation("idle")

For the second method, you just need to have separate animations for each of them in plushies.scml, like so:
image.png.e6bcfa15cd51476bd24c2dbe76a60f55.png

And then they just need to play the animation:

inst.AnimState:SetBank("plushies")
inst.AnimState:SetBuild("plushies")
inst.AnimState:PlayAnimation(id)

 

Edited by JohnWatson
Link to comment
Share on other sites

Thank you very much; using different animations under the same bank solved the issue and now they render properly. =)

I still don't understand why what I did didn't work, though.
And especially why the bunny and elephant worked different from the others.
It's no longer an issue to solve, but I'm really curious to know that.
Do you have any idea?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...