Skip to content Skip to sidebar Skip to footer

How To Get The Starting Point Of Each Bullet? Libgdx Simple Game

I want to get the starting point of the bullet but i can't make it final, and the bullet.x and bullet.y is always changing so i'm not sure how to save the starting co-ordinates of

Solution 1:

My libgdx is a little rusty. That said, this looks like a fairly regular design problem. Essentially, your MyGame class is trying to do too much, which means solving problems within it is difficult.

Right now, you're trying to just use a circle as your bullet, which means you only get what the Circle class provides. You want to store extra information and add behavior to the circle, so you should create something to do that that. I'd suggest creating a Bullet class, something like this:

publicclassBullet {
    private Circle circle;
    privateint startX;
    privateint startY;

    publicBullet(int startX, int startY){
        circle = //create circle from startX and startYthis.startX = startX;
        this.startY = startY;
    }
    //getters and setters here...
}

You could alternatively have Bullet extend Circle, though that would make changing your bullet to something like a rectangle slightly more difficult if you ever decide to.

Then you can store additional information. It also lets you move some behaviour into that class, instead of doing everything inside your MyGame class. This is always good, as it makes code easier to understand.

Post a Comment for "How To Get The Starting Point Of Each Bullet? Libgdx Simple Game"