SFML community forums

Help => Graphics => Topic started by: haxortiz on March 09, 2010, 09:30:38 pm

Title: Best X & Y Position
Post 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
Title: Best X & Y Position
Post by: Nexus on March 09, 2010, 09:37:06 pm
Quote from: "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...

Quote from: "haxortiz"
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.
Title: Best X & Y Position
Post by: haxortiz on March 09, 2010, 09:56:34 pm
How can I use sf::Vector2f to do the velocity of the sprite, can I have an example please.

Thanks,

Haxortiz
Title: Best X & Y Position
Post by: Laurent on March 09, 2010, 11:11:48 pm
Code: [Select]
sprite.Move(velocity * elapsedTime);
Title: Best X & Y Position
Post by: haxortiz on March 10, 2010, 12:23:25 am
Quote from: "Laurent"
Code: [Select]
sprite.Move(velocity * elapsedTime);


Thanks this example really helped,

Haxortiz
Title: Best X & Y Position
Post by: haxortiz on March 10, 2010, 05:23:25 pm
Well I'm doing a submarine that moves across so I used

Code: [Select]
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
Title: Best X & Y Position
Post by: Nexus on March 10, 2010, 05:26:32 pm
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.
Title: Best X & Y Position
Post by: haxortiz on March 10, 2010, 05:39:12 pm
Quote from: "Nexus"
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...
Code: [Select]
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]