SFML community forums
Help => Graphics => Topic started by: viz_fuerte on June 18, 2010, 01:38:16 am
-
Hi!
I have a problem that is safe of mathematics , and not of SFML.
I'm doing a game ships(sprite), and bullets do not go according to the rotation of the ship, go up.
If the ship has a rotation of 90 degrees and the bullets too, but do not follow the direction of the ship. The bullets rotate the same but if the ship is moving at x: 10, the bullets continue straight y: 20+
CBullet::CBullet(float x,float y,float r,E_BULLET_TYPE t)
{
//# Carga la images
img_bullet.LoadFromFile("media/sprites/bullet.png");
img_bullet.SetSmooth(false);
//# Crea el sprite
spr_bullet.SetImage(img_bullet);
//# Posiciona el sprite
spr_bullet.SetPosition(x,y);
//# Centro del sprite
spr_bullet.SetCenter(spr_bullet.GetSize().x/2.f,
spr_bullet.GetSize().y/2.f);
//# Gira el sprite
spr_bullet.SetRotation(rot);
//# Variables
type = t;
rot = r;
}
void CBullet::Update(bool mov)
{
if(mov)
spr_bullet.Move(-400.f * App.GetFrameTime());
App.Draw(spr_bullet);
}
In other libraries have not had problems doing this, but this is not how.
I've searched the forum but there is no convincing answers.
-
It sounds like you need to add the position of the bullet to the ship sprite position.
-
//# Gira el sprite
spr_bullet.SetRotation(rot);
//# Variables
type = t;
rot = r;
The variable rot is being applied to the sprite rotation before being assigned with the parameter r.
I suggest type and rot to be assigned before the other initializations, or do spr_bullet.SetRotation(r); instead.
By the way, do you really need the variable rot? You can get/set it from the sprite at any time.
-
The truth, I have always used matrices to make that kind of thing, so the models (referring to 3D environments), rotated and followed a local position and rotation.
It would have to do something to continue the rotation and position local, not global, but it would create a matrix and more, more work.
I lose much by using 2D environments (and that some say is easier). :lol:
Thanks for the help. :wink: