FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   Drawing
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Drawing  (Read 399 times)
sct


Drawing
« on: Feb 22nd, 2005, 2:06pm »

I'm still not exactly sure how drawing works in Processing. Does it use a double buffering system? If so, how do I create buffers and flip them?
 
The reason I'm asking this is that the small game I am trying to write doesn't display the 'players' (rectangles drawn with the quad command) properly. Run it to see what I mean:
 
 
Player p1 = new Player(150,300,10,50,true);
Player p2 = new Player(150,100,10,50,false);
 
void setup() {
  background(160,165,180);
  size(300,400);
  framerate(40);
}
 
void loop() {
  p1.update();
  p1.control();
  p2.update();
}
 
class Player {
   
  float px;
  float py;
  float phealth;
  float pshield;
  boolean ppos;
   
  void update() {
     
    if(ppos == true){ //it's player 1
 fill(200,150,130,150);
 push();
   quad(px-5,py-10,px+5,py-10,px+5,py+10,px-5,py+10); /*quad draws itself over and over again for some reason */
 pop();
    }
     
    if(ppos == false){ //it's player 2
 fill(150,200,130,150);
 push();
 quad(px-5,py-10,px+5,py-10,px+5,py+10,px-5,py+10);
 pop();
    }
     
  }
 
   
  void control() {
     
    if(ppos == true){ //it's player 1
 if(key == LEFT) {
   px = px - 3;
 } else if(key == 0) {
   px = px;
 }
 if(key == RIGHT) {
   px = px + 3;
 }
    }
     
  }
   
  Player(float x, float y, float health, float shield, boolean pos) {
    px = x;
    py = y;
    phealth = health;
    pshield = shield;
    ppos = pos;
  }
   
}
« Last Edit: Feb 22nd, 2005, 2:06pm by sct »  
JohnG

WWW
Re: Drawing
« Reply #1 on: Feb 22nd, 2005, 3:05pm »

I think processing uses some kind of doubel buffering, however, when you draw to the screen, you're actually drawing to a buffer, and at the end of loop() it gets copied to the screen.
 
*However* it's not cleared, so next time you come to loop() what you had at the end of the last loop is still there. If you want to clear the screen, use:
Code:

background(128,128,128); //set screen to color r=128, g=128, b=128

at the start of your loop() block.
 
If you're worried baout things appearing half drawn, since you don't do the flipping, I'm pretty sure that for most cases, anything you do in the loop() block won't be put to the screen until the end of loop().
 
fry


WWW
Re: Drawing
« Reply #2 on: Feb 22nd, 2005, 4:22pm »

that's correct. processing is entirely double-buffered, so anything that you draw inside of loop() is safe, and is copied to the screen once loop() completes.
 
in the currently public versions, the only problems you'll get with the double buffering is if you try to draw inside of the mouseXxxx() functions, which are not properly buffered. this has been fixed for later releases.
 
sct


Re: Drawing
« Reply #3 on: Feb 22nd, 2005, 4:48pm »

That makes sense. Thanks a lot guys.
 
Pages: 1 

« Previous topic | Next topic »