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

Pages: [1]
1
Graphics / Re: Multiple colours in a single string?
« on: February 26, 2013, 04:28:50 am »
So I finally got around to using this. It works well, though you have to set stuff in a certain order (you can't set the font, character size outside of your loop, you should do it directly after setting the string), and I really can't find any way to add new lines.

EDIT: I searched and found an old thread relating to this, but all that was suggested was that they use an STL container to get around the \n issue. Not really sure how I'd go about doing that.

2
System / Re: Elegant way to check if mouse position is within a rectangle?
« on: February 19, 2013, 02:29:25 am »
Ah yes, I have that function. I should probably update SFML.

So I got it working correctly and it's certainly much cleaner than what I originally had. Do I really need to make an sf::FloatRect to pair with any sf::RectangleShape I make if I want it to be clickable though? Would you suggest I make a Clickable class, with sf::Rectangle, sf::FloatRect, sf::Color, sizes etc, so I can use the mouseclick check that I've gained from this thread with it?

Thanks for your help guys.

3
System / Re: Elegant way to check if mouse position is within a rectangle?
« on: February 18, 2013, 10:18:34 pm »
Am I being simple here by not seeing that Window/RenderWindow function in the documentation listings?..

4
Graphics / Re: Multiple colours in a single string?
« on: February 18, 2013, 05:22:32 pm »
That looks perfect but I'm new to this, how do I 'install' it? Do I just download the .h and .cpp then include in my program?

5
Graphics / Multiple colours in a single string?
« on: February 18, 2013, 05:03:34 pm »
Is something like this possible using text.setString()? Or do I have to make multiple sf::Text variables then just draw them one after the other?..

6
You can get or create the sf::Rect of the stat thingy and call rect.contains(static_cast<sf::FloatRect>(sf::Mouse::getPosition(window)))

Actually I just tried this and I can't get it to work properly.

        // Create tooltip:
        sf::RectangleShape ttBox;
        ttBox.setSize(120.f, 120.f);
        ttBox.setFillColor(sf::Color(0, 0, 0, 175));
        sf::FloatRect ttBoxRect(ttBox.getPosition().x, ttBox.getPosition().y, ttBox.getSize().x, ttBox.getSize().y);
       
        // ...

            if(sf::Mouse::isButtonPressed(sf::Mouse::Right)
            && ttBoxRect.contains(static_cast<sf::FloatRect>(sf::Mouse::getPosition(Screen)))) {
                ttBox.setPosition(sf::Vector2f(sf::Mouse::getPosition(Screen)));
                ttTitle.setPosition(sf::Vector2f(ttBox.getPosition().x + 10.f, ttBox.getPosition().y + -.5f));
                ttTitle.setString("The Tooltip");
                drawTooltip = true;
            }

error: no matching function for call to 'sf::Rect<float>::Rect(sf::Vector2i)'|

7
System / Re: Elegant way to check if mouse position is within a rectangle?
« on: February 17, 2013, 04:15:05 am »
I knew there'd be an easier way to do it, thanks for the help. I should be good from here.

8
System / Elegant way to check if mouse position is within a rectangle?
« on: February 16, 2013, 04:15:08 am »
I'm trying to make right-click tooltip menus for my game and they work just fine, but the way it's implemented seems a bit messy.

// Right click inside of a rect:
if(sf::Mouse::isButtonPressed(sf::Mouse::Right)
&& sf::Mouse::getPosition(Screen).x >= statBox.getPosition().x
&& sf::Mouse::getPosition(Screen).x <= statBox.getPosition().x + statBox.getSize().x
&& sf::Mouse::getPosition(Screen).y >= statBox.getPosition().y
&& sf::Mouse::getPosition(Screen).y <= statBox.getPosition().y + statBox.getSize().y) {
    ttBox.setPosition(sf::Vector2f(sf::Mouse::getPosition(Screen)));
    ttTitle.setPosition(sf::Vector2f(ttBox.getPosition().x + 10.f, ttBox.getPosition().y + -.5f));
    ttTitle.setString("The Tooltip");
    drawTooltip = true;
}

Like I said this works but it isn't ideal. Isn't there a way to do "if object is hovered" or "if object is clicked"? My implementation just specifies a position on the screen equal to the space within corners of the box - it doesn't specifically state that you're clicking in the box if you understand what I'm saying? Sorry if this is confusing, I'll try to explain better if you don't understand.

Thanks in advance guys!

9
That is WAY more work than I would have thought, though your class seems pretty versatile. I'm just trying to get my specific game up and running, I won't be making anything as detailed. I'll to have to look through it for a while though because I don't like using code that I don't fully understand. Thanks for posting it, it'll be useful.

10
I tried messing around with that before, I kinda got somewhere but not completely. I tested with pos.x += moveSpeed; in the game loop, then did if(clock.getElapsedTime() >= duration) moveSpeed = 0;. That made my character move right for a duration (1 second for example) then stop - which is part of what I want. I'm not sure how to trigger that for if you hit a key though. I tried putting a keypress check around it, but then it just didn't move and when I pressed the key it moved like normal - ie didn't automatically move then stop.

As for your suggestion, it didn't effect anything. The section you've wrapped the test around is just for finding the correct area to draw, I think you mean to put it around if(moving) src.x += spritesheet.getSize().x / 4;. It still doesn't limit the animation though. :/

11
I'm new to SFML and I'm wondering how I'd do this.

Right now I have a sprite (spritesheet) which animatesusing IntRect correctly depending on which direction button you press. The character moves in that direction too. However, I have no limit on the animation, so it's incredibly fast. I tried adding sf::sleep which made the sprite animate at a nice speed, but this stopped my character's movement. So one or the other is broken right now, whether I use sleep or not.

My eventual goal is to make Pokémon movement:
- Press right, control is taken from the player
- the sprite moves right one grid space (say 14.f)
- one animation cycle happens during this movement
- the movement takes .5f seconds to elapse

I have no idea how to do this. I'm guessing something either to do with the Clock class or threading the animation and movement separately.

Thanks in advance for you help (:

        // Game Loop:
        while(Screen.isOpen())
        {
            // Check if the window is closed:
            sf::Event event;

            while(Screen.pollEvent(event))
            {
                if(event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
                    Screen.close();
            }

            // Set drawing positions and velocities:
            // - Left and Right:
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
                src.y = sL;
                vel.x = -moveSpeed;
            } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
                src.y = sR;
                vel.x = moveSpeed;
            } else {
                vel.x = 0;
            }
            // - Up and Down:
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
                src.y = sU;
                vel.y = -moveSpeed;
            } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
                src.y = sD;
                vel.y = moveSpeed;
            } else {
                vel.y = 0;
            }

            // Move the player:
            pos.x += vel.x;
            pos.y += vel.y;

            // Animate image:
            if(vel.x != 0 || vel.y != 0) {
                src.x += spritesheet.getSize().x / 4;
                // - No limit in here..
            } else {
                src.x = 0;
            }

            // - reset to the first frame:
            if(src.x == spritesheet.getSize().x)
                src.x = 0;

            // Refresh the screen:
            Screen.clear();

            // Draw and display the player:
            player.setTextureRect(sf::IntRect(src.x, src.y, spritesheet.getSize().x / 4, spritesheet.getSize().y / 4));
            player.setPosition(pos.x, pos.y);
            Screen.draw(player);

            // Show the screen:
            Screen.display();
        }

12
Graphics / Help with getting width of a texture from a sprite (SFML 2.0)
« on: February 08, 2013, 01:43:13 am »
I just started learning SFML 2.0 and have been reading a tutorial, which unfortunately is in 1.6. Anyway, I have an Animation class, which has an sf::Sprite member, and in my int Animation::getFrameWidth() function I'm trying to do this:

return spriteImage.getTexture().getSize().x / amountOfFramesX;

// request for member 'getSize' in '((Animation*)this)->Animation::spriteImage.sf::Sprite::getTexture()', which is of non-class type 'const sf::Texture*'

I've used this in other parts of my program and its worked fine:

someTexture.getSize().x

Any help?

Pages: [1]
anything