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

Pages: 1 [2]
16
Given your edit, I assume there are no huge frame drops anymore, right?

Yea, I turned on FRAPS to see if maybe I just failed at my calculations for the FPS and it seems like I did. The framerate seems to stay steady now.

Instead the suggested solution is mostly to implement fixed time step for your logic.

What features should use fixed timesteps? I currently have movement and collision
detection/resolving on deltaTime. I will not have physics. The only thing I do have on fixed time are animations. If you need me to paste code, just ask. Thanks!

EDIT: Sorry, collision doesn't use deltaTime, but it updates every frame is what I meant to say.

17
General / Re: Does anyone else have massive frame drops for no reason?
« on: August 10, 2014, 02:36:59 am »
No, I'm sure it's not my computer as it's pretty high end. I don't get this in other games.

18
General / Does anyone else have massive frame drops for no reason?
« on: August 10, 2014, 02:14:23 am »
EDIT: So I just realized the way that I was calculating FPS was wrong :u However, I still get stutter even with the high framerates. I am using deltaTime, does anyone know what could be causing this?

Hi,

I am working on a game and am having an issue with my framerate dropping massively for no reason. And I'm not talking about just any framerate drop, I mean it will constantly go from 2000+ to 20 for a frame.This happens when something is happening or when nothing is happening at all. I'm pretty sure this is what is causing issues with jittery movement when using delta time, as well. Has anyone else had this issue?

Thanks!

19
Graphics / setTextureRect() not changing the sprite
« on: May 30, 2014, 07:42:02 pm »
Hi,

So in my header file for the player I have this code:

const std::array<sf::IntRect, 3> INTERACT
        {{
                sf::IntRect(11, 0, 11, 10),
                sf::IntRect(22, 0, 11, 10),
                sf::IntRect(11, 0, 11, 10)
        }};

And then in the source file I have this inside the update function:
 if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space) && animationState != interact)
        {
                 animationState = interact;

                 for (int i = 0; i < INTERACT.size(); i++)
                 {
                         sf::Clock frameTimer;
                         sprite.setTextureRect(INTERACT[i]);
                         std::cout << "Sprite: " << i << "should have changed..." << std::endl;
                         //Waits to iterate the next frame
                         while (frameTimer.getElapsedTime().asMilliseconds() < 100) {}
                 }

                 animationState = idle;
                 std::cout << "done!";
        }

Now, the problem is that the sprite.setTextureRect(INTERACT(i)) part does not work. The cout does run so I know that the function is being called. If I hold down the spacebar, however, it will eventually be showing just the last frame. Is there something obvious that I'm missing?

20
Graphics / Re: Jittery Movement Even With deltaTime
« on: May 30, 2014, 07:36:31 pm »
Thanks, that seems to have helped. I have one more question though... (new forum post because it isn't related to this; it is in the same section though).

21
Graphics / Jittery Movement Even With deltaTime
« on: May 30, 2014, 04:49:01 am »
Hi,

I was creating the code to move my sprite and implemented deltaTime into it, yet the sprite still jitters often when moving around. Does anyone know what is wrong? Comment if you need more detail.

main.cpp
#include <SFML/Graphics.hpp>
#include "player.h"

int main()
{
        sf::RenderWindow window(sf::VideoMode(1280, 720), "Incremental");

        sf::Clock clock;
        player player;

        //Game Loop
        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                window.clear();
                player.update(clock.restart().asSeconds());
                window.draw(player.sprite);
                window.display();
                clock.restart();
        }

        return 0;
}

player.h
#ifndef PLAYER_H
#define PLAYER_H
#include <SFML/Graphics.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/System/Time.hpp>
#include <SFML/Window/Keyboard.hpp>


class player
{
private:

        // Clock and timer used to iterate between positions on the sprite sheet.
        sf::Clock fpsClock;
        sf::Time fpsTimer;

        sf::Texture spriteSheet;


        //Animation States
        enum AnimationState
        {
                idle,
                run,
                interact
        };

        AnimationState animationState = idle;
       
        //Used to check if sprite scale is already inversed when going left.
        bool spriteInvertable = true;
        //Movement
        sf::Vector2f position;
        float speed = 10000;

