I am trying to scale an image (that is from a sprite sheet) using this code below.
Point pos = new Point(100, 100); //this shows where to display the image
Rectangle a = getAnimatedPos(); //just gets the coordinates of a specified image (which works correctly)
g.drawImage(img, pos.x, pos.y, pos.x+getWidth(), pos.y+getHeight(), a.x, a.y, a.x+a.width, a.y+a.height, null);
the function getWidth() returns the width of the frame. The formula is (imageWidth/rows).
the function getHeight() returns the height of the frame. The formula is (imageHeight/cols).
When I scale the image (by changing the width or height), it starts to show the other frames? If I leave the width or height of the image to the default size it works. I thought by defining the sources coords and dest coords it wouldn’t do this.
To clarify, the image is being painted/rendered on an internal frame say with the size of 640×480. Also, when I mean frame, I am talking about a sprite sheet and each image in the sheet is a frame. It is for animations of course.
Another thing to clarify, the image is not being drawn on top of components. Just an internal frame.
What should I try to fix this?
Screen Shots
When everything is default this is what it looks like: http://wisemindstudios.com/good.png
When I change something: http://wisemindstudios.com/bad.png
Thanks a bunch!
I spotted the problem. It was in my getAnimatedPos function. I passed in the new width and height of the frame and not the original width and height of the frame (for source coords). So, it was a very simple fix after all.
I was certain it was something wrong with the drawing and not my code. But, it usually is always the users fault (or programmers in this case). Oh, well. It is what it is.
Thanks for helping me out!