We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi:
Recently, somebody gave me a code which permits drag-and-drop an image wherever is possible, of course in works, I rewrote as a class, , but it nor has mistakes, but neither works.
Here is the code
Draggingpic Dragging = new Draggingpic();
void setup() {
size(600, 600);
noStroke();
Dragging.charge();
}
void draw() {
background(255);
Dragging.mouseDragged();
}
class Draggingpic
{
int x;
int y;
PImage sample;
void Draggingpic(int posx,int posy)
{
x=posx;
y=posy;
image(sample, x, y, 50, 30);
}
void charge()
{
sample=loadImage("g2.png");
}
void mouseDragged()
{
x=mouseX;
y=mouseY;
}
}
Thanks
Answers
B/c your mouseDragged() method is defined inside your class Draggingpic, the sketch can't find it! :-O
Further explanation at this link below: :-B
https://forum.Processing.org/two/discussion/19056/mousepressed-not-working-simple-code
Hi
The original code didn't use mousePressed event at all, anyway, I put here in order to show how it was at first
PImage sample; int x, y; void setup() { size(1000, 600); noStroke(); sample=loadImage("G2.png"); x=0; y=400; } void draw() { background(255); image(sample, x, y, 50, 30); } void mouseDragged() { x=mouseX; y=mouseY; }
https://forum.Processing.org/two/discussion/19282/howto-pass-to-class-code