Note : I have rewritten my question and add more information in last post so it will better go to straight to it
I use images to create animations. No all animations are used at the same time.
If I create images using display.newImage or similar function all images are visible on screen:( Making it invisible it is not good due to efficiency and memory usage so I need other solution. I come up with solution but I’m not it is good enough.
My solution:
Create _textures _for each image and put it in table tex,
_2. _In main loop of my game for each frame (in this step I play single animation)
Remove all images created (by display.newImage or similar) in previous frame
Create new images from tex
Set up position, scale and rotation for images
So my question is: Does this is the way it should be done?
You should definitely use sprite sheets. It’s much easier to use them compared to what you are describing. If you’re trying to make sprite sheets out of multiple single images, use Texture Packer.
I’m not sure a sprite sheet will be useful for me. My animations are bone based (made with Spriter - skeleton based animation software) not frame based.
setting a lot of images to invisible instead of removing them could cause some performance issues depending on amount of images and resolution/size of images
A sort of non-related question, but say if you had a full page image that you were replacing quite often, would it be better to use this method or replace by creating a new image and deleting the old one?
In general they can have different sizes. The library that I’m building is quite robust. It have two functions:
load() - responsible for loading resources like images
draw( object ) - responsible for drawing images on the screen. It takes single image. The function draw is invoked as many times as needed to draw whole animation. If animation consist of 10 images the draw function will be called 10 times. What is more a programmer can choose other animation to play at any time. So during next frame draw function will be called with different arguments.
So I’m not quite sure how to adopt your solution here. To better understand my intention I provide below gif with animation used to tests.
If you curious my library is based on this project. Sorry for my english. I try be clear and understandable as much as possible
Are you telling me, that when you swap out ‘leg art’ you use different sized images?
If all the legs are the same image size, then you can simple change the fills of legs. However, I suspect if you’re using a bone system then the individual body parts each use a ‘same sized’ art asset. i.e. Right arms are all the same size, but may be different from left arms, etc.
For testing purposes I loading all images using display.newImage at once and store it in table resources. Furthermore table resources may contains images from different animation for example images for dragon or human.
When I need draw particular images I simply get it from table resources. So I don’t need swap images at all. I change position/scale/rotation attributes of images to make it animate. I’m looking for better solution.
To be more clear I provide more information what I’m doing.
This is not a game. It is a library.
I try create library which implements runtime for Spriter (Pro) so you can use in Corona SDK animations created with it. As input it takes *.scon file and images. The scon file provide only key-frames so my library have to calculate transition between them.
Spriter enables the “modular” method of creating silky-smooth animations where key-frames are constructed from small, re-useable images (such as body parts). This method of animating offers many benefits for several aspects of a game’s development and for the finished product.
How animations work in my library?
It is simple. A next frame is formed by changing position/rotation/scale of images from previous frame a little bit. I use the same images. So I don’t need swap images to create motion. More robust explanation with image below.
Note : In general some parts of animation may need image swap but as rule animations are made by modify previous frame.
Work flow of my library (the way it works now)
Load resources like images
I create display objects (display.newImage) and store them in table named resources. Since that all images are visible on the screen now.
Initalize player object. I use it to play/stop/modifiy animation.
Start playing chosen animation. For now the draw( image ) function is called to draw all parts of animation. If animation consist 10 parts it will be called 10 times.
Change or modify animation.
I don’t want show all images at the same time. So one possible solution is make unused images invisible but since this is inefficient I’m looking for better solution. So that is why I come up with use of textures.
This just saved me tons of time that I was dreading spending on a redesign to turn all my images into imagesheets. Fill used to be an enterprise feature, so I forgot about it.