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

Pages: [1]
1
Graphics / Re: Trouble understanding spritesheets
« on: May 10, 2020, 07:25:42 pm »
Hi thanks for looking...sorry I wasn't more specific - by nothing I meant the image is not displayed. The window opens fine and no errors. I simply get a black background and that's it. If I change the last to values to something that doesn't make sense...say 300, 400 I do see something. I see a large rectangle of the colour of one of the quadrants in the sheet.
The other thing is, is if I display the whole sheet as is - just as a single image its truncated at the top. I think it seems to be because the title of the window cuts off the image?

https://imgur.com/a/vopWmrU

Here is a 800x600 image displayed in a 800x600 window...there is some of the image missing at the top. I think that is my issue - the sprite is beneath the title bar.
(some further experimenting later) Yes that is the issue. My sprites were so small they were hidden beneath the title bar. Is that expected behaviour? If I offset the sprite vertically bay say 32 pixels it's visible.Anyway here's the code :

// Demonstrate creating a spritesheet
#include "SFML/Graphics.hpp"

int main(int argc, char** argv) {
    sf::RenderWindow renderWindow(sf::VideoMode(640, 480), "Demo Game");

    sf::Event event;
    sf::Texture texture;
    texture.loadFromFile("sheet.png");

    sf::Sprite sprite(texture, sf::IntRect(0, 0, 32, 32));
    sprite.setPosition(32, 32);


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

        renderWindow.clear();
        renderWindow.draw(sprite);
        renderWindow.display();
    }
}

Thanks for looking...I'll definitely check those links.




2
Graphics / Trouble understanding spritesheets
« on: May 10, 2020, 11:19:25 am »
Hey everyone I am very new to this so please bear with me. I've been following this tutorial:
https://www.gamefromscratch.com/post/2015/10/26/SFML-CPP-Tutorial-Spritesheets-and-Animation.aspx
I am on the very first  part.

I am not using his example image, but a very small 32x32 png divided into 4x4 squares of colour.
Now, whatever I use as coordinates, I get nothing, or maybe something but totally unexpected results. The way I understand it is the first two values specify the top corner of the rectangle, the second two its size.
But if I use this:
sf::Sprite sprite(texture, sf::IntRect(0, 0, 16, 16);
I expect a 16x16 pixel chunk of the top left corner of the image. However, when I run it, I get nothing.
Can someone help explain how this works? I not getting it at all!
Thanks!

Pages: [1]
anything