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

Pages: [1] 2
1
General / [Tutorial] - Building SFML2 + Thor2 in VS2010
« on: August 07, 2012, 09:22:17 pm »
Hi a mate of mine wanted help getting sfml2 and thor to compile... so I made him this video... not sure if it is the "best" way but it works for me

http://www.youtube.com/playlist?list=PL4375CFE3936CE63A&feature=view_all

2
Is there a way to tell witch animation is currently playing? I know there is a way to tell if an animation is playing, but is there a way to return the string key of the currently playing animation? Or something like that...

so you could do something like...

if (anim.whatsplaying() == "anim1")
{
// Do something that is unique to when this animation is playing.
}

3
General / Collisions Fail at higher speed....
« on: July 21, 2012, 04:28:34 am »
I'm using a bunch of collision tests. Everything works great.. but if I am going to fast then the collisions simply fail and nothing happens. I am trying to make a pacman clone so I would like pac-man to move pretty fast by the end of a long game.

  • Pac-Man is moving though a factor = velocity * frametime;
  • I am using SFML rectangles to do the tests... eg...sf::FloatRect.contains(pacman.getPostion); This tests a point in space to see if it is inside the rectangle. The point being the centre of pac-man.


So yeah.. I would love to hear any ideas on this!

Thanks in advance

Example of Collision as it is now...

 if ( _rectSwitch.getGlobalBounds().contains( PacMan.getPosition().x, PacMan.getPosition().y ) )

4
Graphics / Pixel Perfect Sprite Position checking?
« on: July 20, 2012, 08:51:53 am »
I am having a problem and I was hoping you guys would have a solution... as I am kinda stuck.

I have a sprite for the main character that is moving around the screen using a velocity and frame time to make a factor to adjust the sprite position. This is a float value. This means that the getPosition(); will return a float and it could be say 300.6348 300.2894 instead of 300,300 for screen cords.

I had planned to do a test on a single pixel to see if the main character was at that pixel. Though I can not get it to work as the sprite seams to just pass directly over it with out trigging the reaction.  I think this is because  the get position of get top/left for the "switch" is a whole number but the testing numbers for the sprite that is moving is in fractions.

I tried using ciel and floor to round the values.. but no real luck there either..

here is what I am trying to do...



Now the coloured squares would not be visible in the end but for now the "switches" can be seen. The idea was for the centre point of each square to test if the pacman centre point is in the same position, and if so do something. Pac-Man and the rects have the transform set to the centre.

I thought this would be trivial with some code something like this....

