How do I animate a texture?

Place to post guides, observations, things related to modding that are not mods themselves.
rainawareness
Inserter
Inserter
Posts: 22
Joined: Sat May 14, 2022 12:07 am
Contact:

How do I animate a texture?

Post by rainawareness »

I've looked at a lotta modding guides but none I found mention animation, and I want to just switch between 2 frames on a timer. Could anyone please point me in the right direction?

robot256
Filter Inserter
Filter Inserter
Posts: 433
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: How do I animate a texture?

Post by robot256 »

Only certain entities allow animations. In those cases, the sprites must be defined by an animation structure in the prototype. Each frame of the animation must be defined in an image spritesheet and linked in the animation definition. See the Assembly Machine for example: https://wiki.factorio.com/Prototype/Cra ... #animation

rainawareness
Inserter
Inserter
Posts: 22
Joined: Sat May 14, 2022 12:07 am
Contact:

Re: How do I animate a texture?

Post by rainawareness »

robot256 wrote:
Sat May 14, 2022 12:57 am
Only certain entities allow animations. In those cases, the sprites must be defined by an animation structure in the prototype. Each frame of the animation must be defined in an image spritesheet and linked in the animation definition. See the Assembly Machine for example: https://wiki.factorio.com/Prototype/Cra ... #animation
Thank you. https://wiki.factorio.com/Prototype/LogisticRobot mentions only https://wiki.factorio.com/Types/RotatedAnimation I think. Could you please help me understand it? Is that how you animate logistic robots? Or is just for them like, spinning?

robot256
Filter Inserter
Filter Inserter
Posts: 433
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: How do I animate a texture?

Post by robot256 »

The assembler has "Animation4Way" because you can place it facing North, South, East, or West, and the animation can use a different spritesheet for each orientation.

The Logistic Bot has "RotatedAnimation" because it can be drawn in more than four orientations. The vanilla robots have separate animation spritesheets for 16 different orientations, to match the direction they are traveling. You can specify (almost) any number of rotations in the animation definition, and the game will pick the animation closest to the angle where the robot is really facing.

rainawareness
Inserter
Inserter
Posts: 22
Joined: Sat May 14, 2022 12:07 am
Contact:

Re: How do I animate a texture?

Post by rainawareness »

robot256 wrote:
Sat May 14, 2022 2:50 am
The assembler has "Animation4Way" because you can place it facing North, South, East, or West, and the animation can use a different spritesheet for each orientation.

The Logistic Bot has "RotatedAnimation" because it can be drawn in more than four orientations. The vanilla robots have separate animation spritesheets for 16 different orientations, to match the direction they are traveling. You can specify (almost) any number of rotations in the animation definition, and the game will pick the animation closest to the angle where the robot is really facing.
Ah, yes the rotation animation I think I'll leave unchanged. What I want to do is give logistic bots an idle animation, as in no matter where they are facing.
I know it must be possible because construction robots have this https://wiki.factorio.com/Prototype/Con ... ot#working animation, which also uses that RotatedAnimation thing. The working animation is a simple 2 frame loop it seems, all I want to do is have exactly that but for logistic robots, to make it look like they are moving. Do you perchance know what I can do? I couldn't look at that "working" code or anything.

robot256
Filter Inserter
Filter Inserter
Posts: 433
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: How do I animate a texture?

Post by robot256 »

Looks like Logistic Robots can only have Idle and Moving animations. They cannot have Working animation because they do not have a "working" state (I suspect the "working" state is for when construction robots have to hover to repair something). You can change or add the Idle animation.

You can make the Idle animation have only one rotation, so the robot will look like it "jumps" to that one rotation while idle, then jump back to the rotated moving animation when it is no longer idle. And remember that there is no 3D rendering in Factorio. You need a separate set of 2D frames for what the robot will look like in each rotation. There are scripts to generate these in Blender by rendering images of a 3D model at several different rotations.

rainawareness
Inserter
Inserter
Posts: 22
Joined: Sat May 14, 2022 12:07 am
Contact:

Re: How do I animate a texture?

Post by rainawareness »

