Allow different frame counts if one of them is 1

User avatar
QGamer
Fast Inserter
Fast Inserter
Posts: 215
Joined: Fri Apr 14, 2017 9:27 pm
Contact:

Allow different frame counts if one of them is 1

Post by QGamer »

I am trying to make a modded entity but am having issues with the graphics:
My entity's animation is 32 frames long. The shadow animation is only 1 frame. I get an error on startup because I'm not allowed to have different animation counts (32 vs. 1) in different layers.

I think an exception to this rule should be made: animations with 1 frame only should be allowed to coexist with animations that have many frames. My thinking behind this is that if there is only 1 frame, it's easier to select which frame to draw every tick (because there is only 1 choice) and therefore shouldn't hurt performance.

For reference, here is my code:

Code: Select all

animation =
{
	layers =
	{
		{
			filename = "file-path/entity-animation.png",
			priority = "high",
			width = 96,
			height = 96,
			frame_count = 32,
			line_length = 8,
			shift = util.by_pixel( 0, 4 ),
			hr_version =
			{
				filename = "file-path/hr-entity-animation.png",
				priority = "high",
				width = 192,
				height = 192,
				frame_count = 32,
				line_length = 8,
				shift = util.by_pixel( 0, 4 ),
				scale = 0.5
			}
		},
		{
			filename = "file-path/entity-shadow.png",
			priority = "high",
			width = 96,
			height = 96,
			frame_count = 1,
			draw_as_shadow = true,
			shift = util.by_pixel( 12, 5 ),
			hr_version =
			{
				filename = "file-path/hr-entity-shadow.png",
				priority = "high",
				width = 192,
				height = 192,
				frame_count = 1,
				draw_as_shadow = true,
				shift = util.by_pixel( 12, 4.75 ),
				scale = 0.5
			}
		},
	}
},
"Adam fell that men might be; and men are, that they might have joy."
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Allow different frame counts if one of them is 1

Post by bobingabout »

have you seen the way construction robot working animation works?

there's several facings, but that animation has 2 frames per facing, where all other sprites, including the shadow, only have one. They added a sprite multiplication function to double the shadow frames to make it work.

You could use the same thing, but I agree with the original request, if one of the sprite counts is a multiple of the other (not just 1, but say, 32 vs 8) then it should be allowed.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2529
Joined: Fri Nov 06, 2015 7:41 pm

Re: Allow different frame counts if one of them is 1

Post by Deadlock989 »

QGamer wrote:I am trying to make a modded entity but am having issues with the graphics:
My entity's animation is 32 frames long. The shadow animation is only 1 frame. I get an error on startup because I'm not allowed to have different animation counts (32 vs. 1) in different layers.

I think an exception to this rule should be made: animations with 1 frame only should be allowed to coexist with animations that have many frames. My thinking behind this is that if there is only 1 frame, it's easier to select which frame to draw every tick (because there is only 1 choice) and therefore shouldn't hurt performance.
Agreed, it's annoying when you have an animation that doesn't affect the shadow silhouette at all but you have to organise a shadow sprite sheet with 32 or more identical frames which uselessly take up VRAM.

In a couple of instances I've opted to not use a shadow layer at all but went back to having the shadows within the actual animation itself. Doesn't work well for tall entities that are routinely stacked up next to each other in arrays.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Allow different frame counts if one of them is 1

Post by eradicator »

Deadlock989 wrote: Agreed, it's annoying when you have an animation that doesn't affect the shadow silhouette at all but you have to organise a shadow sprite sheet with 32 or more identical frames which uselessly take up VRAM.
Shouldn't you be able to construct the shadow sheet in code dynamically using ".sheets="? I.e. by just running a for loop and adding the same single frame file 32 times. Everything that references the same file is hopefully deduplicated and doesn't consume VRAM for every instance. Identical frames in the same sheet are sadly not deduplicated, i asked a dev about that before :x (even though it should be trivial to add).
User avatar
QGamer
Fast Inserter
Fast Inserter
Posts: 215
Joined: Fri Apr 14, 2017 9:27 pm
Contact:

Re: Allow different frame counts if one of them is 1

Post by QGamer »

bobingabout wrote:have you seen the way construction robot working animation works?

there's several facings, but that animation has 2 frames per facing, where all other sprites, including the shadow, only have one. They added a sprite multiplication function to double the shadow frames to make it work.

You could use the same thing, but I agree with the original request, if one of the sprite counts is a multiple of the other (not just 1, but say, 32 vs 8) then it should be allowed.
Wow, thanks! I'd never noticed that the construction robots use a sprite multiplication function. That's amazing, and it worked for me!
"Adam fell that men might be; and men are, that they might have joy."
User avatar
brevven
Long Handed Inserter
Long Handed Inserter
Posts: 69
Joined: Mon May 01, 2017 1:02 am
Contact:

Re: Allow different frame counts if one of them is 1

Post by brevven »

For posterity, the function bobingabout referenced here is

Code: Select all

function util.multiplystripes(count, stripes)
posila
Factorio Staff
Factorio Staff
Posts: 5349
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Allow different frame counts if one of them is 1

Post by posila »

I don't remember when it was added, but there is also repeat_count which is made for exactly this purpose. Final frame count will be frame_count * repeat_count, so in this case, the shadow would have repeat_count = 32
User avatar
brevven
Long Handed Inserter
Long Handed Inserter
Posts: 69
Joined: Mon May 01, 2017 1:02 am
Contact:

Re: Allow different frame counts if one of them is 1

Post by brevven »

Oh brilliant! Thank you.
Post Reply

Return to “Implemented mod requests”