1
Graphics / Help with .setTextureRect
« on: April 16, 2012, 05:23:58 am »
Okay so heres my code sorry if its messy I'm just playing with stuff right now
I'm trying to display the second sprite on my sheet, the sheets 128x128 and each sprite is 32x64 so at the bottom it should display the second sprite on the sheet but instead this is what I get.
its showing two zombies on me
So I would be very grateful if someone could explain what I'm doing wrong.
Code: [Select]
#include "stdafx.h"
#include <iostream>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#define ScreenWidth 800
#define ScreenHeight 600
using namespace std;
using namespace sf;
int main()
{
int SourceFrameX = 0;
int SourceFrameY = 0;
int SourceFrameXO = 32;
int SourceFrameYO = 64;
RenderWindow GameWindow(VideoMode(ScreenWidth, ScreenHeight, 32), "Window");
float ZombposX = 400;
float ZombposY = 300;
Texture ZombieT;
if(!ZombieT.loadFromFile("ZombSprite.png")) return EXIT_FAILURE;
Sprite ZombieS;
ZombieS.setTexture(ZombieT);
while(GameWindow.isOpen())
{
Event MainEvent;
while(GameWindow.pollEvent(MainEvent))
{
if(MainEvent.type == Event::Closed) GameWindow.close();
if(Keyboard::isKeyPressed(Keyboard::D))
{
ZombposX ++;
(SourceFrameX + 32);
(SourceFrameXO + 32);
//ZombieS.setTextureRect(IntRect(SourceFrameX, SourceFrameY, SourceFrameXO, SourceFrameYO));
}
if(Keyboard::isKeyPressed(Keyboard::A))
{
ZombposX --;
(SourceFrameX + 32);
(SourceFrameXO + 32);
//ZombieS.setTextureRect(IntRect(32, 0, 64, 64));
}
if(!Keyboard::isKeyPressed(Keyboard::D))
{
//ZombieS.setTextureRect(IntRect(0, 0, 32, 64));
}
}
ZombieS.setTextureRect(IntRect(32, 0, 64, 64));
ZombieS.setPosition(ZombposX, ZombposY);
GameWindow.clear();
GameWindow.draw(ZombieS);
GameWindow.display();
GameWindow.setVerticalSyncEnabled(true);
}
return EXIT_SUCCESS;
}
I'm trying to display the second sprite on my sheet, the sheets 128x128 and each sprite is 32x64 so at the bottom it should display the second sprite on the sheet but instead this is what I get.
its showing two zombies on me
So I would be very grateful if someone could explain what I'm doing wrong.