robot256 wrote:
Sat May 14, 2022 5:28 pm
Looks like Logistic Robots can only have Idle and Moving animations. They cannot have Working animation because they do not have a "working" state (I suspect the "working" state is for when construction robots have to hover to repair something). You can change or add the Idle animation.

You can make the Idle animation have only one rotation, so the robot will look like it "jumps" to that one rotation while idle, then jump back to the rotated moving animation when it is no longer idle. And remember that there is no 3D rendering in Factorio. You need a separate set of 2D frames for what the robot will look like in each rotation. There are scripts to generate these in Blender by rendering images of a 3D model at several different rotations.
Whaaaaaat? Do you mean logistic bots can't have animations? I mean not a working one of course, but can't a logistic bot's https://wiki.factorio.com/Prototype/Log ... with_cargo idle with cargo animation have 2 frames per direction? It uses the exact same RotatedAnimation thing as construction working animations.
This is what I want to animate if you want to look at it, I'm quite proud of it! https://mods.factorio.com/mod/vivillon_bots

robot256
Filter Inserter
Filter Inserter
Posts: 433
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: How do I animate a texture?

Post by robot256 »

rainawareness wrote:
Sat May 14, 2022 5:38 pm
robot256 wrote:
Sat May 14, 2022 5:28 pm
Looks like Logistic Robots can only have Idle and Moving animations.
Whaaaaaat? Do you mean logistic bots can't have animations?
:roll: If you can do what you want with the Idle and Moving animations then what is the question? I think they can be expanded to up to 255 frames each. With the frame_sequence property, you don't have to repeat identical frames in the texture, but the total actual frames has to be 255 or less.

rainawareness
Inserter
Inserter
Posts: 22
Joined: Sat May 14, 2022 12:07 am
Contact:

Re: How do I animate a texture?

Post by rainawareness »

robot256 wrote:
Sat May 14, 2022 6:30 pm
rainawareness wrote:
Sat May 14, 2022 5:38 pm
robot256 wrote:
Sat May 14, 2022 5:28 pm
Looks like Logistic Robots can only have Idle and Moving animations.
Whaaaaaat? Do you mean logistic bots can't have animations?
:roll: If you can do what you want with the Idle and Moving animations then what is the question? I think they can be expanded to up to 255 frames each. With the frame_sequence property, you don't have to repeat identical frames in the texture, but the total actual frames has to be 255 or less.
Oh, I'm sorry for being stressful, I really appreciate your time. I just wanted to know what I need to write down in my config.lua file to give logistic robots a 2 frame animation given the appropriate sprite sheet.

Do I take it I just have to type
frame_count = 2,
frame_sequence = { 1, 2 }
? I don't know programming, all I've been able to do is follow a simple guide to retexture bots: https://imgur.com/wyujbCH

I was able to find the programming for accumulator charging animations, would what I want to do look something like this? https://imgur.com/caxlRmF

robot256
Filter Inserter
Filter Inserter
Posts: 433
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: How do I animate a texture?

Post by robot256 »

I think frame_sequence is optional if you just want them to go in order. You should look at the existing bot animation definitions, and just change it from 4 frames to 2. Everything else I would have to figure out with trial and error too, so give it a shot!

rainawareness
Inserter
Inserter
Posts: 22
Joined: Sat May 14, 2022 12:07 am
Contact:

Re: How do I animate a texture?

Post by rainawareness »

robot256 wrote:
Sat May 14, 2022 8:16 pm
I think frame_sequence is optional if you just want them to go in order. You should look at the existing bot animation definitions, and just change it from 4 frames to 2. Everything else I would have to figure out with trial and error too, so give it a shot!
Yeah that was kind of the problem, I couldn't find and don't know how to find construction bots' animation code. Do you know anything about that?
Thank you for all of your help.

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 1199
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: How do I animate a texture?

Post by FuryoftheStars »

The actual animation code is all internal. You just need to setup the sprite sheet and define the needed parameters during the data stage. Without my computer in front of me, you should look in the data/base/prototypes/entities/entities.lua file, and search if for the prototype names that match construction and logistic bots. That’s all the “code” there is (exposed to us) for setting up their animations.

robot256
Filter Inserter
Filter Inserter
Posts: 433
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: How do I animate a texture?

Post by robot256 »

