But basically what I have been working towards the past day is a camera zooming effect where depending on where the mouse is upon scrolling the mousewheel, the camera zooms in or out on that area. An example could be from the RTS, Supreme Commander.
What I have is:
public void paint(Graphics g)
{
off.clearRect(0,0,getWidth(), getHeight());
off.scale(zoom,zoom);
int width = (int)(zoom*getWidth()), height = (int)(zoom*getHeight());
if(x+width > getWidth()) width = getWidth() - x; if(y + height > getHeight()) height = getHeight() - y;
off.drawImage(main.getSubimage(
x,
y,
width,
height),
0,
0,
null);
g.drawImage(buffer,0,0,null);
}//end
public void mouseWheelMoved(MouseWheelEvent e)
{
zoom-=e.getWheelRotation()/1000.0;
x+=(int)((e.getX() - getWidth()/2)/100.0*e.getWheelRotation());
y+=(int)((e.getY() - getHeight()/2)/100.0*e.getWheelRotation());
if(x < 0) x = 0; if(y < 0) y = 0;
repaint();
}//end
This is a prototype program in Java, all I want to do is test the zooming effect in an environment outside of a game so that I can easily debug. Buffer is the BufferedImage I use as a back buffer. Off is the Graphics object used by buffer. And finally main is another BufferedImage that I use as my map so I can see whats happening.
I tried scaling the subimage from main so that it would fit inside the applet of size 1000*800. That doesn't happen however. I think my biggest problem is scaling and I think if someone points me in the right direction I will be able to get it working. I'll gladly accept help on anything else related to this

New Topic/Question
Reply



MultiQuote



|