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

Pages: [1] 2
1
Graphics / Re: Camera Boundary
« on: July 20, 2013, 06:41:37 am »
    sf::View view;
    view.reset(sf::FloatRect(0,0, screenDimensions.x, screenDimensions.y));
    view.setViewport(sf::FloatRect(0,0, 1.0f, 1.0f));
    sf::Vector2f position(screenDimensions.x / 2, screenDimensions.y / 2);

        if(animatedSprite.getPosition().x + 16 > screenDimensions.x / 2)
            position.x = animatedSprite.getPosition().x + 16;
        else
            position.x = screenDimensions.x / 2;

        if(animatedSprite.getPosition().y + 16 > screenDimensions.y / 2)
            position.y = animatedSprite.getPosition().y + 16;
        else
            position.y = screenDimensions.y / 2;

        view.setCenter(position);

        window.setView(view);

I keep trying to keep the camera from going off the background by tracking the sprite, but that obviously was not working right!

If I understood you right, you want to stop the camera once it would potentially leave the background texture, is that right?

Yes, that is exactly what I am trying to do. Keeping everything a variable that can change with the size of the map.

2
Graphics / Camera Boundary
« on: July 19, 2013, 10:59:39 pm »
Can anyone point me in the direction of some type of idea how to get a centered camera to stop moving in the bottom and right directions. Should I be figuring out the coordinates of the camera and making sure they are less than my background?

3
Graphics / Re: Sprite Animation Speed Ridiculously Fast
« on: July 19, 2013, 01:29:57 pm »
Well that works perfectly for the 4 directions :D I have plenty more things I can be working on with the game, so refining the code is in no way a priority! Thanks so much for fixing all that!

4
Graphics / Re: Sprite Animation Speed Ridiculously Fast
« on: July 18, 2013, 05:11:26 pm »
You should invest some time in separating Animation updates and input altogether. Input should be handled by it's own, and when you get into updating Animations(which would come in the general character update) you just check for any pressed keys, if no keys are pressed, then you revert to an idle animation, stop any current animations or even let the current animation finish what it's doing. This way if you come into anything more then just 4 movement animations, things will be easier to add in.

At my current understanding of c++ and SFML, I am doing what I know how to do :)

5
Graphics / Re: Sprite Animation Speed Ridiculously Fast
« on: July 18, 2013, 04:52:33 pm »
That's actually a really good idea! That is probably the issue. Now for a solution...

6
Graphics / Re: Sprite Animation Speed Ridiculously Fast
« on: July 18, 2013, 02:21:48 pm »
Spritesheet being used currently

7
Graphics / Re: Sprite Animation Speed Ridiculously Fast
« on: July 18, 2013, 01:44:01 pm »
That is the movement code...
Current situation with this setup:
The animation does not play when I press any direction key, upon release of the key, the animation begins to play the last direction it was going but it is going in loop.

            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
            {
                animatedSprite.move(0, -speed);
                animatedSprite.setAnimation(walkingAnimationUp);
                animatedSprite.play();
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
            {
                animatedSprite.move(0, speed);
                animatedSprite.setAnimation(walkingAnimationDown);
                animatedSprite.play();
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
            {
                animatedSprite.move(speed, 0);
                animatedSprite.setAnimation(walkingAnimationRight);
                animatedSprite.play();
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
            {
                animatedSprite.move(-speed, 0);
                animatedSprite.setAnimation(walkingAnimationLeft);
                animatedSprite.play();
            }

8
Graphics / Re: Sprite Animation Speed Ridiculously Fast
« on: July 18, 2013, 01:18:16 pm »
Moving the animations to input has no animation working at all. Leaving them inside events with the else commented out still only does one loop, but as soon as I let go of the key, the animation just keeps going.

Also, if I continue to hold down the key, no other event is happening, so the animation should keep playing with that else statement. It should only trigger if I do anything else at that point.

9
Graphics / Re: Sprite Animation Speed Ridiculously Fast
« on: July 18, 2013, 01:04:06 pm »
I am having a hard time understanding where to put this bool still... I don't even know what it is that I am not understanding,

10
Window / Re: Closing window returns error.
« on: July 18, 2013, 12:42:55 am »
While helping with another issue, Foaly provided me with a full main.cpp and it changed the window handling to as follows, and it works with no error!

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
                window.close();
            if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::P)
            {

11
Graphics / Re: Sprite Animation Speed Ridiculously Fast
« on: July 18, 2013, 12:30:11 am »
Foaly: I have decided to go with yours as it was easiest for me to understand. I want to point out that there was some error in my code with window handling because your code also got rid of an exit error I have been having and posted in another tread! :)

Assuming that it is somewhat efficient, that is the best I could do with my current knowledge. It works completely! Any further improvements would be appreciated, but with some explanation as I really fried my brain figuring that out. :P

I have one issue though, where do I enable the loop for the animation?

#include <SFML/Graphics.hpp>
#include "AnimatedSprite.hpp"

int main()
{
    sf::Vector2i screenDimensions(800,600);
    sf::RenderWindow window(sf::VideoMode(screenDimensions.x, screenDimensions.y), "Animations!");

    // load texture
    sf::Texture texture;
    texture.loadFromFile("Player.png");

    // push frames
    Animation walkingAnimationDown;
    walkingAnimationDown.setSpriteSheet(texture);
    walkingAnimationDown.addFrame(sf::IntRect(0, 0, 32, 32));
    walkingAnimationDown.addFrame(sf::IntRect(32, 0, 32, 32));
    walkingAnimationDown.addFrame(sf::IntRect(64, 0, 32, 32));

    Animation walkingAnimationLeft;
    walkingAnimationLeft.setSpriteSheet(texture);
    walkingAnimationLeft.addFrame(sf::IntRect(0, 32, 32, 32));
    walkingAnimationLeft.addFrame(sf::IntRect(32, 32, 32, 32));
    walkingAnimationLeft.addFrame(sf::IntRect(64, 32, 32, 32));

    Animation walkingAnimationRight;
    walkingAnimationRight.setSpriteSheet(texture);
    walkingAnimationRight.addFrame(sf::IntRect(0, 64, 32, 32));
    walkingAnimationRight.addFrame(sf::IntRect(32, 64, 32, 32));
    walkingAnimationRight.addFrame(sf::IntRect(64, 64, 32, 32));

    Animation walkingAnimationUp;
    walkingAnimationUp.setSpriteSheet(texture);
    walkingAnimationUp.addFrame(sf::IntRect(0, 96, 32, 32));
    walkingAnimationUp.addFrame(sf::IntRect(32, 96, 32, 32));
    walkingAnimationUp.addFrame(sf::IntRect(64, 96, 32, 32));


    // set up AnimatesSprite
    AnimatedSprite animatedSprite(sf::seconds(0.2));
    animatedSprite.setAnimation(walkingAnimationDown);
    animatedSprite.pause();
    animatedSprite.setPosition(0,0);

    sf::Clock frameClock;

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
                window.close();
            if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Up)
            {
                animatedSprite.setAnimation(walkingAnimationUp);
                animatedSprite.play();
            }
            else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Down)
            {
                animatedSprite.setAnimation(walkingAnimationDown);
                animatedSprite.play();
            }
            else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Left)
            {
                animatedSprite.setAnimation(walkingAnimationLeft);
                animatedSprite.play();
            }
            else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Right)
            {
                animatedSprite.setAnimation(walkingAnimationRight);
                animatedSprite.play();
            }
            else
            {
                animatedSprite.pause();
            }
            /*if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::P)
            {
                if(animatedSprite.isPlaying())
                    animatedSprite.pause();
                else
                    animatedSprite.play();
            }*/

        }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
            {
                animatedSprite.move(0, -.25);
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
            {
                animatedSprite.move(0, .25);
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
            {
                animatedSprite.move(.25, 0);
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
            {
                animatedSprite.move(-.25, 0);
            }
        // update AnimatedSprite
        animatedSprite.update(frameClock.restart());


        window.clear();
        window.draw(animatedSprite);
        window.display();
    }

    return 0;
}

 

12
Graphics / Re: Sprite Animation Speed Ridiculously Fast
« on: July 17, 2013, 01:08:49 pm »
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
        {
            source.y = Up;
            playerImage.move(0, -1);
        }
        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
        {
            source.y = Down;
            playerImage.move(0, 1);
        }animationCounter                           //Not sure what is going on here?
        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
        {
            source.y = Right;
            playerImage.move(1, 0);
        }
        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        {
            source.y = Left;
            playerImage.move(-1, 0);
        }
        if(source.x * 32 >= pTexture.getSize().x)
            source.x = 0;

Not sure what is going on there :p So I just deleted it and it seems to work perfectly :) Thank you so much!

13
Graphics / Re: Sprite Animation Speed Ridiculously Fast
« on: July 17, 2013, 12:28:02 pm »
Perhaps a snippet of an example? Just tinkering with my current code after removing the extra source.x++ gives me an appropriate speed, and I do not have any idea how to properly set up the clock to get the elapsed time to put into an equation to progress my animation. So if you don't mind clarifying that, I would greatly appreciate it. :)

It can be bare minimum not even in proper context, just a general layout would help a lot!

14
Graphics / Re: Sprite Animation Speed Ridiculously Fast
« on: July 17, 2013, 12:01:28 pm »
massive_potato: That was the issue! So thank you very much for pointing that out.

gostron: I am not exactly well versed in SFML, so let me take a shot at understanding what I should be doing with that counter.

By time passed, are you referring to the time between frames in ms?

Either way, when the passed time is greater than 300ms for example, I would then source.x++?

15
Graphics / Re: Sprite Animation Speed Ridiculously Fast
« on: July 17, 2013, 09:30:53 am »
I set it to 1 and get the same exact result. It is just not affecting it at all.

Pages: [1] 2
anything