mask() doesn't work in js mode

edited March 2014 in JavaScript Mode

My sketch is at http://www.openprocessing.org/sketch/138925

The mask function is not working in js mode (works in java mode) and not sure why. I am new to processing.js, help!

Answers

  • I am working in Processing 2.1 on a Mac OS 10.9.1. The code:

        /* @pjs preload="0.jpg, 1.jpg, 2.jpg, 3.jpg, 4.jpg, 5.jpg, 6.jpg, 7.jpg, 8.jpg, 9.jpg, 10.jpg, 11.jpg, 12.jpg"; */
    
    
        PImage people;
        PImage ground;
        PGraphics pm;
        int x1, x2, y1, y2, i;
    
        void setup()
        {
          size(840, 470);
        //  frameRate(5);
          noStroke();
    
    
          pm = createGraphics(width,height);
    
          ground = loadImage("0.jpg");
          image(ground, 0, 0);
    
        }
    
        void draw() {
    
          i = int(random(0, 12));
    
          x1 = int(random(0,width));
          x2 = int(random(5,20));
          y1 = int(random(0,height));
          y2 = height - (2*y1);
    
          people = loadImage(i + ".jpg");
    
          pm.beginDraw();
          pm.fill(0);
          pm.rect(0,0,width,height);
          pm.fill(255);
          pm.rect(x1,y1,x2,y2);
          pm.endDraw(); 
    
    
          people.mask(pm);
          image(people,0,0);
    
    
          }
    
  • You should load all of your images within setup(). Place their references in an array! Load operations are too slow! [..]

Sign In or Register to comment.