Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Best X & Y Position  (Read 3340 times)

0 Members and 1 Guest are viewing this topic.

haxortiz

  • Newbie
  • *
  • Posts: 14
    • View Profile
Best X & Y Position
« 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

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Best X & Y Position
« Reply #1 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

haxortiz

  • Newbie
  • *
  • Posts: 14
    • View Profile
Best X & Y Position
« Reply #2 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Best X & Y Position
« Reply #3 on: March 09, 2010, 11:11:48 pm »
Code: [Select]
sprite.Move(velocity * elapsedTime);
Laurent Gomila - SFML developer

haxortiz

  • Newbie
  • *
  • Posts: 14
    • View Profile
Best X & Y Position
« Reply #4 on: March 10, 2010, 12:23:25 am »
Quote from: "Laurent"
Code: [Select]
sprite.Move(velocity * elapsedTime);


Thanks this example really helped,

Haxortiz

haxortiz

  • Newbie
  • *
  • Posts: 14
    • View Profile
Best X & Y Position
« Reply #5 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

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Best X & Y Position
« Reply #6 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

haxortiz

  • Newbie
  • *
  • Posts: 14
    • View Profile
Best X & Y Position
« Reply #7 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]

 

anything