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

Pages: 1 2 [3] 4 5 6
31
are you meant to have a single event for the entire window.. or lots of events all over the place? I have changed the code now that a reference to the window event is sent into all function and nothing seamed to change apart form there is no event in a loop anymore.

Um I am just fooling about with the moment class for my objects, this is the mouse movement part.. but I am also doing a free moving one , and I have see ncode that uses some kind of mathematics based on time to get a velocity.. but I am not sure I understand it

32
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);
        }
}

33
yes that is exactly what I'm asking if possible .

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

35
Graphics / Re: [THOR2] - Questions about the animation class.
« on: June 22, 2012, 07:49:23 pm »
For now I just removed the default animation completely... then everything worked as planned.. It also had the bonus of pausing the animation on the last from... witch was nice...


anyway if you like you can check out my test animation demo thing @ MediaFire

36
Graphics / Re: [THOR2] - Questions about the animation class.
« on: June 22, 2012, 04:59:12 pm »
I think this must be the Thor lib itself as it seams like the isPlayingAnimation() is returning 1 no matter what even in the demo provided?

<--- EDIT

if you just add
std::cout<<animator.isPlayingAnimation()<<"\n";

To the example "Animation.cpp" that comes with Thor at the base of the while poll event.. ... then as you move your mouse about even though you are not playing any animations.. it still reports 1 :(

37
Graphics / Re: [THOR2] - Questions about the animation class.
« on: June 22, 2012, 04:45:59 pm »
I kinda got it to work.. seamed there was a problem with my initialisation functions.. once i moved all the animation init stuff (as in .addFrame etc etc) then it works as expected... ALMOST :) heh heh

        animSign.playAnimation("FaSign");
        for (;;)
        {
                // Update animator and apply current animation state to the sprite
                animSign.update(frameClock.restart());
                animSign.animate(_sign);

                // Draw everything
                rw.clear(sf::Color(50, 50, 50));
                rw.draw(_sign);
                rw.display();

                std::cout<<animSign.isPlayingAnimation()<<"\n";
        }
        std::cout<<"Out of loop\n";

This will now work.. BUT the animSign.isPlayingAnimation() is always returning 1... it is never switching to false and reporting the animation as stopped playing.

38
Graphics / Re: [THOR2] - Questions about the animation class.
« on: June 22, 2012, 04:22:28 pm »
I kind of have it working by copying the code directly from the example file and modding it a bit...

        animSign.playAnimation("FaSign", true);
        for (;;)
        {

                // Handle events
                sf::Event eventSplash;
                while (rw.pollEvent(eventSplash))
                {
                        if (eventSplash.type == sf::Event::KeyPressed)
                        {
                                // stuff would go in here
                        }
                        else if (eventSplash.type == sf::Event::Closed)
                        {
                                // stuff would go here
                        }
                }

                // Update animator and apply current animation state to the sprite
                animSign.update(frameClock.restart());
                animSign.animate(_Sign);

                // Draw everything
                rw.clear(sf::Color::Black);
                rw.draw(_Sign);
                rw.display();
        }

Now this works fine.... but if I change the play animation thing to ...

        animSign.playAnimation("FaSign", false);

// or

        animSign.playAnimation("FaSign");

then it is stuck at the 1st frame again.... so unless you want an infinity animation loop.. .? ?

39
Graphics / Re: [THOR2] - Questions about the animation class.
« on: June 22, 2012, 03:54:50 pm »
yes, that is exactly what is happening.. as in it is stuck on teh first frame.. but your code dose not seam to help unfortunately :(

40
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();
        }

 

41
Window / Re: Mesuring Time in SFML2
« on: June 05, 2012, 11:53:40 am »
Quote
the tutorials 1.6 seam depreciated
So look at the 2.0 tutorials ;)

lol.. I swear I looked at them like a few days ago :).. thanks L-man! Can not wait for the rest.

42
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();
}


43
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.

44
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

45
is this happening when running from inside VS? try building a release build and running from explorer.. you might find it runs fine. I forget where ... but i saw a post that said there was a bug that caused a crash as the program closed when running from the run command in VS...

The fix as I understand it is to use a custom font rather than the default one... anyway that worked for me when i tried to make a corss project in xciode code::blocks(ubuntu) and Vs2010... in vs2010 the exact same code would crash... simply changed it to laod a custom font and it worked...

Pages: 1 2 [3] 4 5 6