How to handle many images?

Hi,

Note : I have rewritten my question and add more information in last post so it will better go to straight to it :slight_smile:

    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:

  1.  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? 

ldurniat

Hi,

I have not done this myself yet but wouldnt it be helpful to use regular sprite animations based of spritesheets?

If you dont have it already, getting TexturePacker (3rd party app) helps alot.

My 2 cents anyway.

Anaqim

Ya it definitely sounds like your doing more work than you need to, if you arent super familiar with sprite sheets check out: 

https://docs.coronalabs.com/guide/media/spriteAnimation/index.html

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. 

So, do you manually move the skeletal joints of the image for each frame?

I’m writing my own implementation od runtime for Corona SDK based on somebody else work :slight_smile:

You could create a function that increases in count, and for each time this occurs you could do:

display.newImage("frame" .. count .. ".png") currentImage.isVisible = false

This is a possible solution.

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

Are all the images of a similar size?

If so, just change the fill of the image you need to replace.

https://docs.coronalabs.com/api/type/BitmapPaint/index.html

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?

I’m pretty sure, filling a like sized image should always be cheaper/more efficient.

Tip: This is an easy thing to test and benchmark…

Fair enough, Im at work, but I’ll test tonight

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 :slight_smile:

ToOldV5.gif

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.

In this case, the fill solution would work fine.

No.

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.

I guess I don’t understand what you’re doing and I have run out of time.  Sorry. 

Probably a good way to get help on this is to make a little test bench and show us how this swapping works.

i.e. Share a little project with us and let folks poke at it and provide suggestions on changes.

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.

From Spriter site (https://brashmonkey.com/spriter-features/):

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)

  1. 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.

 

  1. Initalize player object. I use it to play/stop/modifiy animation.

 

  1. 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.

 

  1. 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.

xlvGAYT.png

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.

Thanks, @roaminggamer!

@asmar1x,

Glad it helped you.

@ldurniat,

Hey.  I never answered your great reply.  My internet went out at the end of June for a couple weeks and I never caught up on old posts.

Sorry I left you hanging!