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

Pages: [1]
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?..

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:
&& 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) {
    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!

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:
            // Check if the window is closed:
            sf::Event event;

                if(event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))

            // 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:

            // 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);

            // Show the screen:

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:


Any help?

Pages: [1]