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

Pages: 1 [2]
16
Graphics / SFML 2.0 Collision detection
« on: August 27, 2011, 01:06:56 pm »
Hey guys, is there any working collision_detection for SFML 2.0 that you know of? I tried finding it but I can only find some for 1.6 version which aint working on 2.0 unfortunately.

Best regards

17
Graphics / SFML 2.0 Sprite animation
« on: August 26, 2011, 08:18:58 pm »
Hey all,

I am trying to get my sprite to walk left or right. I am using 5 images.

Image 1 = standing still.
Image 2 till 5 are running animations.

What I need to accomplice is:

if no button left or right is pressed display 1.
If left or right is pressed start with 2, then 3, then 4, then 5.
Then go back to 4, then 3, then 2, and now repeat the process. THis way I would have a smooth animation of my character running.

I have been trying it my self for a couple of days now, I also tried some stuff from YouTube today for like 8 hours but I just cant get it to work.

Can someone please write me a example code? or just give me a couple of directions? I dont know either if I should write a class for my character or not. Any information would be highly appreciated!

Ill post my current code down here.

Have a nice weekend!

Yours sincerely,

GZ

P.S. My char is movable (left and right) as you can see, but I have not written the whole setTexture codes yet cause I keep failing at them. I need them in the sequence of 2, 3, 4, 5, 4, 3, 2 and so on...

Currently I wrote a couple when walking left but it does not change the animation. It only uses frame 2 then it gets stuck at frame 1 it seems.


Code: [Select]
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Config.hpp>

// set some globals
char faceDirection = 'L';     // L = Left, R = Right
int minAni = 2;               // Start at picture 2 for the walk animation
int maxAni = 5;               // End at picture 5 for the walk animation
int curAni = 2;               // What animation we start on
char wayAni = 'R';            // What way should we start counting first

int main()
{
    // create a new window 800x600 resolution 32 bit
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "MyTest");


    /////////////////////////////////// SPRITE 1 FRAME 1 //////////////////////
    sf::Image character1;
    character1.LoadFromFile("character_sprites/character_1.png");

    sf::Texture charTexture1;
    charTexture1.LoadFromImage(character1);

    sf::Sprite charSprite1(charTexture1);
    charSprite1.SetPosition(390, 400);

    /////////////////////////////////// SPRITE 1 FRAME 2 //////////////////////
    sf::Image character2;
    character2.LoadFromFile("character_sprites/character_2.png");

    sf::Texture charTexture2;
    charTexture2.LoadFromImage(character2);

    /////////////////////////////////// SPRITE 1 FRAME 3 //////////////////////
    sf::Image character3;
    character3.LoadFromFile("character_sprites/character_3.png");

    sf::Texture charTexture3;
    charTexture3.LoadFromImage(character3);

    /////////////////////////////////// SPRITE 1 FRAME 4 //////////////////////
    sf::Image character4;
    character4.LoadFromFile("character_sprites/character_4.png");

    sf::Texture charTexture4;
    charTexture4.LoadFromImage(character4);

    /////////////////////////////////// SPRITE 1 FRAME 5 //////////////////////
    sf::Image character5;
    character5.LoadFromFile("character_sprites/character_5.png");

    sf::Texture charTexture5;
    charTexture5.LoadFromImage(character5);

    //////////////////////////////////////////////////////////////////////////


    // timers so app runs on the same speed on every machine possible
    sf::Clock clock;        // timer for events
    sf::Clock aniClock;     // timer for character animation

    while( App.IsOpened())
    {
        // events loop
        sf::Event Event;
        while (App.PollEvent(Event))
        {
            switch(Event.Type)
            {
                // if screen is closed
                case sf::Event::Closed:
                    App.Close();
                break;
            }

        } // end events

        // move the character at a rate of 33 ms per second
        if(clock.GetElapsedTime() >= 33)
        {
            if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Left))
            {
                charSprite1.Move( -2, 0 );
            }

            if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Right))
            {
                charSprite1.Move( 2, 0 );
            }

            // reset the clock for the event timer
            clock.Reset();
        }



        if(aniClock.GetElapsedTime() >= 100)
        {

            if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Left))
            {
                // check if facing the opposit side then flip
                if( faceDirection == 'R')
                    charSprite1.FlipX(false);

                // set the direction we are facing
                faceDirection = 'L';

                // set to frame 2
                if( curAni <= 2 && wayAni == 'R')
                    charSprite1.SetTexture(charTexture2);
                curAni++;

                // set to frame 3
                if( curAni <= 3 && wayAni == 'R')
                    charSprite1.SetTexture(charTexture3);
                curAni++;

                // set to frame 4
                if( curAni <= 4 && wayAni == 'R')
                    charSprite1.SetTexture(charTexture4);
                curAni++;

                // set to frame 5 and set the wayAni in the opposite way
                if( curAni <= 5 && wayAni == 'R')
                    charSprite1.SetTexture(charTexture5);
                curAni++;
                wayAni = 'L';

            }
            else if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Right))
            {
                // check if facing the opposit side then flip
                if( faceDirection == 'L')
                    charSprite1.FlipX(true);

                // set the direction we are facing
                faceDirection = 'R';
            }
            else
            {
                // we are not moving, set the sprite back to animation 1
                charSprite1.SetTexture(charTexture1);
            }

            aniClock.Reset();

        }




        // clear the screen
        App.Clear();

        // draw the sprite
        App.Draw(charSprite1);

        // display the window with the new stuff
        App.Display();

    } // end while App is opened

    return EXIT_SUCCESS;
}

18
General / Install on Mac OS X, and newest xcode
« on: August 25, 2011, 03:18:55 pm »
Dear reader,

I have used CMAKE to extract the files, then did a SUDO MAKE INSTALL. It gave some errors but that seems normal according to Google.

I THINK, it installed some files to two directories i.e. LIBRARY and USR directory.

I do not know what folders or files it are. But when I start Xcode I still cannot find the SFML icon in the project list when creating a new project.

Could someone tell me what folders / files to copy, and to where?

Yours truly,

GZ

19
General / Cant find lots of stuff in 2.0
« on: August 22, 2011, 11:22:53 pm »
Good evening all,

I am having trouble finding some stuff. for example:

http://www.sfml-dev.org/documentation/2.0/classsf_1_1Sound.php#details

I am using their code but nothing.

When I type sf::

i see a list of stuff I can use, but no "sound" or "music" in there.
Exactly the same for the sprite part.

I used the code given on the website to draw a block (black) but nothing.

Code: [Select]
// Create a 20x20 image filled with black color
 sf::Image image;
 if (!image.Create(20, 20, sf::Color::Black))
     return -1;


Does anyone have any idea?

My code:

Code: [Select]
#include <SFML/Window.hpp>

int main()
{
    // create a new window 800x600 resolution 32 bit
    sf::Window App(sf::VideoMode(800, 600, 32), "Zombie Madnezz");

    // disable vertical synchronization for max framerate
    App.EnableVerticalSync(false);

    // attach the GetInput function to our window
    //const sf::Input& Input = App.GetInput();

    // as long as this window is running
    while( App.IsOpened())
    {
        sf::Event Event;
        while (App.PollEvent(Event))
        {
            // if user closes the window stop running the program
            if(Event.Type == sf::Event::Closed)
            {
                App.Close();
            }

            // if user presses ESC button stop running the program
            if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Escape))
            {
                App.Close();
            }

            // set the objects for keyboard and mouse input
            bool LeftKeyDown  = sf::Keyboard::IsKeyPressed(sf::Keyboard::Left);            // left arrow key
            bool RightKeyDown = sf::Keyboard::IsKeyPressed(sf::Keyboard::Right);           // right array key
            bool SpacebarDown = sf::Keyboard::IsKeyPressed(sf::Keyboard::Space);           // spacebar

            bool LeftMouseButton = sf::Mouse::IsButtonPressed(sf::Mouse::Left);            // left mouse button
            bool RightMouseButton = sf::Mouse::IsButtonPressed(sf::Mouse::Right);          // right mouse button

            //unsigned int MouseCoordsX = Input.GetMouseX();                                 // mouse position x-as
            //unsigned int MouseCoordsY = Input.GetMouseY();                                 // mouse position y-as

            // configure some character settings
            const float Speed = 50.f;
            float Left      = 0.f;                                                         // only left and top are needed as we can
            float Top       = 0.f;                                                         // calculate all with those three numbers

            /*  CHECK OUT THIS PART WITH CLOCK FUNCTION TO HAVE THE SAME TIMING
                ON EVERY HARDWARE COMPUTER                                       */
            ///////////////////////////////////////////////////////////////////////
            // http://www.sfml-dev.org/tutorials/1.6/window-time.php

            // execute a action according to the boolean (keyboard)
            if ( LeftKeyDown == true )  Left -= Speed;
            if ( RightKeyDown == true )  Left += Speed;

        } // checks for events with PollEvent

        //##############################
        // Create a sprite and add music, but aint workin
        ///////////////////////////////////////////////////////////////////////
        // http://www.sfml-dev.org/tutorials/1.6/graphics-sprite.php



        // display the window
        App.Display();

    } // end while app is opened

    return EXIT_SUCCESS;
}


