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

Author Topic: SFML Game Dev Guide - Game Tick Problem  (Read 4369 times)

0 Members and 1 Guest are viewing this topic.

Falke88

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
SFML Game Dev Guide - Game Tick Problem
« on: November 04, 2014, 08:12:50 am »
Hey guys,

I accepted the challenge to get along with the guide book for SFML and .NET.

I managed to skip simple problems yet and got them working.
Still theres a little bugger for me actually here with Time / Clock.
Am not talking about where to find Clock/Time within SFML.NET.

The main issue is the passed value for the elapsed time.
I think I made everything right here - still the seconds value passed over always holds the value "0" which isn't that surprising because I can't imagine that a full second may manage to get over to the Update() Method anyway.

I know thought about seconds being passed over as float values - that way at least a fracture of a second can be passed like "0.2" Seconds or something - that way my movement will at least work at slow pace.

Can anybody please tell me how to manage that right.

Because TimeSpan deltaTime.Seconds only returns a INT value...any way to provide a float value of it.


Greets Charlie

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10911
    • View Profile
    • development blog
    • Email
AW: SFML Game Dev Guide - Game Tick Problem
« Reply #1 on: November 04, 2014, 09:17:02 am »
You need to build the latest version of SFML.NET from GitHub.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Falke88

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: SFML Game Dev Guide - Game Tick Problem
« Reply #2 on: November 04, 2014, 01:25:22 pm »
Hey There,

Sorry I can't follow you on how the GitHub SFML.NET build may help me here? I have the latest build I'm sure.

As I said I'm following the book SFML Game Dev. Tutorial.

Here is where I'm at

 
 Stopwatch clock;
 Vector2f newPos;                // help vector for movement
 float playerspeed = 1.0f;       // speed of player movement

...

public void Run()
        {
            while(mWindow.IsOpen())
            {
                clock.Restart();        //restart clock
                ProcessEvents();
                Update(clock.Elapsed);  //pass the elapsed time
                Render();
            }
        }
 private void Update(TimeSpan deltaTime)
        {
            if (mIsMovingUp)
                newPos.Y -= playerspeed;
            if (mIsMovingDown)
                newPos.Y += playerspeed;
            if (mIsMovingLeft)
                newPos.X -= playerspeed;
            if (mIsMovingRight)
                newPos.X += playerspeed;

            Console.WriteLine(deltaTime.TotalSeconds);
            mPlayer.Position = newPos * deltaTime.TotalSeconds;
        }

 

I really tried to match the .NET Code with the C++ Code from the book here.

But the main issue is with
mPlayer.Position = newPos * deltaTime.TotalSeconds;

Where newPos is a Vector2f object and TotalSeconds is a property of type double.
It's not possible to multiply these two for sure.

Even tho its written that way in the Tutorial:
mPlayer.move(movement * deltaTime.asSeconds());

where movement is from sf::Vector2f and multiplied by at least any number type (int, double etc) - dunno if this might work in C++ and not in C# tho.


I have a hard time to find a fitting solution for .NET so I would appreciate if anybody could help me out here.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML Game Dev Guide - Game Tick Problem
« Reply #3 on: November 04, 2014, 01:46:40 pm »
SFML.NET provides a multiplication operator for Vector2f and float (not double).

eXpl0it3r's comment is in so far right, as Clock and Time classes have been added to SFML.NET after version 2.1. So that's what you should use, like in C++.

Sounds familiar, eh? :P
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Falke88

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: SFML Game Dev Guide - Game Tick Problem
« Reply #4 on: November 04, 2014, 01:51:00 pm »
And as far I could see there isn't any .dll provided to simply download eh?

So I presume that I have to merge these i.e. Clock.cs etc. Files to the existing sfmlnet-graphics-2.dll file ?
If yes - can anybody link me some tutorial, because I never did that before.

Would also round up this thread
« Last Edit: November 04, 2014, 01:56:53 pm by Falke88 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10911
    • View Profile
    • development blog
    • Email
AW: SFML Game Dev Guide - Game Tick Problem
« Reply #5 on: November 04, 2014, 02:34:15 pm »
No, you have to build from source, no "merge" something...
To make things easier though, you could get my CSFML nightly build.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Falke88

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: SFML Game Dev Guide - Game Tick Problem
« Reply #6 on: November 04, 2014, 03:12:51 pm »
Thanks but I managed to build these 4 .dlls outta the Github src.

Btw. can you shortly describe me the differences between CSFML and the other SFML .dlls?

EDIT:

Funny coincidence...error message:
Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'csfml-grap
hics-2': The specified module could not be found. (Exception from HRESULT: 0x800
7007E)
   at SFML.Graphics.RenderWindow.sfRenderWindow_createUnicode(VideoMode Mode, In
tPtr Title, Styles Style, ContextSettings& Params)
   at SFML.Graphics.RenderWindow..ctor(VideoMode mode, String title, Styles styl
e, ContextSettings settings)
   at SFML.Graphics.RenderWindow..ctor(VideoMode mode, String title)
   at Tutorial_Game.Game..ctor() in c:\Users\FalkeXY\Desktop\SFML_Game_Dev\Game\
Game.cs:line 30
   at Tutorial_Game.Program.Main(String[] args) in c:\Users\FalkeXY\Desktop\SFML
_Game_Dev\Game\Program.cs:line 14
Press any key to continue . . .
« Last Edit: November 04, 2014, 03:20:11 pm by Falke88 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10911
    • View Profile
    • development blog
    • Email
AW: SFML Game Dev Guide - Game Tick Problem
« Reply #7 on: November 04, 2014, 03:19:42 pm »
SFML is the actual library with all the functions. CSFML is a C API "wrapper" for SFML, that way you get a C ABI which is needed for (easily) writing bindings, such as SFML.NET.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Falke88

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: SFML Game Dev Guide - Game Tick Problem
« Reply #8 on: November 04, 2014, 03:27:44 pm »
Hm okay, well I'm not into "wrappers" at all till now. Would be too nice to see my stuff working right away - its always more fun with errors interrupting :P

I checked your nightly builds page - but couldn't find any solution for .NET tho.
Also I can't figure out good enough how to use CSFML DLLs...
Tried to integrate them like I did with sfml .DLL but an error message provides me with flames here aswell.

So I'm stuck with that Error Message above until I figured out how to solve it.
Since I don't wanna bugger you with these FAQuestions of mine I would just like to see any URL to some descriptions and tutorials to get along with CSFML.

EDIT: Just found out my Error erupted because I didn't put these CSFML files into the Debug folder. reading through the classes of the sfml.net .dlls told me that these csfml.dlls are being imported externally...nice to know
« Last Edit: November 04, 2014, 03:53:18 pm by Falke88 »

 

anything