Can we stop a draw in middle of it, and starts it again ?

edited January 2014 in How To...

Hi, I'm coding a imageloader, for avoid the green screen at start of my sketch. I want to loop only on a "loading" animation, until all my pictures are loaded. Can I stop the draw and starts it again, or I should use a solution like :

    if(!imageLoaded){ 
      "loading" animation
    }
    else{ 
      the rest of my sketch 
    } 
Tagged:

Answers

  • Answer ✓

    your approach to the solution is correct

  • Answer ✓

    A little example snippet:

    String[] filenames = new String[] { "h t t p://www.processing.org/exhibition/images/petting.jpg".replace(" ", ""),
                                        "h t t p://www.processing.org/exhibition/images/fragmented.jpg".replace(" ", ""),
                                        "h t t p://www.processing.org/exhibition/images/avena.jpg".replace(" ", ""),
                                        "h t t p://www.processing.org/exhibition/images/kinograph.jpg".replace(" ", "") };
    PImage[] images;
    boolean imagesLoaded = false;
    
    void setup() {
        size(400, 400, P2D);
        thread("loadImages");
    }
    
    void draw() {
        background(#000000);
        if(imagesLoaded)
            drawImages();
        else
            drawLoadingAnimation();
    }
    
    void drawImages() {
        float imageHeight = height / filenames.length;
        for(int n = 0; n < filenames.length; n++)
            image(images[n], 0, n * imageHeight, width, imageHeight);
    }
    
    void drawLoadingAnimation() {
        fill(#ffffff);
        translate(width / 2, height / 2);
        rotate(frameCount / 10.0);
        rect(-20, -20, 40, 40);
    }
    
    void loadImages() {
        images = new PImage[filenames.length];
        for(int n = 0; n < filenames.length; n++)
            images[n] = loadImage(filenames[n]);
        imagesLoaded = true;
        delay(1000);
    }
    
  • see also the requestImage() example in reference.

  • edited January 2014

    @zumbaree : thanks
    @Poersch : i use thread in my project but i never guessed to use it for load my pictures :D
    @koogs : the requestImage gives me the same error than loadImage few months ago

    Regards and thanks for your help

Sign In or Register to comment.