Chris Ochsenreither
Chris Ochsenreither

Reputation: 75

Load an image into draw loop in Processingjs

My bee won't show up. What is the proper way to load and display an image in the draw loop?

/* @pjs preload="/static/uploaded_resources/p.8706/Flower-Ice-icon.png"; */
/* @pjs preload="/static/uploaded_resources/p.8706/bee.png"; */
void setup() {  // this is run once.   

    PImage img;
    PImage bee;
    // set the background color
    background(255);

    // canvas size (Variable aren't evaluated. Integers only, please.)
    size(256, 256); 

    img = loadImage("/static/uploaded_resources/p.8706/Flower-Ice-icon.png");
    bee = loadImage("/static/uploaded_resources/p.8706/bee.png");
    image(img, 0, 0);
} 
void draw() {  // this is run repeatedly.  
    image(bee, mouseX, mouseY);
}

Here's a link to the sketch: http://studio.sketchpad.cc/sp/pad/view/VfC92Mrf5o/rev.119

Upvotes: 0

Views: 1488

Answers (1)

Using multiple preloads is not supported by Pjs. Instead, you'll want to comma-separate those two images as argument to a single preload command. See http://processingjs.org/reference/preload, "Syntax for multiple images"

Upvotes: 2

Related Questions