Skip to main content
gamedev.net
🔒 Locked

Java Rendering problems.

Started by j14rk1n Dec 20, 2005 at 7:35 PM 1 replies 700+ views
Original Post
j14rk1n
j14rk1n
I've been trying to create simple little games in Java, but get discouraged when I find that I don't know the things necessary to pull it off. The project sits on my HD for months until I think of something else that eventually doesn't work. I'm trying to make a simple overhead game now that supports a layering system so that I can have things appear underwater or over certain objects. So far, this has been working great. The problem is that when I try to rotate induvidual units the whole screen gets rotated. I've the pictures below: No Rotation: http://j14rk1n.cjb.cc/GDHelp/noRot.jpg Rotation Problem: http://j14rk1n.cjb.cc/GDHelp/whaaaat.jpg Also, my sourcecode for the project can be found here: http://j14rk1n.cjb.cc/GDHelp/GameCode.zip Is there some kind of "push/pop" method that I should be using to isolate the images? Can someone help me out here? Thanks in advance :)
BertS
BertS
You're rotating your complete coord system.
Use this:
AffineTransform transform = new AffineTransform();transform.translate( current.getCoords().getX() - (current.getImage().getWidth(null)/2), current.getCoords().getY() - (current.getImage().getHeight(null)/2));transform.rotate(Math.toRadians(current.getAngle()));g2.drawImage(current.getImage(), transform, null);


instead of:
g2.rotate(Math.toRadians(current.getAngle()), current.getCoords().getX() - (current.getImage().getWidth(null)/2), current.getCoords().getY() - (current.getImage().getHeight(null)/2));g2.drawImage(current.getImage(), current.getCoords().getX()/* - (current.getImage().getWidth(null)/2)*/, current.getCoords().getY()/* - (current.getImage().getHeight(null)/2)*/, null);
j14rk1n
j14rk1n
NICE! Thanks a lot, BertS.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.