Two quick questions...

edited June 2017 in How To...

How does one fire an event on surface resize. I only want to update my background if its resized. I dont want to have to check for height/ width and draw the image every frame... If I can avoid it.

Also, I have a few different groups of similar objects that inherit from a parent class. All need collision detection, but not with every other group. Some have to collide with one group, some have to collide with another group... and so on. Would it be better to use one loop and one arraylist... and then get the class name of the objects to filter the collisions, or is it better to just have multiple loops and arraylists.

Answers

  • edited June 2017

    might be an event for it in documention, otherwise checking if width or height changed seems to work

    int pwidth, pheight;
    import java.awt.event.*;
    void setup() {
      size(400, 400);
      surface.setResizable(true);
      registerMethod("post", this);
    }
    void post() {
      if (width != pwidth || height != pheight) {
        println("haha");
      }
      pwidth = width; 
      pheight = height;
    }
    void draw() {
    }
    
Sign In or Register to comment.