rainawareness wrote:
Sat May 14, 2022 8:18 pm
robot256 wrote:
Sat May 14, 2022 8:16 pm
I think frame_sequence is optional if you just want them to go in order. You should look at the existing bot animation definitions, and just change it from 4 frames to 2. Everything else I would have to figure out with trial and error too, so give it a shot!
Yeah that was kind of the problem, I couldn't find and don't know how to find construction bots' animation code. Do you know anything about that?
Thank you for all of your help.
It will be somewhere in the data/base/prototypes folder. In the game, press "control-shift-E" to open the prototype browser. Click the "entity" tab and search for the bot. Find the entity name. The search for it in "entities.lua". (It might be somewhere else, but probably there.)

rainawareness
Inserter
Inserter
Posts: 22
Joined: Sat May 14, 2022 12:07 am
Contact:

Re: How do I animate a texture?

Post by rainawareness »

FuryoftheStars wrote:
Sat May 14, 2022 8:49 pm
The actual animation code is all internal. You just need to setup the sprite sheet and define the needed parameters during the data stage. Without my computer in front of me, you should look in the data/base/prototypes/entities/entities.lua file, and search if for the prototype names that match construction and logistic bots. That’s all the “code” there is (exposed to us) for setting up their animations.
Thank you very much. Sadly, somehow there doesn't seem to be even a mention of construction robots besides their reflections. https://i.imgur.com/0b0DE4E.png
Do you have any insight you can provide?

rainawareness
Inserter
Inserter
Posts: 22
Joined: Sat May 14, 2022 12:07 am
Contact:

Re: How do I animate a texture?

Post by rainawareness »

robot256 wrote:
Sat May 14, 2022 9:02 pm
rainawareness wrote:
Sat May 14, 2022 8:18 pm
robot256 wrote:
Sat May 14, 2022 8:16 pm
I think frame_sequence is optional if you just want them to go in order. You should look at the existing bot animation definitions, and just change it from 4 frames to 2. Everything else I would have to figure out with trial and error too, so give it a shot!
Yeah that was kind of the problem, I couldn't find and don't know how to find construction bots' animation code. Do you know anything about that?
Thank you for all of your help.
It will be somewhere in the data/base/prototypes folder. In the game, press "control-shift-E" to open the prototype browser. Click the "entity" tab and search for the bot. Find the entity name. The search for it in "entities.lua". (It might be somewhere else, but probably there.)
Thank you very much. But, do you know where else it may be? Somehow it doesn't seem to be in entities.lua: https://i.imgur.com/0b0DE4E.png
And flying robots.lua seems to refer to combat robots only.

robot256
Filter Inserter
Filter Inserter
Posts: 433
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: How do I animate a texture?

Post by robot256 »

Just keep looking! If it wasn't there somewhere, it wouldn't appear in the game. Use a text editor like Notepad++ that can search for text in all the files at once.

Edit: what you found was a subroutine that is called inside the actual definition. You can search for the name of the subroutine (the word after "function") to find where it is used.

rainawareness
Inserter
Inserter
Posts: 22
Joined: Sat May 14, 2022 12:07 am
Contact:

Re: How do I animate a texture?

Post by rainawareness »

robot256 wrote:
Sat May 14, 2022 9:58 pm
Just keep looking! If it wasn't there somewhere, it wouldn't appear in the game. Use a text editor like Notepad++ that can search for text in all the files at once.

Edit: what you found was a subroutine that is called inside the actual definition. You can search for the name of the subroutine (the word after "function") to find where it is used.
Thank you. It turns out that it was in flyingrobots.lua. But it's the exact same thing as all other definitions, just has an animation speed parameter and mentions the sprite sheet size is different:
working =
{
filename = "__base__/graphics/entity/construction-robot/construction-robot-working.png",
priority = "high",
line_length = 2,
width = 28,
height = 36,
frame_count = 2,
shift = util.by_pixel(-0.25, -5),
direction_count = 16,
animation_speed = 0.3,
hr_version =
Here's the idle definition for context:
idle =
{
filename = "__base__/graphics/entity/construction-robot/construction-robot.png",
priority = "high",
line_length = 16,
width = 32,
height = 36,
frame_count = 1,
shift = util.by_pixel(0,-4.5),
direction_count = 16,
hr_version =
Well looking at it like that, the animated code does say it has 2 frames instead of 1. Maybe I can go
in_motion
{
line_length = twice,
width = dunno what this is,
height = dunno what this is,
frame_count = 2,
But I feel like it'll just end up loading to an error. Or, is there like a tutorial on making changes to these in mods? That sounds much more common, right???

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 1199
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: How do I animate a texture?

Post by FuryoftheStars »

Look at the wiki for rotated animation. Width and height are the width and height of the frames within the sprite sheet. While it does have you tell it how many frames there are, it doesn't automatically calculate out what that means for their size within the sheet. And it should be noted that line_length is (essentially) how rows of frames are in the sprite sheet.

As an example, assembling-machione-1's animation has 32 frames and 4 lines. If you look at it's sprite sheet, you'll notice it's 4 rows of 8.

I'm not sure if there is a tutorial on animation, but the errors are generally fairly descriptive as to why it's erroring.

rainawareness
Inserter
Inserter
Posts: 22
Joined: Sat May 14, 2022 12:07 am
Contact:

Re: How do I animate a texture?

Post by rainawareness »

FuryoftheStars wrote:
Sat May 14, 2022 10:56 pm
Look at the wiki for rotated animation. Width and height are the width and height of the frames within the sprite sheet. While it does have you tell it how many frames there are, it doesn't automatically calculate out what that means for their size within the sheet. And it should be noted that line_length is (essentially) how rows of frames are in the sprite sheet.

As an example, assembling-machione-1's animation has 32 frames and 4 lines. If you look at it's sprite sheet, you'll notice it's 4 rows of 8.

I'm not sure if there is a tutorial on animation, but the errors are generally fairly descriptive as to why it's erroring.
Ooooh I dunno about these descriptive errors. I got this error about a missing bracket in that file: https://i.imgur.com/YoP7W3U.png
I haven't even opened that file, and all of the brackets in config.lua are accounted for I'm sure:
return {
-- lower case resource pack name, same of mod folder name (exclusing version) and "name" in info.json; no double underscores ("__")!
resource_pack_name = "vivillon_bots",

-- let the mod know what you will be retexturing
data = {

base = {
graphics = {
entity = {
["logistic-robot"] = {
["logistic-robot.png"] = { },
["hr-logistic-robot.png"] = { },

},
},
},
},
},


data = {

base = {
prototypes= {
entity = {
["flying-robot.lua"] = {


robot_animations.logistic_robot =
{
idle =
{
priority = "high",
line_length = 2,
width = 28,
height = 36,
frame_count = 2,
shift = util.by_pixel(-0.25, -5),
direction_count = 16,
animation_speed = 0.3,
},

idle_with_cargo =
{
priority = "high",
line_length = 2,
width = 28,
height = 36,
frame_count = 2,
shift = util.by_pixel(-0.25, -5),
direction_count = 16,
animation_speed = 0.3,
},
in_motion =
{
priority = "high",
line_length = 2,
width = 28,
height = 36,
frame_count = 2,
shift = util.by_pixel(-0.25, -5),
direction_count = 16,
animation_speed = 0.3,
},
in_motion_with_cargo =
{
priority = "high",
line_length = 2,
width = 28,
height = 36,
frame_count = 2,
shift = util.by_pixel(-0.25, -5),
direction_count = 16,
animation_speed = 0.3,
},


},
},
},
},
},
},



}
If there's like an obvious error, please let me know.

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 1199
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: How do I animate a texture?

Post by FuryoftheStars »

You should use the code tags to preserve the indents (makes it easier to read :) ), or just attach the original file (which, btw, all those pics you uploaded to another site then linked to? You could've just attached them directly to your post. :) ).
code

That said, line 30 looks wrong to me:

Code: Select all

robot_animations.logistic_robot =
Maybe try changing it to:

Code: Select all

robot_animations = {
    logistic_robot =

    'other code

}
?

But this is a syntax error. These can be... misleading, depending on the issue. Actually giving a data type the wrong information it can be more precise on.

Post Reply

Return to “Modding discussion”