Results 1 to 5 of 5
Thread: Java rotate(); problem
- 06-02-2010, 09:19 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 3
- Rep Power
- 0
Java rotate(); problem
Hello all, I'm started to study java and I have come to problem, I have tried to solve this few days but now I need to ask help.
I'm trying to rotate 1 image but looks like I'm rotating all images.
How can I rotate only 1 image to x degree. I have already made a function what counts that "kulma" to rad.
and if I do this:Java Code:public void update( Graphics g ) { backg.drawImage( bgimg, 0, 0, this ); backg.drawImage( hp, 0,0, this); backg.setColor( Color.white ); backg.drawImage( player, x2, y2, this ); backg.drawImage(meteor,cx,cy,this); backg.drawString("Gas left:" +kaasu, 400,10); backg.drawString("Kulma Deg: "+Math.atan(kulma) * 180/Math.PI , 200,25); backg.drawString("Score:" +score, 300,10); backg.drawString("Health: 100", 34,10); backg.drawString("Mouse at:" +mx, 475,10); backg.drawString(","+my, 550,10); lol(g); g.drawImage( backbuffer, 0, 0, this ); } public void paint( Graphics g ) { update( g ); } public void lol( Graphics g ) { Graphics2D g2d=(Graphics2D)g; if (mx>x2) g2d.rotate(kulma *-1); else g2d.rotate(kulma); backg.drawImage( ase,x2, y2 +4, this ); }
And if I rotate the graphics back after drawing single image.Java Code:g2d.rotate(kulma); backg.drawImage(ase,x,y,this); g2d.rotate(kulma *-1);
nothing don't rotate because I use backg. to draw in buffer and not g2d.
So what I need to do..?
Sorry for my bad english and thanks for all upcoming help :)
-
This code looks funny to me as it looks as if you're trying to do some drawing to a BufferedImage but doing this drawing from within the paint method and possibly losing benefits of using a background BufferedImage. I suggest you create a small compilable program that requires no outside resources other than perhaps images available online (I often use the public domain Java-Duke images located here: Duke Images), that we can compile and run unmodified on our computers at home, and that demonstrates your problem. For more details on what I'm asking for, please see my link on creating an SSCCE in my signature below.
Much luck!
- 06-03-2010, 07:02 AM #3
Member
- Join Date
- Jun 2010
- Posts
- 3
- Rep Power
- 0
I can change those drawings like this:
and call it in run loop or where ever..Java Code:public void paint(){ backg.draw........ }
I just want to know how can I rotate only 1 image.
- 06-03-2010, 08:46 AM #4
Stubborn aren't you? You were asked for an SSCCE, not a couple of meaningless lines of code.
Looks like you don't really want to learn anything.
db
- 06-03-2010, 10:58 AM #5
Member
- Join Date
- Jun 2010
- Posts
- 3
- Rep Power
- 0
You mean:
1)I should use to load images
2) Paste the whole code here that you can help me and run it on your comp?Java Code:try { URL url = new URL(getCodeBase(), "strawberry.jpg"); img = ImageIO.read(url); } catch (IOException e) { }
3) I'm sorry if I were rude but I miss understood that SSCCE thing because of my bad english.
Similar Threads
-
How to rotate an image
By ChipChamp in forum New To JavaReplies: 4Last Post: 06-20-2012, 07:22 PM -
How to rotate catalina.out without restarting tomcat
By kzvi.kzvi.1 in forum Advanced JavaReplies: 1Last Post: 03-25-2010, 06:05 PM -
Image rotate
By Micromani in forum AWT / SwingReplies: 0Last Post: 03-17-2010, 01:33 PM -
Rotate Image!
By Moncleared in forum AWT / SwingReplies: 1Last Post: 02-11-2009, 05:22 PM -
JFrame rotate
By etheralthougt in forum AWT / SwingReplies: 1Last Post: 10-24-2008, 06:03 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks