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

Pages: [1]
1
Graphics / Conceptualizing "Ghosting" Sprite Movement
« on: August 29, 2014, 07:58:11 pm »
I have an animated sprite of a walking character.  I would like to achieve something similar to Castlevania:SoTN's "ghosting" effect, seen in this gif when the character is falling:

and in this image (to a lesser extent):


I'm thinking of handling it by:
1) drawing the sprite to a rendertexture.  Successive frames would then
2) offset the sprite by whatever camera movement has taken place,
3) doing a color/alpha pass on the existing "ghosted" render texture,
4) rendering the current sprite in it's normal position, and repeating.

Am I overthinking this and should just use a collection of sf::Sprites along with some setColor's, or is the gpu be the best way to go?

2
Graphics / sf::VertexArray: Help Generating Verticies of This Object
« on: August 09, 2014, 02:06:55 am »
I'm trying to create a light source like in this image:


I see the implementation looking something like this, but I'm stuck as to how to achieve the radius fall-off effect.  Generating a full circle is a trivial case, the case where the angle is not a full circle is interesting, and to be clear, the radius fall-off is the most interesting part of this problem.  I'm looking ideally to use a for loop and create this look for an arbitrarily-sized vertex array, thanks.

struct Light : public sf::Drawable {
        Light( );


        sf::Vector2f    position;       // center of the triangle fan
        sf::Vector2f    direction;      // values clamped [-1, 1]
        float                   radius;
        float                   angle;          // equals pi radians in the image
        sf::Color               color;
        sf::VertexArray verticies;      // TriangleFan

        void                    draw( sf::RenderTarget& target, sf::RenderStates states ) const final override { target.draw( verticies, states ); }
        void                    calculateVerticies( );
};

void Light::calculateVerticies( ) {
        // amazing code, wow so good
}

3
Thanks Mark, but unfortunately that doesn't affect anything.  The reason I separated the ifs is so that I can check for right click and mouse wheel later using else statements rather than having to check for mouse event multiple times (the event is in scope the entire time so the event information will be stored in event.mouseButton).

the rect and text in question are created during the construction of the editor in the Game class (assignment in a constructor is bad, yes I know, but I'm only creating like 5 rectangleShapes and 5 texts at the beginning of the game so this is tolerable for my purposes).  During the construction I simply write:

editorItem_t button;
        button.rect = sf::RectangleShape( sf::Vector2f( editor.shell.getLocalBounds( ).width, EDITOR_BUTTON_HEIGHT ) );
        button.rect.setOutlineColor( sf::Color::White );
        button.rect.setOutlineThickness( EDITOR_OUTLINE_THICKNESS );
        button.rect.setFillColor( sf::Color( ) );  //black
        button.rect.setPosition( sf::Vector2f( 100, 100 ) );  //dummy location
       
        //center the text
        button.text = sf::Text( buttonText, editorFont, 20 );  //white text by default
        sf::FloatRect textRect = button.text.getLocalBounds( );
        button.text.setOrigin( textRect.left + textRect.width / 2.0f, textRect.top + textRect.height / 2.0f );

and this works fine.  In particular, I really don't understand how the button.rect.setFillColor() function works during construction of the editor but is unresponsive during the EditorMode setFillColor() statement.  Even writing a function in the Editor class called, say, ChangeColor, and calling it instead doesn't work for me:

void Editor::ChangeColor( sf::RectangleShape& rectangle ) {
        rectangle.setFillColor( sf::Color:Blue );
}

4
Hello,

The EditorMode() function is the end of my "Process Input" phase, and immediately after finishing with that function the main loop moves to the update phase:

void Game::MainLoop( ) {
        while ( window.isOpen( ) ) {
                ProcessInput( );
                Update( );
                window.clear();
                entityManager.DrawAll( window );
                window.display( );
        }
}

I don't have trouble clearing or drawing any objects, just changing the color.  I tried to leave out some steps which I thought were not relevant to this problem.  Adding the window.draw as suggested doesn't seem to change anything, since the rect/text is still getting drawn during the normal draw phase of the loop:

void Game::EditorMode( const sf::Event& currentEvent ) {
    //check to see if any editorItem_t rects were clicked
    if ( currentEvent.type == sf::Event::MouseButtonPressed ) {
        if ( sf::Mouse::isButtonPressed( sf::Mouse::Button::Left ) ) {
            for ( auto itr = editor.editorItems.begin( ); itr != editor.editorItems.end( ); ++itr ) {
                if ( itr->rect.getGlobalBounds( ).contains( currentEvent.mouseButton.x, currentEvent.mouseButton.y ) ) {
                    itr->rect.setFillColor( sf::Color::Blue );  //this isn't working at all
                    itr->text.setColor( sf::Color::White );     //this isn't working at all
                    window.draw( itr->rect );
                    window.draw( itr->text );
                    std::cout << "But this statement is working fine!" << std::endl;
                }
            }
        }
    }
}

5
I have two classes which, for the purpose of this exercise, are defined as follows:

class Editor {
public:
struct editorItem_t {
        sf::RectangleShape                                      rect;
        sf::Text                                                        text;
        editorState_t                                           action;
};
std::list<editorItem_t>                                 editorItems;
}

class Game {
public:
        void Game::EditorMode( const sf::Event& currentEvent );
private:
        Editor editor;
}

Please assume that there is a font loaded and that the sf::Text component is currently writing correctly.  EditorMode is defined as follows, and this is where my problem lies.  I'm using C++11 auto notation, but even without that the color-change statements are not working as intended:

void Game::EditorMode( const sf::Event& currentEvent ) {
        //check to see if any editorItem_t rects were clicked
        if ( currentEvent.type == sf::Event::MouseButtonPressed ) {
                if ( sf::Mouse::isButtonPressed( sf::Mouse::Button::Left ) ) {
                        for ( auto itr = editor.editorItems.begin( ); itr != editor.editorItems.end( ); ++itr ) {
                                if ( itr->rect.getGlobalBounds( ).contains( currentEvent.mouseButton.x, currentEvent.mouseButton.y ) ) {
                                        itr->rect.setFillColor( sf::Color::Blue );      //this isn't working at all
                                        itr->text.setColor( sf::Color::White );     //this isn't working at all
                                        std::cout << "But this statement is working fine!" << std::endl;
                                }
                        }
                }
        }
}

The compiler basically seems to be treating the rect.setFillColor and text.SetColor statements as no-ops and I have no idea how to fix this, any help would be much appreciated.

6
I struggled a ton with VS2013 today, probably wasted almost 2 hours on this.  Your template is amazing, can't thank you enough!

Pages: [1]
anything