Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

reorder draw/stack index?

$
0
0

Hi , Im having a problem with objects (Tiles) - I set where a bunch of Tiles appear on the canvass and if the mouse cursor is over one of the Tiles it enlarges and plays a video. All this is working fine but I would like a way to say - if mouse cursor over object - draw this object last so that it is drawn over the other objects (effectively masking them out as it enlarges).

I had seen this; http://www.openprocessing.org/sketch/50914 - about drawing stack order.

This example is nearly exactly what I want to do but the problem is I still need to be able to set exactly where these objects appear on the canvass so I can't create them in a if statement or loop - they need to be set individually. Is there a way to re order when they are run though draw when the mouse hovers over them?

I had tried creating a discussion before but unfortunately I managed to put it in the wrong category so am re posting this here.

Code below - and thanks for the help!

import processing.video.*;

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;

Minim minim;
AudioSample sample;
Tile[]Tiles = new Tile[10];

void setup() {
  fullScreen(2);
  //noCursor();
  imageMode(CENTER);
  minim = new Minim(this);

  for (int i = 0; i< 10; i++){
    Tiles[i]= new Tile(this);
    Tiles[i].setMovie("TORCH_2_1.mov");
    Tiles[i].setAudio(minim, "Paper Rustle_1.mp3");
  }


}

void draw() {
  background(0);

  Tiles[0].presentTile(200, 200);
  Tiles[1].presentTile(225, 200);
  Tiles[2].presentTile(250, 200);
  Tiles[3].presentTile(275, 200);
  Tiles[4].presentTile(300, 200);
  Tiles[5].presentTile(325, 200);

}

class Tile {
  PApplet app;
  Movie movie = null;
  AudioSample sample = null;

  boolean overBox = false;
  boolean canTrigger = true;
  float boxMax = 100;
  float boxMin = 25;
  int boxSize;

  Tile(PApplet papp) {
    app = papp;
    boxSize = 25;
  }

  void setMovie(String fname) {
    movie = new Movie(app, fname);
    movie.loop();
    movie.pause();
  }

  void setAudio(Minim m, String fname) {
    sample = m.loadSample(fname, 512);
  }

  void isOver(float x, float y) {
    overBox = (mouseX > x-(boxSize/2) && mouseX < x +(boxSize/2) &&
    mouseY > y-(boxSize/2) && mouseY < y+(boxSize/2));
  }


  void presentTile(float bx, float by) {

    isOver(bx, by);
    if (movie != null) {
      if (movie.available() == true)
        movie.read();
      if (overBox && (boxSize < boxMax)) {
        image(movie, bx, by, boxSize++, boxSize++);
        movie.loop();
      }
      if (!overBox && boxSize > boxMin ) {
        image(movie, bx, by, boxSize-=1, boxSize-=1);
        movie.pause();

      }
      image(movie, bx, by, boxSize, boxSize);
    }
    if (sample != null) {
      if (canTrigger && overBox) {
        sample.trigger();
        canTrigger = false;
      }
      if (!overBox) {
        sample.stop();
        canTrigger = true;
      }
    }
  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles