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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - franks

Pages: [1]
1
General / Re: Window resize and world coordinates
« on: March 24, 2017, 12:48:18 pm »
This is because your movement is based directly on your frame time. The larger your window the longer it takes to render a frame, and the slower the program updates. Take a look at the fix your timestep article for a good explanation. You're also moving in the middle of a clear/display cycle, when really you should be updating your logic outside of this.

Thank you, this works  ;D

Anyway, conversions between coordinate systems have nothing to do with movements being slower. Try to describe your problem precisely, instead of describing what you think the solution is.

Sorry, next time I will explain directly my problem

2
General / Re: Window resize and world coordinates
« on: March 22, 2017, 08:45:49 pm »
Alright  :). This is what I done (I simplified). With or without the view I have the same problem. When I run my game the player has a certain speed. But when I scale up the window the player is slower. And when I scale down the window  the player is quicker. Why ?

#include <SFML/Graphics.hpp>

int main() {
   
   // Window and view
   sf::RenderWindow window(sf::VideoMode(1024, 768), "SFML Test");
   sf::View view(sf::FloatRect(0, 0, 720, 480));
   window.setView(view);
   
   // Events
   sf::Event event;
   
   // Texture and sprite
   sf::Texture texture;
   texture.loadFromFile("../res/player.png");
   sf::Sprite player(texture);

   // Main loop
   while(window.isOpen()) {
     
      // Check events
      while(window.pollEvent(event))
         if(event.type == sf::Event::Closed)
            window.close();
     
     
      // Clear window
      window.clear(sf::Color::Black);
   
      // Movement
      if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
         player.move(-1, 0);
     
      if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
         player.move(1, 0);
   
      // Draw the plaxer
      window.draw(player);
   
      // End the current frame
      window.display();
   }

   return EXIT_SUCCESS;
}

 

PS : I added the view because I have a tiled map in my game.

3
General / Re: Window resize and world coordinates
« on: March 22, 2017, 06:47:24 pm »
I can't scale my rendering region. I can just change the size of the rendering region. However I can use a view. But it's the same problem. When you use a custom view or when you resize the window I think I have to convert my coordinate.

4
General / Window resize and world coordinates
« on: March 22, 2017, 06:07:27 pm »
Hello,

I'm trying to develop a basic 2D platformer game with SFML2. I have a player that can move right, left and jump. But when I resize the window the movements are slow. I did some research and I found that I need to convert the world unit to pixel with mapCoordsToPixel ...

Do I really need to convert every coordinates of my entities ? Is there a camera like Libgdx and draw on this instead of the screen ? What is the best pratice to do that ?

Pages: [1]