Thursday, January 5, 2017

java - How to Align Gun with Bullets


I have a top-down 2D shooter. I have an image of a player holding a gun, that rotates to face the mouse. Please note that the gun isn't a separate image tethered to the player, but rather part of the player. Right now, bullets are created at the player's x and y. This works when the player is facing the right way, but not when they rotate. The bullets move in the right direction, but don't come from the gun. How can I fix this?


TL;DR: When the player rotates, bullets don't come from gun.


public void fire() {
angle = sprite.getRotation();

System.out.println(angle);
x = sprite.getX();
y = sprite.getY();

Bullet b = new Bullet(x, y, angle);
Utils.world.addBullet(b);
}


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...