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

Author Topic: How to set Valocity with Frame rate?  (Read 4247 times)

0 Members and 1 Guest are viewing this topic.

Sanction

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
How to set Valocity with Frame rate?
« on: November 30, 2014, 08:29:13 am »
I'm trying to move mPlayer to Mouse Position when Clicked witch I have done..
but Now I'm trying to make the mPlayer move at a set speed over time.

How would do this with time? I can find my distance (MouseX - PlayerX) (MouseY - PlayerY) and set speed?
I'm new to game coding

My Code
(click to show/hide)
Knowledge comes, but wisdom lingers. It may not be difficult to store up in the mind a vast quantity of facts within a comparatively short time, but the ability to form judgments requires the severe discipline of hard work and the tempering heat of experience and maturity.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: How to set Valocity with Frame rate?
« Reply #1 on: November 30, 2014, 11:08:11 am »
First, you need to find a way of making game logic independent of the frame rate. A simple way is to use sf::RenderWindow::setFramerateLimit() and approximate the frame duration, more sophisticated ways include decoupling from rendering and logics, such as here.

Concerning movement, you can basically use Euler integration. That means the position is updated by the velocity multiplied with the elapsed time in every frame.
// Convert mouse position to world coordinates
sf::Vector2i mousePos = ...; // get from sf::Event
sf::Vector2f target = window.mapPixelToCoords(mousePos);

// Compute player's movement
const float speed = ...;
sf::Vector2f position = ...; // current
sf::Vector2f direction = target - position;

// p += v * t
sf::Time dt = ...; // elapsed frame time, measure with sf::Clock
position += speed * thor::unitVector(direction) * dt.asSeconds();

thor::unitVector() computes a vector of unit length, see here. In Thor, I've written a bunch of functions that simplify vector algebra, you can use them without building the library (i.e. header-only).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Sanction

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: How to set Valocity with Frame rate?
« Reply #2 on: November 30, 2014, 08:30:03 pm »
I'm following the SFML Game Development Book as I go, now I think I got my Fixed Delta Time correct this time. I think I might be able to finish this.

I just finished "C++ Through Game Programming" book(fourth Edition) about a month ago.. Working on SFML Game Development Book Learning and trying things as I go.

but how do I link to Thor Lib and also SFML Lib? & Will I have to make my own Thor Build with Cmake?

I have also seen SFGUI Will this work with SFML2.1? The forums seemed a little old.

Here is my Current code:
(click to show/hide)

 its a little messy right now but once I figure it out I can clean it up
Knowledge comes, but wisdom lingers. It may not be difficult to store up in the mind a vast quantity of facts within a comparatively short time, but the ability to form judgments requires the severe discipline of hard work and the tempering heat of experience and maturity.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: How to set Valocity with Frame rate?
« Reply #3 on: November 30, 2014, 10:03:08 pm »
but how do I link to Thor Lib and also SFML Lib? & Will I have to make my own Thor Build with Cmake?
You can build Thor yourself or use the nightly builds. In any case, please read the installation tutorial at my homepage which explains how to link Thor.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Sanction

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: How to set Valocity with Frame rate?
« Reply #4 on: December 01, 2014, 03:34:08 am »
There is no tutorial on how to use the nightly builds there. I did how ever try to build thor with cmake and got this error:

error C2679 : Binary '/' : no operator found which takes a right - hand operand of type 'sf::Time'

I'm still a newbie :(
Knowledge comes, but wisdom lingers. It may not be difficult to store up in the mind a vast quantity of facts within a comparatively short time, but the ability to form judgments requires the severe discipline of hard work and the tempering heat of experience and maturity.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10777
    • View Profile
    • development blog
    • Email
AW: How to set Valocity with Frame rate?
« Reply #5 on: December 01, 2014, 06:58:54 am »
Use the nightly build just like an offical SDK, thus all the offical tutorials apply.

If you build Thor, you need to build SFML from source as well.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: How to set Valocity with Frame rate?
« Reply #6 on: December 01, 2014, 11:29:32 am »
error C2679 : Binary '/' : no operator found which takes a right - hand operand of type 'sf::Time'
Please search in the forum. A lot of people have this error because they don't read the instructions carefully and mix arbitrary versions.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Sanction

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: How to set Valocity with Frame rate?
« Reply #7 on: December 01, 2014, 12:48:06 pm »
Quote
Use the nightly build just like an offical SDK, thus all the offical tutorials apply.
I've never used a SDK that is self install.. only Android Development Kit for Java, some more information would be helpful.

I guess I'm confused on how to combine the two Libs.. I thought I could just take a nightly build and throw it into my current SFML build and link and go.. but the program wont link to that lib (#include "Thor" )
Knowledge comes, but wisdom lingers. It may not be difficult to store up in the mind a vast quantity of facts within a comparatively short time, but the ability to form judgments requires the severe discipline of hard work and the tempering heat of experience and maturity.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: How to set Valocity with Frame rate?
« Reply #8 on: December 01, 2014, 01:24:55 pm »
I've never used a SDK that is self install..
Nothing is self-install... There are either archives you can decompress and build with CMake, or distributions of binaries and headers.

some more information would be helpful.
For some reason we have written tutorials that explain every single step. There is also a FAQ that explains even more, and tons of forum threads with common problems.

As a programmer, you should really learn how to gather the required information on your own. Of course, you can still ask when things are unclear, but not before at least consulting the official sources. And if you do so, ask concrete and specific questions ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Sanction

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: How to set Valocity with Frame rate?
« Reply #9 on: December 01, 2014, 10:40:36 pm »
No I understand you guys get newbie questions all the time and trust me I try not to ask questions on the forums because its almost a slap in the face every time.
Knowledge comes, but wisdom lingers. It may not be difficult to store up in the mind a vast quantity of facts within a comparatively short time, but the ability to form judgments requires the severe discipline of hard work and the tempering heat of experience and maturity.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: How to set Valocity with Frame rate?
« Reply #10 on: December 02, 2014, 11:06:33 am »
I wrote my last post 1. to encourage you to read the resources like tutorials carefully and 2. to make you ask precise questions. Now I still don't know how we can help you, apart from reiterating what's already written in the tutorials.

Use either the master revisions of Thor and SFML or the latest nightly builds -- for both. If there are problems, describe exactly what you tried and at which point in the tutorial you're stuck. Give as much information as possible.
« Last Edit: December 02, 2014, 11:08:08 am by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Sanction

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: How to set Valocity with Frame rate?
« Reply #11 on: December 03, 2014, 12:20:48 am »
Yes, Thanks, I will go back and have another go at it after I finish my assignments in Java. I really do appreciate all your help.
Knowledge comes, but wisdom lingers. It may not be difficult to store up in the mind a vast quantity of facts within a comparatively short time, but the ability to form judgments requires the severe discipline of hard work and the tempering heat of experience and maturity.

Sanction

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: How to set Valocity with Frame rate?
« Reply #12 on: December 05, 2014, 05:19:15 am »
I did it! it Works! I also included SFGUI so let the learning begin!
Knowledge comes, but wisdom lingers. It may not be difficult to store up in the mind a vast quantity of facts within a comparatively short time, but the ability to form judgments requires the severe discipline of hard work and the tempering heat of experience and maturity.