2 Replies - 616 Views - Last Post: 16 March 2010 - 10:18 AM Rate Topic: -----

#1 HunterE30633  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 21-October 09

Game Camera MousePointer Zooming

Posted 14 March 2010 - 03:40 AM

I hope the title is clear. I had a better post written before this, but as soon as it was ready to post, my cat of 6 months decided to press the right keys to close the window on her way jumping on the desk.

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

Is This A Good Question/Topic? 0
  • +

Replies To: Game Camera MousePointer Zooming

#2 HunterE30633  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 21-October 09

Re: Game Camera MousePointer Zooming

Posted 15 March 2010 - 12:32 AM

If anyone can point to a tutorial or something that would be great.
Was This Post Helpful? 0
  • +
  • -

#3 HunterE30633  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 21-October 09

Re: Game Camera MousePointer Zooming

Posted 16 March 2010 - 10:18 AM

No one can help? If you need a better idea of what I'm trying to do or something else I'll be happy to help. I'm not looking for a code sample, I'll be happy with a constructive, serious idea that tells me what I need to do. Tutorials, ideas, anything will help

Thank you
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1