translating the screen and objects logically?
in
Programming Questions
•
2 years ago
hey i has a method that allows the user to click hold and drag the screen across and translates the screen, there is also a zoom function. nodes are created and stored in an arraylist which are basically rects with text are created and move with the screen as required. the problem is a mouse over function doesnt translate with then (the nodes actual x,y,h,w). the zoom works because its a decimal number multiplied by the x,y so on.
The draw in the main program and translate functions
The draw in the main program and translate functions
- void draw()
{
background(255,255,255);
scale(zoom);
translate(centerX,centerY);
Node firstNode = (Node) nodes.get(0);
firstNode.formatNode();
firstNode.draw();
firstNode.mouseOver();
if (mousePressed == true && overNode == false)
{
centerX = mouseX-distanceX;
centerY = mouseY-distanceY;
}
} - void mouseWheel(int direction)
{
if(direction == -1)
{
zoom += 0.1;
}
else if(direction == 1)
{
zoom -= 0.1;
}
}
void mousePressed()
{
cursor(MOVE);
distanceX = mouseX-centerX;
distanceY = mouseY-centerY;
}
- if(mouseX > ((x)*zoom) && mouseX < ((x + w)*zoom) && mouseY > ((y)*zoom) && mouseY < ((y + h)*zoom))
1