        //Scale Properties
        float spriteScaleX = 10, spriteScaleY = 10;

        /*Animation positions in the sprite sheet...
        Arrays are static and initialized elsewhere
        cause VS is a POS and I had to use a workaround.
        */

        const sf::IntRect IDLE = sf::IntRect(0, 0, 8, 10);
        static const sf::IntRect RUN[2];
        static const sf::IntRect INTERACT[4];

public:

        sf::Sprite sprite;
       
        //Animation Functions
        void setAnimationState(const AnimationState&);
        void animate();
        void update(const double&);

        player();
};

#endif
 

player.cpp
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/System/Time.hpp>
#include <SFML/Window/Keyboard.hpp>
#include <iostream>
#include "player.h"

const sf::IntRect player::RUN[2] =
{
        sf::IntRect(33, 0, 8, 10),
        sf::IntRect(44, 0, 8, 10)
};
const sf::IntRect player::INTERACT[4] =
{
        sf::IntRect(1, 0, 8, 10),
        sf::IntRect(9, 0, 8, 10),
        sf::IntRect(17, 0, 8, 10),
        sf::IntRect(9, 0, 8, 10)
};

void player::setAnimationState(const AnimationState& state)
{
        animationState = state;
}
void player::update(const double& deltaTime)
{
        //Debugz
        std::cout << deltaTime << std::endl;

        //Movement Update
        if
                (
                sf::Keyboard::isKeyPressed(sf::Keyboard::D) &&
                !sf::Keyboard::isKeyPressed(sf::Keyboard::A) &&
                animationState != interact
                )
        {
                //Moves the sprite
                sprite.move(speed * deltaTime, 0);

                setAnimationState(run);
                fpsTimer = fpsClock.getElapsedTime();

                //Animates by going through the texture (probably a better way to do this...)
                if (fpsTimer.asMilliseconds() <= 30 * 3)
                {
                        sprite.setTextureRect(RUN[0]);
                }
                else if (fpsTimer.asMilliseconds() <= 60 * 3 && fpsTimer.asMilliseconds() > 30 * 3)
                {
                        sprite.setTextureRect(RUN[1]);
                }
                else if (fpsTimer.asMilliseconds() >= 60 * 3)
                {
                        fpsClock.restart();
                }

                //Re-enables spriteInvertable and uninverts the image if it was inverted.
                if (!spriteInvertable)
                {
                        sprite.setScale(spriteScaleX, spriteScaleY);
                        spriteInvertable = true;
                }
        }
        else if
                (
                sf::Keyboard::isKeyPressed(sf::Keyboard::A) &&
                !sf::Keyboard::isKeyPressed(sf::Keyboard::D) &&
                animationState != interact
                )
        {
                //Moves the sprite
                sprite.move(-1 * speed * deltaTime, 0);
               
                setAnimationState(run);
                fpsTimer = fpsClock.getElapsedTime();

                //Animates by going through the texture (probably a better way to do this...)
                if (fpsTimer.asMilliseconds() <= 30 * 3)
                {
                        sprite.setTextureRect(RUN[0]);
                }
                else if (fpsTimer.asMilliseconds() <= 60 * 3 && fpsTimer.asMilliseconds() > 30 * 3)
                {
                        sprite.setTextureRect(RUN[1]);
                }
                else if (fpsTimer.asMilliseconds() >= 60 * 3)
                {
                        fpsClock.restart();
                }
               
                //Inverts Sprite
                if (spriteInvertable)
                {
                        sprite.setScale(-spriteScaleX, spriteScaleY);
                        spriteInvertable = false;
                }

        }
        else
        {
                sprite.setTextureRect(IDLE);
        }
}

player::player()
{
        //Loads up the texture and sets the sprite to it.
        spriteSheet.loadFromFile("../art/final/player.png");
        sprite.setTexture(spriteSheet);
        sprite.setOrigin(5, 8);
        //Default state
        sprite.move(0, 100);
        sprite.setTextureRect(IDLE);
        sprite.setScale(spriteScaleX, spriteScaleY);
}

THANKS!  ;)

Pages: 1 [2]
anything