We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
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
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
There is an unofficial method hidden in processing.js (version 1.4.1 or higher): mouseScrolled() .
Example: