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

Pages: [1]
1
Graphics / Sprite tearing problem?
« on: November 30, 2013, 06:23:42 am »



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()

2
General / Re: I can't get this to work.
« on: November 28, 2013, 02:47:49 am »
Ooooh, I got it, Thanks so much, That should work.

3
General / Re: I can't get this to work.
« on: November 28, 2013, 02:21:03 am »
                TIMER.restart();
                Time t1 = TIMER.getElapsedTime();
t1 is probably 0ms or close to 0ms.
So it is never >= milliseconds(333) or >= t2 (which is also milliseconds(333) lol.).

When posting pieces of code (especially long ones) in the forum, you have to surround it with code tags. It greatly improves readability and you'll be more likely to get answers.


Thanks, I changed it.

Doesn't getElapsedTime get the time of how long the program has been running so far? So wouldn't it never be 0ms?

4
General / I can't get this to work.
« on: November 28, 2013, 02:03:49 am »
So I made this program and I totally was able to grab sprites until I added code for animation. All of the sudden when I run it, it's not showing anything. Here is the code. Why doesn't it work?
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
//#include "Chardicks.h"
//#include "Keystrokes.h"

using namespace sf;
using namespace std;

Texture texture;
Sprite Charmander;

int main()
{
    RenderWindow window(VideoMode(640, 480), "FUCKING CHARMANDER!");

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

                Clock TIMER;
                TIMER.restart();
                Time t2 = milliseconds(333);
                Time t1 = TIMER.getElapsedTime();
                int step = 0;

                TIMER.restart();

                if (t1 >= milliseconds(333))
                {
                        window.clear();
                        texture.loadFromFile("PokeSprites.png", IntRect(1,1,32,32));
                        Charmander.setTexture(texture);
                        step = 1;
                        TIMER.restart();
                        window.draw(Charmander);
                        window.display();

                }
                if (t1 >= t2)
                {
                        window.clear();
                        texture.loadFromFile("PokeSprites.png", IntRect(0,32,32,32));
                        Charmander.setTexture(texture);
                        step = 0;
                        TIMER.restart();
                        window.draw(Charmander);
                        window.display();
                }
    }

    return 0;
}
 

5
General / My window will only stay open for a second.
« on: November 12, 2012, 06:08:37 am »
I am very new to the SFML libraries, I have been reading through the tutorials and decided to play around with it to see how it worked. Everything was working fantastically! I fixed my linker issues, Everything was running smoothly...

Until I Cleared the screen and drew a shape.
After I put in those two instructions the window now only stays open for a second then closes.

I am using SFML 1.6 with Windows Visual C++ 2008 Express edition.

Here is the code

#include "stdafx.h"
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
using namespace sf;
using namespace std;

int main(){


RenderWindow App(VideoMode(800,600,32), "Tutorial");
Shape rect = Shape::Rectangle (0, 0, 10, 10, Color::Red);
int NumberLoops = 0;
while(true) {
Event handle;

while(App.GetEvent(handle))
{
       

       
        cout << "Next loop has been made, It has looped" << NumberLoops << "times";
        NumberLoops++;
        cout << endl;
        if(handle.Key.Code == Key::Back || handle.Type == Event::Closed) {
                App.Close();
        cout << "Window closed";
        cout << endl;
        }
        if(handle.Type == Event::MouseButtonPressed) {
                cout << "Mouse button pressed?";
                cout << endl;
        }
       
        if(handle.Type == Event::MouseButtonReleased) {
                cout << "Mouse button released";
                cout << endl;
        }
}
App.Clear();
App.Draw(rect);
App.Display();
}


return EXIT_SUCCESS;
}

If I get rid of App.Clear(); and App.Draw(rect); It will run fine without closing, But apparently those two members of the RenderWindow class doesn't like my IDE very much.

Where have I gone wrong?

If it helps anything, this is what it says on the debug window when it closes.

STATUS_STACK_BUFFER_OVERRUN encountered
The thread 'Win32 Thread' (0x1e94) has exited with code -1073740791 (0xc0000409).
The thread 'Win32 Thread' (0x1f08) has exited with code -1073740791 (0xc0000409).
The thread 'Win32 Thread' (0x1e68) has exited with code -1073740791 (0xc0000409).
The thread 'Win32 Thread' (0xec) has exited with code -1073740791 (0xc0000409).
The program '[7824] Testing_sfml.exe: Managed' has exited with code -1073740791 (0xc0000409).
The program '[7824] Testing_sfml.exe: Native' has exited with code -1073740791 (0xc0000409).
 

6
General / Re: Why can't I compile this? What are these errors?
« on: October 26, 2012, 11:31:59 am »
Please read the tutorial carefully. Look at the screenshots.
I found my solution, for some odd reason I was putting .dll instead of .lib

Thank you so much for being patient with me and showing me where I needed to be. :)

7
General / Re: Why can't I compile this? What are these errors?
« on: October 26, 2012, 08:54:00 am »
It is explained in the "Getting started" tutorial.

Alright cool, So I went into additional dependencies and put in  sfml-graphics; sfml-window

But when I tried to run it, it gave me this fatal error.

1>LINK : fatal error LNK1104: cannot open file 'sfml-graphics;.obj'

8
General / Re: Why can't I compile this? What are these errors?
« on: October 26, 2012, 08:38:08 am »
You must link to sfml-graphics and sfml-window.

Oh thank you! A reply :)

How do I link? D:

9
General / Why can't I compile this? What are these errors?
« on: October 26, 2012, 05:10:42 am »
I am using Micrsoft visual studios C++ 2008

I opened a C++ console window after installing and following all the directions for install and including all the libraries for the project.

This is the code

#include "stdafx.h"


#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <iostream>


int main() {

        sf::RenderWindow Game(sf::VideoMode (800, 600, 32), "SFML window test" );
                sf::Event Event;
                while(Game.IsOpened())
                {
                        while(Game.GetEvent(Event)) {

                                if ( Event.Type == sf::Event::Closed)
                                        Game.Close();

                        }
                        Game.Clear();

                        Game.Display();

                }
        return EXIT_SUCCESS;
}


 


And here are the errors

1>Linking...
1>Testing_sfml.obj : error LNK2028: unresolved token (0A0003A9) "public: void __thiscall sf::Window::Display(void)" (?Display@Window@sf@@$$FQAEXXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Testing_sfml.obj : error LNK2028: unresolved token (0A0003AA) "public: __thiscall sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (??0Color@sf@@$$FQAE@EEEE@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Testing_sfml.obj : error LNK2028: unresolved token (0A0003AB) "public: void __thiscall sf::RenderTarget::Clear(class sf::Color const &)" (?Clear@RenderTarget@sf@@$$FQAEXABVColor@2@@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Testing_sfml.obj : error LNK2028: unresolved token (0A0003AC) "public: void __thiscall sf::Window::Close(void)" (?Close@Window@sf@@$$FQAEXXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Testing_sfml.obj : error LNK2028: unresolved token (0A0003AD) "public: bool __thiscall sf::Window::GetEvent(class sf::Event &)" (?GetEvent@Window@sf@@$$FQAE_NAAVEvent@2@@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Testing_sfml.obj : error LNK2028: unresolved token (0A0003AE) "public: bool __thiscall sf::Window::IsOpened(void)const " (?IsOpened@Window@sf@@$$FQBE_NXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Testing_sfml.obj : error LNK2028: unresolved token (0A0003AF) "public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)" (??1RenderWindow@sf@@$$FUAE@XZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Testing_sfml.obj : error LNK2028: unresolved token (0A0003B0) "public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (??0VideoMode@sf@@$$FQAE@III@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Testing_sfml.obj : error LNK2028: unresolved token (0A0003B1) "public: __thiscall sf::RenderWindow::RenderWindow(class sf::VideoMode,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned long,struct sf::WindowSettings const &)" (??0RenderWindow@sf@@$$FQAE@VVideoMode@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@KABUWindowSettings@1@@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Testing_sfml.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)" (??1RenderWindow@sf@@$$FUAE@XZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Testing_sfml.obj : error LNK2019: unresolved external symbol "public: void __thiscall sf::Window::Display(void)" (?Display@Window@sf@@$$FQAEXXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Testing_sfml.obj : error LNK2019: unresolved external symbol "public: void __thiscall sf::RenderTarget::Clear(class sf::Color const &)" (?Clear@RenderTarget@sf@@$$FQAEXABVColor@2@@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Testing_sfml.obj : error LNK2019: unresolved external symbol "public: __thiscall sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (??0Color@sf@@$$FQAE@EEEE@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Testing_sfml.obj : error LNK2019: unresolved external symbol "public: void __thiscall sf::Window::Close(void)" (?Close@Window@sf@@$$FQAEXXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Testing_sfml.obj : error LNK2019: unresolved external symbol "public: bool __thiscall sf::Window::GetEvent(class sf::Event &)" (?GetEvent@Window@sf@@$$FQAE_NAAVEvent@2@@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Testing_sfml.obj : error LNK2019: unresolved external symbol "public: bool __thiscall sf::Window::IsOpened(void)const " (?IsOpened@Window@sf@@$$FQBE_NXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Testing_sfml.obj : error LNK2019: unresolved external symbol "public: __thiscall sf::RenderWindow::RenderWindow(class sf::VideoMode,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned long,struct sf::WindowSettings const &)" (??0RenderWindow@sf@@$$FQAE@VVideoMode@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@KABUWindowSettings@1@@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Testing_sfml.obj : error LNK2019: unresolved external symbol "public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (??0VideoMode@sf@@$$FQAE@III@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>C:\Users\michalan\Documents\Visual Studio 2008\Projects\Testing_sfml\Debug\Testing_sfml.exe : fatal error LNK1120: 18 unresolved externals

Pages: [1]