Questions about sprites based stuff

Hi there.
I have a nice dev to code for a friend, also more an artist than a device.
It involves bunch of objects having parameters and behavior and displayed on the screen.
I’m okay about the objects and classes side of things. I guess I’ll handle this by using vectors to store. I’m okay with instantiation of these.

My questions are related to display/visual.
Those objects will be very basic black and white small bits like small characters running 2D,moving on the screen etc.

Would sprites make sense for this purpose?
Can I easily switch from one sprite to another for a same object?
I guess I can create sprites from… files like gif?

The piece is intended for desktop computer on osx, no ios i mean.

Any ideas and leads would be very appreciated :slight_smile:

You could try using ofxGifDecoder https://github.com/jesusgollonet/ofxGifDecoder It helps with loading gifs and drawing the frames.

If a gif is too limited for your purpose. It shouldn’t be too complicated to load a folder containing image sequences of jpgs, or pngs into a class and then draw one image after the other.

thanks for your answer.
I guess what you are proposing could fit better my needs, indeed.
I have to figure out how I can control the speed of frames drawing etc.

I’d really need to be able to control this for each object.
One object would have a set of GIF. I mean, if an object is a person, that could be
gif1= a running person
gif2= a sleeping one etc.

I’ll dig that asap and still open to opinions and leads :slight_smile:

If I need control over the speed of something, I sometimes use time based code like this (pseudocode)

  
  
long nextUpdate = 0;  
  
void update(){  
    long time = ofGetElapsedTimeMillis();  
    if(nextUpdate < time){  
       doSomething();  
       nextUpdate = time+1000; //if you want to do something every second  
    }  
}  
  
  

this would happen in each instance… I’m afraid about cpu/perf
btw, I got that. there wouldn’t be a lot of other solutions.

handling my objects using vectors or hashtable or whatever, this will be the core of the perf optimizations, afaik.

How many sprites will you have? On an average computer you should be able to show hundreds of animated images with that method. As long as you preload them beforehand.

You could also load an image with all frames next to each other and change the uv coordinates for each frame…

for sure I’d have no more than around 100 objects at a time. some disappearing and being replaced by other but not more than that. and it is a maximum.

Btw, I don’t know if I’d use sprites if I use the ofxGifDecoder. By sprites, I meant directly using ofxSpriteSheetRenderer for instance. I don’t know if it provides what we talked about before (I mean: loading gif or whatever else etc)

I used Box2D too a couple of time.
That woud be AMAZING to be able to use it and to load my sprites as objects in this context

ofxSpriteSheetRenderer works very fine.

now trying to figure out how to model the piece.
I guess I’ll use a Vector or map in order to store my “objects” and I’ll deal with sprite handling directly within my objects’ methods.

I mean, an object is a character.
It can enter into multiple modes like running, jumping.
I’ll display my objects and update then at each turn by changing their state.

does it make sense ?

That makes sense. You can always just change which part of the texture you’re drawing to change “the state”.

ofxSpriteSheetRenderer example just taught me that.
Indeed, I’ll do that at runtime.

Now my main concern is about the piece itself.
As I explained in the previous posts, I need objects.
These objects would be class’ instances.
Each object would have properties.

I guess I’ll have to “link” each object to each sprite using indexes, or whatever.
That should work…