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 - utan

Pages: [1]
1
General / Re: setFramerateLimit() && setVerticalSyncEnabled()
« on: January 30, 2021, 03:43:56 pm »
Hi,

Anyone able to duplicate the issue?

2
General / Re: setFramerateLimit() && setVerticalSyncEnabled()
« on: January 30, 2021, 03:10:38 am »
well,

I formulated badly my post, if I use any of them I get the frame skipping ..

I have tested same example in AMD PC and an Intel one.. same result..

If I don't use any of them it works fine...

 I am don't know what is it..

3
General / setFramerateLimit() && setVerticalSyncEnabled()
« on: January 30, 2021, 01:23:37 am »
Hi all,

So I am getting weird results when moving my character is not smooth.. it actually skips at the middle center of the window.. When I disable both functions it doesn't appear to skip anymore..

I try to do bare bone to see if it was something I did in the code, I found this in the forum and would like to know if you see frame skipped using the example below because in my computer it seems to do..

thanks..

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Test");
    window.setVerticalSyncEnabled(true);

    sf::Vector2f player1(10, 10);
    sf::RectangleShape paddle1(sf::Vector2f(10, 30));

    sf::Clock clock;
    sf::Time time;

    float dt = 0;
    const int speed = 500;

    // Start the game loop
    while (window.isOpen())
    {

        // Poll for events
        sf::Event event;
        while (window.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed)
                window.close();

            // Escape pressed : exit
            if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
                window.close();
        }


        // Check for user input
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
            player1.y += speed * dt;

        // Check for user input
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
            player1.y -= speed * dt;

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
            player1.x -= speed * dt;

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
            player1.x += speed * dt;


        // Restart the clock and get the delta time
        time = clock.restart();
        dt = time.asSeconds();


        // Update the object positions
        paddle1.setPosition(player1.x, player1.y);

        // Clear screen
        window.clear();

        // Draw the sprites
        window.draw(paddle1);

        // Update the window
        window.display();
    }

    return EXIT_SUCCESS;
}
 

see in youtube

4
If no doable the way i want then i will do it passing reference or passing any parameter taken from de SF::WINDOW
 Apreciate ur help

5
Hi,
 To get the size of the window mainly , i dont like passing reference and having a global reference of sf::window come handy i guess. I am still learning SFML.


6
Thanks a lot,

 But is not that I want to draw the player, instead I want to have some public functions in the Player class that are dependent of the intance the window and I dont want to pass it as parameter refence to all clases that I want to create..

7
Hello there all,

 I am very new to CPP, but I have a question I couldn't get it settle searching..

private:
class Game {
private:
    sf::RenderWindow window;
public:

    Game() {
        this->window.create(sf::VideoMode(600, 500), this->name, sf::Style::Close);

        this->player(this->window);// instantiated window

    }
    Player player;
};

class Player {
private:
    sf::RenderWindow w;
public:
    Player(sf::RenderWindow& window)
        : w(window)
    {

        this->w; // window reference from Game class Available globally in Player Class this->w

    }
};

int main() {
        Game game;
        return 0;
}
 

I don't want to be passing reference of window on every class method in Player class and I don't want to pass it in main.cpp and pass it as reference from a normal object to both classes because I know works using the list initiator in the constructors.

Pages: [1]
anything