0 Members and 1 Guest are viewing this topic.

#### Pacman

• Newbie
• Posts: 18
##### Shooting projectiles Straight **Advice needed***
« on: November 23, 2014, 01:21:26 am »
Hey SFML coders !
How do i get a sprite to be fired as projectile and move straight ahead .

Here is the code i have.

/////////////////////////////
///Create the bullet
////////////////////////////
void Bullet::createBullet(sf::Texture &bulletTexture, sf::Sprite &bulletImage, sf::Sprite &shipImage)
{
cout << "ERROR:bullet could not load" << endl;

bulletImage.setTexture(bulletTexture);///
sf::Vector2f shipLocation = shipImage.getPosition(); ///Gets the location of the ship

float locationX = shipLocation.x - 83;///sets the X location of the ship places the bullet of  it
float locationY= shipLocation.y +4 ;///sets the Y loction of the ship

bulletImage.setPosition(locationX, locationY);
}

////////////////////////
///Move the bullet
////////////////////////
void Bullet::moveBullet(sf::Sprite &bulletImage, sf::Sprite &shipImage)
{
float moveX = shipImage.getPosition().x;
bulletImage.move(-3,0);
}

#### BaneTrapper

• Full Member
• Posts: 213
• Do you even see this, i dont need it.
##### Re: Shooting projectiles Straight **Advice needed***
« Reply #1 on: November 23, 2014, 03:35:30 am »
Hey SFML coders !
How do i get a sprite to be fired as projectile and move straight ahead .
Now honestly.
Stuff like:
In my game i want to shoot a gun, and projectiles to travel in direction of mouse. How do i do this?

angle_in_degrees is just angle in degrees...
distance_to_move is value you move the spite in given angle.
Code: [Select]
`posX += cos(angle_in_degrees)*distance_to_move;posY += sin(angle_in_degrees)*distance_to_move;`
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

anything