Page 1 of 1

Allow different frame counts if one of them is 1

Posted: Sat Apr 14, 2018 2:56 am
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
			}
		},
	}
},

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

Posted: Mon Apr 16, 2018 8:47 am
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.

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

Posted: Mon Apr 16, 2018 11:24 am
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.

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

Posted: Mon Apr 16, 2018 11:52 am
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).

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

Posted: Mon Apr 16, 2018 9:50 pm
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!

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

Posted: Mon Jul 18, 2022 3:48 am
by brevven
For posterity, the function bobingabout referenced here is

Code: Select all

function util.multiplystripes(count, stripes)

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

Posted: Mon Jul 18, 2022 6:35 am
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

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

Posted: Tue Jul 19, 2022 6:19 am
by brevven
Oh brilliant! Thank you.