SFML community forums
Help => Graphics => Topic started by: haxortiz on March 09, 2010, 09:30:38 pm
-
What's the best way to find and move the X and Y position of a sprite?
And i can i use a vector for Velocity of this sprite.
Thanks,
Haxortiz
-
What's the best way to find and move the X and Y position of a sprite?
Did you even look at the documentation? The methods have obvious names...
And i can i use a vector for Velocity of this sprite.
Yes, but this is not a property of a sprite, rather of the logical object (for example a space ship). So, let the respective class have a sf::Vector2f member that represents the velocity.
-
How can I use sf::Vector2f to do the velocity of the sprite, can I have an example please.
Thanks,
Haxortiz
-
sprite.Move(velocity * elapsedTime);
-
sprite.Move(velocity * elapsedTime);
Thanks this example really helped,
Haxortiz
-
Well I'm doing a submarine that moves across so I used
player.Move(subVelocity * elapsedTime);
To move it across but how can I add or subtact to make it go faster or slower when the user press a key?
Thanks,
Haxortiz
-
Increase/decrease the velocity? Use an if statement? :idea:
If you don't know how to react to keyboard input, you should read the tutorials.
-
Increase/decrease the velocity? Use an if statement? :idea:
If you don't know how to react to keyboard input, you should read the tutorials.
I have, this is what i got so far...
if (App.GetInput().IsKeyDown(sf::Key::D))
{
if(player.getEnergy()>100)
{
if(player.getPositionX()!= (game.getWidth()- 100))
{
player.Move(subVelocity * elapsedTime);
player.setEnergy(player.getEnergy()-1);
}
}
}
But everytime I try and use + or -, it starts having errors. Is there a better way?
[Edit]Doesn't Matter, done it now. Wow some really noobish errors in that coding. Haha, Thanks for the help.
Haxortiz[/Edit][/b]