This is what's happening when I load certain sprites. Is it just that they're too big? Is this a known problem with SFML?
Here is my code (It's long) Tell me if posting the sprite map we're using would help (I load the charizard sprite under the function EVOLVE(); )
#include "stdafx.h"
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
using namespace sf;
using namespace std;
enum STATE {PLAY, PAUSED, STARTER, LOADING} GAME_STATE = LOADING;
enum POKEMON { BULB, CHAR, SQUIRT, IVY, CHARMIL, WART, NONE } POKEMON_STATE = NONE;
Clock TIMER;
Time t1 = TIMER.getElapsedTime();
Time t2 = milliseconds(333);
Texture pauseTexture;
Sprite pauseSprite;
Texture texture;
Sprite sprite;
Texture startMenu;
Sprite startMenuS;
Texture palletTexture;
Sprite palletSprite;
RenderWindow window(VideoMode(640, 480), "PokeMOBA!", Style::Titlebar);
Vector2i poke;
double speed = 15.1;
void LOAD()
{
palletTexture.loadFromFile("palletTown.png");
palletSprite.setTexture(palletTexture);
texture.loadFromFile("PokeSprites.png");
sprite.setTexture(texture);
pauseTexture.loadFromFile("PAUSE.png");
pauseSprite.setTexture(pauseTexture);
GAME_STATE = STARTER;
}
void START()
{
window.clear();
startMenu.loadFromFile("choosepokemon.png");
startMenuS.setTexture(startMenu);
window.draw(startMenuS);
window.display();
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
sf::Vector2i localPosition = sf::Mouse::getPosition(window); // window is a sf::Window
if (localPosition.y < 165 && localPosition.y > 40)
{ //Clicked near a pokeball
if ( 150 > localPosition.x && localPosition.x > 20)
{ //chose Bulbasaur!
poke.x = 0;
poke.y = 0;
GAME_STATE = PLAY;
POKEMON_STATE = BULB;
texture.loadFromFile("PokeSprites.png", IntRect(poke.x,poke.y,32,32));
sprite.setTexture(texture);
window.clear();
window.draw(sprite);
window.display();
}
if (380 > localPosition.x && localPosition.x > 250)
{//Chose CHARMANDER
poke.x = 256;
poke.y = 0;
GAME_STATE = PLAY;
POKEMON_STATE = CHAR;
texture.loadFromFile("PokeSprites.png", IntRect(poke.x,poke.y,32,32));
sprite.setTexture(texture);
window.clear();
window.draw(sprite);
window.display();
}
if (625 > localPosition.x && localPosition.x > 495)
{//Chose Squirtle
poke.x = 450;
poke.y = 0;
GAME_STATE = PLAY;
POKEMON_STATE = SQUIRT;
texture.loadFromFile("PokeSprites.png", IntRect(poke.x,poke.y,32,32));
sprite.setTexture(texture);
window.clear();
window.draw(sprite);
window.display();
}
}
}
}
void EVOLVE() {
if(POKEMON_STATE == BULB && Keyboard::isKeyPressed(Keyboard::M)) { //EVOLVED INTO IVYSAUR!
poke.x = 64;
poke.y = 0;
POKEMON_STATE = IVY;
texture.loadFromFile("PokeSprites.png", IntRect(poke.x,poke.y,32,32));
sprite.setTexture(texture);
window.clear();
window.draw(sprite);
window.display();
}
if(POKEMON_STATE == IVY && Keyboard::isKeyPressed(Keyboard::M)) { //EVOLVED INTO Venusaur!
poke.x = 128;
poke.y = 0;
POKEMON_STATE = IVY;
texture.loadFromFile("PokeSprites.png", IntRect(poke.x,poke.y,32,32));
sprite.setTexture(texture);
window.clear();
window.draw(sprite);
window.display();
}
if(POKEMON_STATE == CHAR && Keyboard::isKeyPressed(Keyboard::M)) { //EVOLVED INTO CHARMILLION!
poke.x = 320;
poke.y = 0;
POKEMON_STATE = CHARMIL;
texture.loadFromFile("PokeSprites.png", IntRect(poke.x,poke.y,32,32));
sprite.setTexture(texture);
window.clear();
window.draw(sprite);
window.display();
}
if(POKEMON_STATE == CHARMIL && Keyboard::isKeyPressed(Keyboard::M)) { //EVOLVED INTO Charizard!!
poke.x = 385;
poke.y = 0;
texture.loadFromFile("PokeSprites.png", IntRect(poke.x,poke.y,32,32));
sprite.setTexture(texture);
window.clear();
window.draw(sprite);
window.display();
}
if(POKEMON_STATE == SQUIRT && Keyboard::isKeyPressed(Keyboard::M)) { //EVOLVED INTO Venusaur!
poke.x = 512;
poke.y = 0;
POKEMON_STATE = WART;
texture.loadFromFile("PokeSprites.png", IntRect(poke.x,poke.y,32,32));
sprite.setTexture(texture);
window.clear();
window.draw(sprite);
window.display();
}
if(POKEMON_STATE == WART && Keyboard::isKeyPressed(Keyboard::M)) { //EVOLVED INTO Venusaur!
poke.x = 576;
poke.y = 0;
texture.loadFromFile("PokeSprites.png", IntRect(poke.x,poke.y,32,32));
sprite.setTexture(texture);
window.clear();
window.draw(sprite);
window.display();
}
}
void PAUSE()
{
window.clear();
pauseTexture.loadFromFile("PAUSE.png");
pauseSprite.setTexture(pauseTexture);
window.draw(pauseSprite);
window.display();
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
{
GAME_STATE = PLAY;
window.clear();
}
}
void playDraw()
{
window.draw(palletSprite);
window.draw(sprite);
window.display();
}
void walkAnimation(int x1, int y1, double speedx, double speedy)
{
//if(t1 < t2)
if (true)
{
TIMER.restart();
window.clear();
sprite.move(speedx,speedy);
texture.loadFromFile("PokeSprites.png", IntRect(x1,y1,32,32));
sprite.setTexture(texture);
//sprite.setTextureRect(IntRect(x1,y1,32,32));
playDraw();;
window.clear();
sprite.move(speedx,speedy);
texture.loadFromFile("PokeSprites.png", IntRect(x1,y1+32,32,32));
sprite.setTexture(texture);
//sprite.setTextureRect(IntRect(x1+32,y1,32,32));
playDraw();
}
}
void playControls()
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
{
PAUSE();
GAME_STATE = PAUSED;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
{
START();
GAME_STATE = STARTER;
}
//while (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
while (sf::Keyboard::isKeyPressed(sf::Keyboard::E))
walkAnimation(poke.x,poke.y,speed,-speed);
//while (Keyboard::isKeyPressed(Keyboard::Up) && Keyboard::isKeyPressed(Keyboard::Left))
while (sf::Keyboard::isKeyPressed(sf::Keyboard::Q))
walkAnimation(poke.x,poke.y,-speed,-speed);
while (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) //poke.x//poke.y+32//-SPEED//0
walkAnimation(poke.x+32,poke.y,-speed,0);
while (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) //poke.x//poke.y+64//+SPEED//0
walkAnimation(poke.x+32,poke.y+64,speed,0);
while (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) //This is the basis//poke.x//poke.y//0//-SPEED
walkAnimation(poke.x,poke.y,0,-speed);
while (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) //poke.x//poke.y+32//0//+SPEED
walkAnimation(poke.x,poke.y+64,0,speed);
}
int main()
{
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type == Event::Closed)
window.close();
}
// Initialize
sprite.setScale(2,2); //Increases the size of the sprite (xratio,yratio)
while (GAME_STATE == LOADING)
{
LOAD();
}
while (GAME_STATE == STARTER)
{
START();
}
while (GAME_STATE == PAUSED)
{
PAUSE();
if(Keyboard::isKeyPressed(Keyboard::Delete)) {
window.close();
break;
}
}
while (GAME_STATE == PLAY)
{
playDraw();
EVOLVE();
playControls();
}
} //Close of while (window.isOpen())
return 0;
} //Close of int main()