I need some help with something. Right now i have a play and i use the mouse to shoot the bullet. The bullet shoots towards the mouse fine and dandy. Basically I would like the change the image of the bullet when ever the bullet is at a certain Degree or Radian. Could someone help me. I supplied arrows and an image as to what i want to do.

I have an image with 8 bullets inside of it. for all 8 directions, "North", "North-East", "East", "South-East", "South", "South-West", "West", and "North-Wast" like the black arrows in the images. I want to change the image when the mouse is at the "North-East" of the player or if the mouse is at the "South-East" of the player etc....

// You create an identity transform (this should never change):AffineTransformidentity = newAffineTransform();// You create another transform (used for rotating):AffineTransformat= newAffineTransform();// set the transform for rotating to the identity (do this with every bullet):at.setTransform(identity)// rotate your image:at.rotate(angle);// Draw your image:g2d.drawImage(image, at, this);

The AffineTransform class is quite complicated and i don't even understand it fully, but that would maybe do the trick .

Edit: changed the code because it won't do anything else than my code posted before xD

//rotate the Graphics2D object around the center of your bullet objectg.rotate(angle,x+(bulletWidth/2), y+(bulletHeight/2));//draw the bullet as you would normallyg.drawImage(bulletImage, x,y, null);//rotate it back in the using negative angleg.rotate(-angle,x+(bulletWidth/2), y+(bulletHeight/2));

It's just a matter of rotating it back. However, depending on your usage of rotation (especially with larger images), sometimes it is logical to cache an pre-rendered image array of,say every 5 or 10 degrees, so that you don't have to do the rotation each time.

Also, just food for thought, you could also render the bullet as just a line if you don't want to deal with all that.

Currently designing a puzzle-horror game called SLEEP in my free time.I also draw and animate stuff on Youtube.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org