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

Author Topic: sf::Seconds delay?  (Read 15003 times)

0 Members and 1 Guest are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Seconds delay?
« Reply #15 on: August 23, 2012, 11:55:21 pm »
sf::Rect is an axis-aligned rectangle, so you only need 4 coordinates to describe it.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: sf::Seconds delay?
« Reply #16 on: August 24, 2012, 12:00:12 am »
Does who can read have a clear advantage... ;D

It's all written in the documentation and even the variable names tell what to pass in.
The first argument is for the (top) left coordinate of the sub-image, the second for the (left) top coordinate, the third is for the width of the sub-image (going from the specified left coordinate into the direction right) and the forth is for the height of the sub-image (going from the specified top coordinate into the direction down).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

rush905

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: sf::Seconds delay?
« Reply #17 on: August 24, 2012, 12:20:07 am »
I'm sorry, what? The first agrument is for the top-left corner, and the 2nd is for the left-top corner?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Seconds delay?
« Reply #18 on: August 24, 2012, 12:21:36 am »
Yeah, this was not the clearest explanation :P

The first is the  X coordinate of the left edge, the second is the Y coordinate of the top edge.
Laurent Gomila - SFML developer

rush905

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: sf::Seconds delay?
« Reply #19 on: August 24, 2012, 12:24:28 am »
Yeah, this was not the clearest explanation :P

The first is the  X coordinate of the left edge, the second is the Y coordinate of the top edge.

Ah, thank you. That makes a lot more sense. I'll try it out in a sec.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: sf::Seconds delay?
« Reply #20 on: August 24, 2012, 12:25:22 am »
Yeah, this was not the clearest explanation :P
True my over pronouncing was kind of missleading, but seriously read the documentation, I mean what's so hard to understand with the description "left", "top", "width" and "height"? ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

rush905

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: sf::Seconds delay?
« Reply #21 on: August 24, 2012, 12:30:22 am »
I guess because I would have done it with the cords of each corner, and I thought that was the approach they were trying to do as well.

Okay, I'm literally pulling my hair out right now, trying to figure out why this isn't working. If you guys could tell me what's wrong I would be so happy.

The image I'm using (zoomed):
http://i.imgur.com/jAc3D.png

Not zoomed:
http://i.imgur.com/JNRGT.png

The source:

#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
        //Create window, and limit frame rate
        sf::RenderWindow window (sf::VideoMode(800, 600, 32), "Game", sf::Style::Default);
        window.setFramerateLimit(30);

        //Declare image
        sf::Texture texture;
        //Load image
        if(!texture.loadFromFile("Sprites/main.png"))
        {
                return 1;
        }

        //Creates and places the main sprite
        sf::Sprite sprite;
        sprite.setPosition(400, 300);

        //Defines the rects that will be used to switch character view
        sf::IntRect front(2, 2, 17, -22);
        sf::IntRect back (22, 2, 16, 21);
        sf::IntRect left (2, 27, 16, 23);
        sf::IntRect right (23, 27, 16, 23);

        //Starts clock
        sf::Clock clock;

        //Main window loop
        while(window.isOpen())
        {
                sf::Event event;

                sf::Time time = clock.restart();

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

                        if(event.key.code == sf::Keyboard::Insert)
                        {
                                sf::Image screenshot = window.capture();
                                screenshot.saveToFile("Screenshot.png");
                        }
                }

                //Movement
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                {
                        sprite.setTextureRect(front);
                        sprite.move(0, -14 * time.asSeconds());
                }

                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                {
                        sprite.setTextureRect(back);
                        sprite.move(0, 14 * time.asSeconds());
                }

                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                {
                        sprite.setTextureRect(right);
                        sprite.move(16 * time.asSeconds(), 0);
                }

                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                {
                        sprite.setTextureRect(left);
                        sprite.move(-16 * time.asSeconds(), 0);
                }
               
                //Draw sequence
                window.clear(sf::Color(255, 0, 0)); //(Red, Green, Blue, (optional) Alpha) Alpha is transperency

                //Draw....

                window.draw(sprite);

                window.display();
        }
        return 0;
}
 
« Last Edit: August 24, 2012, 12:47:17 am by rush905 »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: sf::Seconds delay?
« Reply #22 on: August 24, 2012, 02:52:37 am »
Your rects are all wrong.
Your spirte has no texture assigned to it so it quits it's drawing call without drawing anything.
Back to C++ gamedev with SFML in May 2023

rush905

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: sf::Seconds delay?
« Reply #23 on: August 24, 2012, 03:09:34 am »
Oh my god, I must have deleted it by mistake! I've been up all night, and haven't slept at all, so I can't think straight right now. Thank you so much, you saved me.

Now I have to get the original problem I was having solved. I need to delay the movement of the character. The earlier solution didn't help.
« Last Edit: August 24, 2012, 03:17:07 am by rush905 »