Loading Images

Hi,
I’m working on drawing a few images into the update function. Is there a way to draw them one after another so that it creates an animation? Right now they draw on top of each other. Is my only option to create an array?

void testApp::setup(){

startanimation=false;
image1.loadImage(“images/1.png”);
image2.loadImage(“images/2.png”);
image3.loadImage(“images/3.png”);

imagePos.x=20;
imagePos.y= 20;
}

void testApp::update(){
if(camera) {

if(camera->imageUpdated){

if (startanimation==true){

image1.draw(imagePos.x, imagePos.y);
image2.draw(imagePos.x,imagePos.y);
image3.draw(imagePos.x, imagePos.y);

}

Hi

yes, try it with an array and a counter.

in testApp.h add

  
ofImage images[42];  
int counter;  

in testApp.cpp

  
counter++;  
if(counter>=42) counter=0;  
images[counter].draw(0, 0);  

you should draw images in the draw()-function

greetings ascorbin

Thank you! I’m still having a few problems if you could give me more help I’d really appreciate it.

  
  
void testApp::update(){  
  if( startanimation==true) {  
                images[1].loadImage("images/1.png");  
                images[2].loadImage("images/2.png");  
                ...  
                  
            }  
  
void testApp::draw(){  
 if (startanimation){  
       images[1].draw(imagePos.x, imagePos.y);  
      images[2].draw(imagePos.x,imagePos.y);  
       images[3].draw(imagePos.x, imagePos.y);  
      images[4].draw(imagePos.x, imagePos.y);  
   
     counter++;  
    if(counter>=4) counter=0;  
    images[counter].draw(imagePos.x,imagePos.y);  
     
   }  
  
//--------------------------------------------------------------  
void testApp::touchDown(ofTouchEventArgs & touch){  
if(touch.id == 1){  
startanimation=true;   
}  
  
  

hi

dont load images in update(), better preload them in setup without start animation-condition, also set framerate in setup with ofSetFramerate(12);

greetings