0

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

2
  • 2
    I'd have to see the translated js code to be sure, but I bet it's a scoping issue. Try moving the PImage declarations outside both functions. Commented Feb 5, 2013 at 3:19
  • Oh, happy pollination! studio.sketchpad.cc/sp/pad/view/VfC92Mrf5o/rev.152 Commented Feb 5, 2013 at 3:23

1 Answer 1

2

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"

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, that helps a lot for another sketch I'm working on studio.sketchpad.cc/sp/pad/view/9QiGOX61ks/rev.244 Is Processingjs still in active development?
we're trying to get some code in to be on par with the upcoming Processing 2.0 API, but we don't have as many devs as we used to, so it's taking longer between releases now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.