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

Author Topic: Help with .setTextureRect  (Read 2071 times)

0 Members and 1 Guest are viewing this topic.

kkiikki

  • Newbie
  • *
  • Posts: 3
    • View Profile
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  :-\

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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Help with .setTextureRect
« Reply #1 on: April 16, 2012, 07:51:00 am »
Read the doc of IntRect::IntRect again ;)
Laurent Gomila - SFML developer