Skip to main content
GameDev.net gamedev.net
🔒 Locked

Rotary System in Java

Started by Satrio Haryo Prakoso Aug 15, 2013 at 12:01 PM 2 replies 2.1k views
Original Post
Satrio Haryo Prakoso
Satrio Haryo Prakoso

i didn't know how to post video yet, so if you could spare your time to look the video i would be very gratefull, im in the middle of developing a game and i really want to have a rotary system like in the video the problem is i did'nt know how to make the camera follow the character and rotate like in the video. could you please help me with the programming or algorithm? i'm using eclipse for this development. Thank you for your time

the artwork is all complete the problem is int he game engine

minibutmany
minibutmany

To do rotations, you are going to want to look at Java's Graphics2D class.

This stack overflow thread shows how to rotate and image with G2D: http://stackoverflow.com/questions/7517688/rotate-a-java-graphics2d-rectangle.

One simple way to simulate a camera pan is to just subtract actual X,Y values from the cameras X,Y values.

For example:

sprite's X position = 10

cameras X position = 5

subtract: 10 - 5 = 5

now draw the sprite at 5, rather than 10.

Another way is to just render everything like normal to an image, and then change the X and Y position and rotation of that image, and then render the new image to the screen. Depending on how big this image is, this could sacrifice some performance.

Can you post some of your graphics code?

Stay gold, Pony Boy.
Satrio Haryo Prakoso
Satrio Haryo Prakoso

To do rotations, you are going to want to look at Java's Graphics2D class.

This stack overflow thread shows how to rotate and image with G2D: http://stackoverflow.com/questions/7517688/rotate-a-java-graphics2d-rectangle.

One simple way to simulate a camera pan is to just subtract actual X,Y values from the cameras X,Y values.

For example:

sprite's X position = 10

cameras X position = 5

subtract: 10 - 5 = 5

now draw the sprite at 5, rather than 10.

Another way is to just render everything like normal to an image, and then change the X and Y position and rotation of that image, and then render the new image to the screen. Depending on how big this image is, this could sacrifice some performance.

Can you post some of your graphics code?

thanks it realy helped me now i know how to rotate graphics, i know about how the drawing the sprite works, but how do i aply an collision detection on a circle object? sorry if i burden you. i will post my graphics code a few days again its not in my computer in the moment

SimonForsman
SimonForsman

To do rotations, you are going to want to look at Java's Graphics2D class.

This stack overflow thread shows how to rotate and image with G2D: http://stackoverflow.com/questions/7517688/rotate-a-java-graphics2d-rectangle.

One simple way to simulate a camera pan is to just subtract actual X,Y values from the cameras X,Y values.

For example:

sprite's X position = 10

cameras X position = 5

subtract: 10 - 5 = 5

now draw the sprite at 5, rather than 10.

Another way is to just render everything like normal to an image, and then change the X and Y position and rotation of that image, and then render the new image to the screen. Depending on how big this image is, this could sacrifice some performance.

Can you post some of your graphics code?

thanks it realy helped me now i know how to rotate graphics, i know about how the drawing the sprite works, but how do i aply an collision detection on a circle object? sorry if i burden you. i will post my graphics code a few days again its not in my computer in the moment

the easiest way to detect collission between two circles is to compare the square of the distance between them with the square of the sum of their radii.


bool circleTest(float x1, float y1, float radius1, float x2, float y2, float radius2) {
    float dx = x2 - x1;
    float dy = y2 - y1;
    float radii = radius1 + radius2;
    if ( ( dx * dx ) + ( dy * dy ) < radii * radii ) {
        return true;
    } else {
        return false;
    }
}
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

Topic Locked

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

Sign in to reply to this topic.