Camera Class Zooms and Cuts Off Image

I’m working on implementing a simple camera to use with my projects. It works like it should, except when it draws the image, it is zoomed in, and some of the bottom and right side are completely cut off. First, here’s the code for the class (keep in mine I use the Slick2D Image and GameContainer):

public class ECamera 
{
	// Image to draw
	protected Image bg;

	// Position of the camera
	protected float camX, camY;

	// Width and height of image
	protected float bgWidth, bgHeight;

	// Game container to get screen width/height
	protected GameContainer gc;
	
	/**
	 * Create new Camera with background image
	 * 
	 * @param gc the game container
	 * @param bg the background image
	 */
	public ECamera(GameContainer gc, Image bg)
	{
		this.bg = bg;

		bgWidth =  bg.getWidth();
		bgHeight = bg.getHeight();

		camX = camY = 0;

		this.gc = gc;
	}

	/**
	 * Centers on the x, y coordinate given. If the camera comes to an edge of 
	 * the image, the camera stops
	 * 
	 * @param x x-position to center on
	 * @param y y-position to center on
	 */
	public void centerOn(float x, float y)
	{
		camX = x - (gc.getWidth()  / 2);
		camY = y - (gc.getHeight() / 2);

		if (camX < 0) 
			camX = 0;
		if (camX + gc.getWidth() > bgWidth) 
			camX = bgWidth - gc.getWidth();

		if (camY < 0) 
			camY = 0;
		if (camY + gc.getHeight() > bgHeight) 
			camY = bgHeight - gc.getHeight();
	}
	
	/**
	 * Draw the background
	 */
	public void draw()
	{
		this.draw(camX, camY);
	}
	
	/**
	 * Draw the background using an offset separate of the camera
	 * 
	 * @param offsetX x-offset to use
	 * @param offsetY y-offset to use
	 */
	public void draw(float offsetX, float offsetY)
	{	if (bg != null)
			gc.getGraphics().drawImage(bg, 0, 0, offsetX, offsetY, offsetX + gc.getWidth(), offsetY + gc.getHeight());
	}
	
	/**
	 * Translates all graphics relative to the camera
	 */
	public void translateGraphics()
	{
		gc.getGraphics().translate(-camX, -camY);
	}
	
	/**
	 * Undoes translateGraphics(). Use before drawing anything that is 
	 * independent of camera position, like HUD's
	 */
	public void untranslateGraphics()
	{
		gc.getGraphics().translate(camX, camY);
	}
}

I use the Graphics.draw() method that lets you specify The top left corner and the bottom right corner of the area of the image you want to draw. It specifically says in the API:

[quote]Draw a section of an image at a particular location and scale on the screen
[/quote]
So, I guess my main thing is, how do I do what I’m already doing, just without the image being scaled?

I’m going to bump this. Finding information on a Camera class is proving to be difficult. They are easy to find, if it’s for a tile map. I just used one of those, and modified it to work for non-tile games, since I couldn’t find any otherwise.

So, yeah. I still need help with this.

I’m going to bump this. Finding information on a Camera class is proving to be difficult. They are easy to find, if it’s for a tile map. I just used one of those, and modified it to work for non-tile games, since I couldn’t find any otherwise.

So, yeah. I still need help with this.