if (_switch.getPosition() == PacMan.getPosition()
{
//do somthing
}

but it just doesn't seam to work and I am not sure why or how to fix it... Any ideas?

// - - //
Some more info

Each Switch is 40,40px and PacMan is 40x40px. The main idea of this test was so that pacman can not change direction unless he is completely inside the switch. I can test is a point is in the switch or is a edge of pacmans bounding box hits the switch.. but I am unsure about how to do the center === center test if it is possible at all.

5
I am getting a crash in my game and the console is getting this message printed in it..


Code: [Select]
Assertion failed: progress >= 0.f && progress <= 1.f, file h:\nom!\_xternlibs\sfml2\include\thor\animation\frameanimation.hpp, line 115
The strange thing is the crash only happens sometimes. If I compile, it will run, and then I run it a few times and suddenly it will crash with this error, with no code change at all. If I compile a release version, same thing happens, I can just sit there running the exe, and 1/2 the time it works.. the other 1/2 it crashes.

Anyideas?

Here is my code if it helps.

#include "goPac.h"

goPac::goPac()
        : _nextDirection(STOPPED)
        , _velocity(10.0f)
        , _maxVelocity(100.0f)
{
        _PACsprite.setTexture(*TextureManager::getInstance().rSpriteSheet());


        thor::FrameAnimation defaultAnim;
        defaultAnim.addFrame(1.f, sf::IntRect(40, 80, 40, 40));

        // Create animation: CHOMP
        thor::FrameAnimation chomp;
        chomp.addFrame(1.f, sf::IntRect(120, 80, 40, 40));
        chomp.addFrame(1.5f, sf::IntRect(160, 80, 40, 40));
        chomp.addFrame(1.f, sf::IntRect(120, 80, 40, 40));
        chomp.addFrame(2.f, sf::IntRect(40, 80, 40, 40));

        animPac.setDefaultAnimation(defaultAnim, sf::seconds(1.f));
        animPac.addAnimation("chomp", chomp, sf::seconds(0.4f));
}

goPac::~goPac()
{
}

void goPac::Update(sf::RenderWindow& rw, sf::Event& _event, float TimeElapsed)
{
        rw.pollEvent(_event);
        rw.setKeyRepeatEnabled(false);


        if (_event.type == sf::Event::KeyPressed)
        {
                if (_event.key.code == sf::Keyboard::Up || _event.key.code == sf::Keyboard::W || _event.key.code == sf::Keyboard::Num8)
                {
                        debug("UP");
                        playAnimation();

                }

                if (_event.key.code == sf::Keyboard::Left || _event.key.code == sf::Keyboard::A || _event.key.code == sf::Keyboard::Num4)
                {
                        debug("LEFT");
                }

                if (_event.key.code == sf::Keyboard::Right || _event.key.code == sf::Keyboard::D || _event.key.code == sf::Keyboard::Num6)
                {
                        debug("RIGHT");
                }

                if (_event.key.code == sf::Keyboard::Down || _event.key.code == sf::Keyboard::S || _event.key.code == sf::Keyboard::Num2)
                {
                        debug("DOWN");
                }

        }

        animPac.update(animClock.restart());
        animPac.animate(_PACsprite);
}

void goPac::playAnimation()
{
        debug("playAnimation();");
        animPac.update(animClock.restart());
        animPac.playAnimation("chomp", true);
}

void goPac::Draw(sf::RenderWindow& rw)
{
        rw.draw(_PACsprite);
}


6
General / Problems compiling an release SFML2 application on linux
« on: July 04, 2012, 01:35:24 am »
Hi I am trying to compile on linux, (ubuntu) but I am having a problem with static linking. I would like to static link as there isn't a sfml2 pack out people can easily install. Everything compiles fine normally, but if I add the -s to the linker then it all goes haywire.

log - http://ctrlv.it/id/MzAwMzky



Maybe static isn't the way to go? But if I remove the -s and the #define it will now compile fine and even play, like in code::blocks when i press the build/run button... the application runs... but then if i go to the file itself.. as in the one I would post and send to people to use, it will not run?



7
General / Simple Collision Detection -> SFML2
« on: June 25, 2012, 04:49:31 am »
ON the wikie is a cool collision tester
https://github.com/SFML/SFML/wiki/SourceSimpleCollisionDetection

but it is not SFML2.. I went to try and update it but some of teh function are not in sfml2 as far as I know.. like "TransformToGlobal" ... is there ea version of that under a new name in sfml2?

TransformToGlobal
GetSize

Dose anyone know the sfml2 alternative to these?

Dose anyone have this code updated for SFML2?

Thanks in advance


8
Hi there, I have some code to move an object in sync to the mouse moment in X... I am using getPostion(rw); but I was wondering if this is the best way to do it.. my application seams to be having a slight strobie look to it.. and I was wondering if this can be fixed.. maybe my methods is not a good solution.

I am passing a float for time, but as of yet it is not getting used.. and the frame rate of the window is set to 60.

void goArkanoid::Update(sf::RenderWindow& rw, float TimeElapsed)
{
        sf::Vector2f CurrentMousePos((float)sf::Mouse::getPosition(rw).x, 671);
        sf::Event event;
        rw.pollEvent(event);
       
        if (event.type == sf::Event::MouseMoved)
        {

                if (GetPosition().x < sf::Mouse::getPosition(rw).x)
                {
                        GameObject::SetTile(RIGHT);
                }

                if (GetPosition().x > sf::Mouse::getPosition(rw).x)
                {
                        GameObject::SetTile(LEFT);
                }

                GameObject::SetPosition(CurrentMousePos);
                std::cout<<"xM = "<<CurrentMousePos.x<<"\n"<<" "<<sf::Mouse::getPosition().x<<"\n\n";
        }

        if (GetPosition().x == sf::Mouse::getPosition(rw).x)
        {
                GameObject::SetTile(STOPPED);
        }
}

9
Is there a way in Thor to add a sound event to a given frame of an animation?

10
I have this code snipit... and this is working fine.. like you press the Q button the animation plays.. but I thought I would be able to use it in the do{}while() loop to make it autoplay before any pollevents are checked.

This animation is for a logo tumble at the start of the game.

Any ideas?

void SplashScreen::Show(sf::RenderWindow& rw){

        _sprite.setTexture(*TextureManager::getInstance().rSplashScreen());
        _sprite.setTextureRect(sf::IntRect(0,0,844,514)); //Screen
        _sprite.setPosition(220,23);

        initAnimation();
/*
                do{
                        std::cout<<"Animation Tester\n";
                        animSign.playAnimation("FaSign");
                        animSign.update(frameClock.restart());
                        animSign.animate(_Sign);
                        rw.draw(_Sign);
                        rw.display();
                }while(animSign.isPlayingAnimation());*/



        sf::Event eventSplash;
        while(true)
        {
                while(rw.pollEvent(eventSplash))
                {
                        if ((eventSplash.type == sf::Event::KeyPressed) && (eventSplash.key.code == sf::Keyboard::Q))
                        {
                                animSign.playAnimation("FaSign");
                        }                      
                }
                animSign.update(frameClock.restart());
                animSign.animate(_Sign);
                rw.draw(_Sign);
                rw.display();
        }
       
}

If I change some of the code to this...

        sf::Event eventSplash;
        while(true)
        {
                while(rw.pollEvent(eventSplash))
                {
                        animSign.playAnimation("FaSign");                    
                }
                animSign.update(frameClock.restart());
                animSign.animate(_Sign);
                rw.draw(_Sign);
                rw.display();
        }

Then it plays fine, but it will play form the start every time I move my mouse inside the window... if I remove the pollevent and place the it in the while loop (what I was trying to do with the do{}while() loop then nothing happens like b4..

        sf::Event eventSplash;
        while(true)
        {
                animSign.playAnimation("FaSign");
                animSign.update(frameClock.restart());
                animSign.animate(_Sign);
                rw.draw(_Sign);
                rw.display();
        }

 

11
Window / [SOLVED] - Measuring Time in SFML2
« on: June 05, 2012, 09:37:33 am »
I can not work out how to measure time in SFML2.. the tutorials 1.6 seam depreciated. I have searched but all i see is a lot of people asking the question and a few solutions that are embedded in complex code.

Any ideas how to re-write in sfml2?

sf::Clock Clock;

while (App.IsOpened())
{
    float Framerate = 1.f / Clock.GetElapsedTime();
    Clock.Reset();
}

// Or :

while (App.IsOpened())
{
    float Framerate = 1.f / App.GetFrameTime();
}


12
Graphics / Strange Event.mouseButton.x / y behaviour?
« on: May 14, 2012, 05:46:10 am »
Hi there...

check this code snipit

sf::Event event;

// Mouse Position tmp Variables
        sf::Vector2i position = sf::Mouse::getPosition(window);

<SNIP A LARGE CHUNK OF CODE>

                        case sf::Event::MouseMoved:

                                position=sf::Mouse::getPosition(window);
                                std::cout<<"Position X = "<<position.x<<" Y = "<<position.y<<std::endl;
                                std::cout<<"mouseButton.x = "<<event.mouseButton.x<<" Y = "<<event.mouseButton.y<<std::endl;
                                std::cout<<"Mouse moved - X: "<<event.mouseMove.x<<" Y: "<<event.mouseMove.y<<std::endl<<std::endl;

                                break;

it is my understanding that event.mouseButton.x returns the current mouse position before the mouse is moved, unlike event.mouseMove.x witch returns the x position of where the mouse was moved to? What is happening though is mouseButton.X is giving me the window cords of the mouse's Y position and the .y is returning junk.

here is a example of what si wrong - http://screencast.com/t/U2JgoqR1e

What I am trying to do is simply make left or right mouse moment to move teh block left or right, but not have it relative to mouse position, so it is just testing that the mouse moved left or right, not to were it is pointing at all. The plan was to have a tmp variable for the current mouse position in X only, then if the mouse moves say 34 pixles left register that as a single left moment and move the block, then reset the tmp variable to this new spot.

13
I do not get how to load a image into a sprite...

        sf::Image iBackgrnd;
        if (!iBackgrnd.loadFromFile("board.png"))
                return EXIT_FAILURE;
        sf::Sprite backgrnd;
//      backgrnd.setImage(iBackgrnd); // - No longer works.... what do I do here instead?

Like this works...

        sf::Texture iBackgrnd;
        if (!iBackgrnd.loadFromFile("board.png"))
                return EXIT_FAILURE;
        sf::Sprite backgrnd;
        backgrnd.setTexture(iBackgrnd);

butthen.. what is Image used for? and how... the documentation says they are diffrent.. but I am not sure i understand how image is used now

14
General / [SOLVED] - xCode 4 - Templates?? Now showing up?
« on: May 11, 2012, 12:18:44 am »
I can not seam to find the templates.

I built SFML2 form the snapshot using cmake and everything seamed to go fine... but I can not seam to see the sfml templates.... I go "New Project" like in the tutorial but I do not see any SFML templates...

Is there a way I can simple add them to Xcode?

15
General / [SOLVED] - OSX Lion + Cmake / SFML2
« on: May 10, 2012, 03:06:29 pm »
I have SFML2-Snapshot and cmake working fine in windows and ubuntu, now I want to get the dev environment working on the mac as well.. but I can not seam to get the cmake to work. I am new to mac, so bear with me.

I installed xcode from the app market, then I installed cmake from the cmake website though the downloadable mac binary link on its download page. In a terminal I can run cmake fine so it seams to be working...

When I run with cmake -i i get this error....
Code: [Select]
cmake -i
Would you like to see advanced options? [No]:
Please wait while cmake processes CMakeLists.txt files....

CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file:/Users/itisme/Development/_cMake/SFML2-Snap/CMakeFiles/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file:/Users/itisme/Development/_cMake/SFML2-Snap/CMakeFiles/CMakeCXXCompiler.cmake
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage

I also tried cmake -G "MakeFile" -i and cmake -G "Unix Makefiles"

I also tried the gui...


I know there is a basic error in my dev environment somewhere.. any idea where?

Pages: [1] 2
anything