Display sketch online (using MouseWheelListener)

edited October 2014 in JavaScript Mode

hi, i am new to processing and i am trying to use mouseWheel to control the movement of objects

the code i have translates the object to move up and down using scroll, but it doesnt appear on any web browsers, or in javascript mode

scroll3

CODE:

import java.awt.event.*; float y;

void mouseWheel(int delta) {

y = y + (delta * 50);

println(delta); println(y); }

void setup() { size(1200,605); addMouseWheelListener(new java.awt.event.MouseWheelListener() { public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) { mouseWheel(evt.getWheelRotation()); }}); }

void draw() { background(51); stroke(255); fill(127); rect(mouseX,mouseY - y,100,50); }

is there a way i can show my mouseWheel controlled sketch online?

thanks, Lucas.

Answers

  • edited October 2014

    In order for a Java Mode sketch to work in JS Mode, it gotta follow very closely Processing's API: L-)
    http://processingjs.org/reference/

    And I've got my doubts about mouseWheel() callback being available there:
    http://processing.org/reference/mouseWheel_.html

    If it happens to be available, the old syntax gotta be used, since the Processing.JS's project which JS Mode is based is still stuck at series 1.x.x! X_X

    Best bet for ya is re-write your sketch in P5.JS, which is the latest Processing-based framework for the JavaScript language: :bz
    http://p5js.org/reference/

  • ok thanks heaps, ill give it a go

  • edited October 2014

    There is an unofficial method hidden in processing.js (version 1.4.1 or higher): mouseScrolled() .

    Example:

    void mouseScrolled() {
      int step=mouseScroll;
      println(step);
    }
    
Sign In or Register to comment.