This is possible. I experimented around with it quite a while ago.
So, if you have an entity definition table called "my_entity", you would have to use self.object:set_sprite in one of the functions, like on_activate. In lua_api.txt, it is described as
set_sprite(p, num_frames, framelength, select_horiz_by_yawpitch)p is the coordinate of the first animation tile of the entity. Probably {x=0, y=0} in most cases, as this is the top left corner of the image file.
num_frames is the number of animation tiles there are. Obviously more than 1 if you want any animation at all.
framelength is how long each tile is shown.
select_horiz_by_yawpitch is an interesting option. If true, it allows you to make things like the dungeon master in the early games. So, if the player is facing the side of the dungeon master, you will see the vertical tiles a few rows over on the image.
Next, in the object properties, you have to have
spritediv = {x=[width of spritesheet], y=[height of spritesheet]}. If you also have
initial_sprite_basepos = {x=[number], y = [number]}, this will define the first sprite to be used in the sprite sheet, in case you want them to be animated starting with a different tile.
So, if you want to make an exact clone of the original dungeon master, your code would look something like this (only relevant parts included):
- Code: Select all
local my_entity = {
initial_properties = {
...
visual = "sprite",
textures = {"dungeon_master.png"},
spritediv = {x=6, y=5}, -- size of sheet
initial_sprite_basepos = {x=0, y=0},
...
},
...
}
function my_entity:on_activate(staticdata, dtime_s)
self.object:set_sprite({x=0, y=0}, 3, 0.5, true)
end
minetest.register_entity("my_mod:my_entity", my_entity)
BTW, the background of the sprite has to be transparent, so don't include the red and yellow stuff in the image.
As a last note, this only works with sprites. Things like cubes or upright_sprites will not work with this. I don't know if it's possible to make those have animations.