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.


Topics - DarwinCar

Pages: [1]
1
Graphics / Problem with IntRect or setTextureRect
« on: October 24, 2018, 06:09:06 pm »
Hello,
So I've struggling to find if its a problem with my code or anything else on my part. (Also, tried different Visual Studio versions, different textures/sprites, also tried inside a VM and with different SFML versions 2.4/2.5.1).

I've attached the whole project.
The way its supposed to look : https://imgur.com/a/o8Wc2oZ
And how it looks : https://imgur.com/a/rzU6zM1

Also here is the code :
Code: [Select]
#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("images/dragonFrames.png");

sf::IntRect rectSourceSprite(300, 0, 300, 400);
sf::Sprite sprite(texture, rectSourceSprite);
sf::Clock clock;

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

if (clock.getElapsedTime().asSeconds() > 1.0f) {
if (rectSourceSprite.left == 600)
rectSourceSprite.left = 0;
else
rectSourceSprite.left += 300;

sprite.setTextureRect(rectSourceSprite);
clock.restart();
}


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

Pages: [1]
anything