After switching from Corona to Gideros I was looking for a method to create animated sprites / movie clips from a texture sheet. The docs are more than confusing regarding that. There is a class named MovieClip but it seems that those MovieClip thingies are static images whose properties can be tweened only. So obviously not what I am looking for.
Then I searched the example codes and found three different things: the bird animation, gtween and the Texture Pack example.
1. So which one should be preferred? I am using a texture atlas exported from Texture Packer (non-uniform / different sized frames) and want to create an animated sprite from it.
2. In the Texture Pack example, TexturePack.new() is used like this:
local pack = TexturePack.new("anim.txt", "anim.png")
Whereas the docs specify TexturePack.new() like this:
TexturePack.new(textures, padding, filtering, options)
Which one is correct?
And how should the "textures" parameter look like? A string? Or a table? And if this parameter is a table, what properties should it contain and in what order?
3. What does the content in an anim.txt file stand for? I assume that the strings are just name identifiers for each individual frame (and can be changed to anything else), while the next four numbers on a row define the x,y,width and height of this individual texture region -but what about the other four numbers?
The reference is very unclear and confusing on that -or did I miss some "magic" tutorial section here where all this is explained in detail? o.O
Comments
1) from what I understood MovieClip is exactly what you need, just enter each frame and it's length in it and thats all.
Tweening of frames is only additionally if needed, but not required, MovieClip is meant for frame animations.
So if you have a TexturePack, you wold go like this.
3) anim.txt contains the references to the original images, so you could use original image names to get textures instead of providing positions, dimensions and offsets.
local pack = TexturePack.new("anim.txt", "textureSheet.png")
it uses the .txt file (where all images used on the sheet are already defined by name).
But as I understood, I additionally have to "hardcode" the image names in my code then:
self.anim =
{
Bitmap.new(pack:getTextureRegion("anim_01.png")),
Bitmap.new(pack:getTextureRegion("anim_02.png")),
Bitmap.new(pack:getTextureRegion("anim_03.png")),
.......
}
I'd prefer to only specify the .txt file as exported from Texure Packer and avoid hardcoding the image names in my actual code. So is it possible to extract the image names from a texture pack and create a list of images like this?
self.anim = {}
for i = 1, pack.numImages do
self.anim[i] = pack.getTextureRegion[i]
end
Also, if it would be possible to numerally loop through a texture pack's texture regions like this, there would be no need to use self.anim anymore to store references to them.
Is there a way to do so to avoid hardcoding the image names of a texture atlas in the actual project code? I want to avoid unnecessarily blowing up my code, but also the need to change my code again if I decide to replace the anim.txt with another one at a later time.
Likes: Platypus
Dislikes: shandiaobd
The bird example is out of date (at least in my version) as it precedes the introduction of the setTexture function. In this example the bird is a sprite with several children bitmaps. At any given time all but one are invisible which gives the illusion of animation but its a complex, clunky way to write code and not practical for anything complex. Use setTexture instead.
Likes: Platypus
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
Likes: Platypus
It feels a bit like solving a puzzle, always jumping around in the reference and collecting things together. I wish there would be a clear, complete, up-to-date guide on how to efficiently animate sprites (or bitmaps) with Gideros. Or is there one that I just missed yet?
Oh another option I forgot to mention is TNT Animator Studio:
http://www.tntparticlesengine.com/?cat=14
And there were also other community released classes/libs to help with animations on the forum
As @ar2rsawseen suggested, I highly recommend that you take a look at TNT Animator Studio provided by @GregBUG.
Likes: Platypus
It basically works (the MovieClip is created and plays correctly) -but for some reason my class does not return a valid handle to the created MovieClip:
"class_movieclip.lua"
Create a MovieClip from a specified Texture Packer .txt and .png and return its handle:
This seems to work since the MovieClip is displayed on the stage and animates. But when I try to access the returned MovieClip handle ("Clip") from my main.lua, it gives me an error:
main.lua
What did I do wrong..?
And since AnimClip class does not inherit from Sprite, it does not have setPosition method
What you can do is to inherit your AnimClass as Sprite
However, I am not sure how to extend the class properly. My approach is like this:
We could also remove included examples and move it online somewhere. Or we could show online page on gideros studio welcome screen ala Netbeans or Visual Studio.
It takes time to create examples, but it should help many newcomers. I think there are many newcomers recently on this forum (which is good for business!)
@ar2rsawseen @atilim
Likes: Platypus
http://www.nightspade.com