I think the problem is I don’t know how to structure classes the correct way. The design behind the class structure and overall program structure.
Here’s my modified method, which is in a class called “Entity”, which basically handles everything that is displayed on the screen. So I thought by “zooming”, the entity class
all the subclasses and children of that class would be “zoomed” as well.
The zoom method just checks to see which way the mouse scroll wheel has been rotated and applies the appropriate scaling.
At the moment it only scales 1x.
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
public class Entity{
protected double x;
protected double y;
protected Sprite sprite;
protected double dx;
protected double dy;
AffineTransform tx;
public Entity(String ref, int x, int y){
this.sprite = SpriteStore.get().getSprite(ref);
this.x = x;
this.y = y;
tx = new AffineTransform();
}
public void move(int delta) {
x += (delta * dx) / 1000;
y += (delta * dy) / 1000;
}
public void zoom(Graphics2D g, int scrollAmount){
if (scrollAmount > 0){
g.setTransform(tx);
g.scale(0.9, 0.9);
} else if (scrollAmount < 0){
g.setTransform(tx);
g.scale(1.1, 1.1);
}
}
public void setHorizontalMovement(double dx) {
this.dx = dx;
}
public void setVerticalMovement(double dy) {
this.dy = dy;
}
public double getHorizontalMovement() {
return dx;
}
public double getVerticalMovement() {
return dy;
}
public void draw(Graphics2D g) {
zoom(g, MouseWheelInputHandler.scrollAmount);
sprite.draw(g,(int) x,(int) y);
}
public int getX() {
return (int) x;
}
public int getY() {
return (int) y;
}
public int getHeight(){
return sprite.getHeight();
}
public int getWidth(){
return sprite.getWidth();
}
}