my .pro file:

Code: [Select]
#-------------------------------------------------
#
# Project created by QtCreator 2011-08-22T17:53:13
#
#-------------------------------------------------

QT       += core gui

TARGET = game
TEMPLATE = app


SOURCES += main.cpp

HEADERS  +=

FORMS    +=

LIBS += -L"C:\Program Files (x86)\SFML\lib" -lsfml-window -lsfml-graphics -sfml-system -sfml-main -sfml-audio

INCLUDEPATH = "C:\Program Files (x86)\SFML\include"

20
Window / Input not declared
« on: August 22, 2011, 08:06:47 pm »
Hello guys,

I am following the tutorials on the website but I keep getting multiple errors.
I have been trying for ages to fix it but without any luck. I hope someone can help me out.

My code so far:

Code: [Select]
#include <SFML/Window.hpp>

int main()
{
    // create a new window 800x600 resolution 32 bit
    sf::Window App(sf::VideoMode(800, 600, 32), "Zombie Madnezz");

    // attach the GetInput function to our window
    const sf::Input& Input = App.GetInput();

    // as long as this window is running
    while( App.IsOpened())
    {
        sf::Event Event;
        while (App.PollEvent(Event))
        {
            // if user closes the window stop running the program
            if(Event.Type == sf::Event::Closed)
            {
                App.Close();
            }

            // if user presses ESC button stop running the program
            if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Escape))
            {
                App.Close();
            }

            // set the objects for keyboard and mouse input
            bool LeftKeyDown  = Input.IsKeyDown(sf::Keyboard::Left);            // left arrow key
            bool RightKeyDown = Input.IsKeyDown(sf::Keyboard::Right);           // right array key
            bool SpacebarDown = Input.IsKeyDown(sf::Keyboard::Space);           // spacebar

            bool LeftMouseButton = Input.IsMouseButtonDown(sf::Mouse::Left);    // left mouse button
            bool RightMouseButton = Input.IsMouseButtonDown(sf::Mouse::Right);  // right mouse button

            unsigned int MouseCoordsX = Input.GetMouseX();                      // mouse position x-as
            unsigned int MouseCoordsY = Input.GetMouseY();                      // mouse position y-as

            // configure some character settings
            const float Speed = 50.f;
            float Left      = 0.f;                                              // only left and top are needed as we can
            float Top       = 0.f;                                              // calculate all with those three numbers

            // check if a key is pressed
            sf::Clock Clock;

            while (App.IsOpened())
            {
                float ElapsedTime = Clock.GetElapsedTime();
                Clock.Reset();

                if (App.GetInput().IsKeyDown(sf::Keyboard::Left))  Left -= Speed * ElapsedTime;
                if (App.GetInput().IsKeyDown(sf::Keyboard::Right)) Left += Speed * ElapsedTime;
                if (App.GetInput().IsKeyDown(sf::Keyboard::Up)) Top += Speed * ElapsedTime;
                if (App.GetInput().IsKeyDown(sf::Keyboard::Down)) Top -= Speed * ElapsedTime;
            }

        }

        // display the window
        App.Display();
    }

    return EXIT_SUCCESS;
}


My pro file:

Code: [Select]
#-------------------------------------------------
#
# Project created by QtCreator 2011-08-22T17:53:13
#
#-------------------------------------------------

QT       += core gui

TARGET = game
TEMPLATE = app


SOURCES += main.cpp

HEADERS  +=

FORMS    +=

LIBS += -L"C:\Program Files (x86)\SFML\lib" -lsfml-window -lsfml-graphics -sfml-system -sfml-main -sfml-audio

INCLUDEPATH = "C:\Program Files (x86)\SFML\include"


The error I get:

C:\Users\Ground Zero\Desktop\C++\leren\GAME\game-build-desktop\..\game\main.cpp:9: error: expected initializer before '&' token

C:\Users\Ground Zero\Desktop\C++\leren\GAME\game-build-desktop\..\game\main.cpp:30: error: 'Input' was not declared in this scope

C:\Users\Ground Zero\Desktop\C++\leren\GAME\game-build-desktop\..\game\main.cpp:53: error: 'class sf::Window' has no member named 'GetInput'

I have been following the tutorial of version 1.6. I am using version 2.0 though. I am on a Windows 7 Prof. machine with Qt Creator (newest version).

Hopefully someone can help me out.

Yours sincerely,


GZ

Pages: 1 [2]