Exemplo n.º 1
0
/**
 * Render object at runtime
 */
bool RuntimeSpriteObject::Draw( sf::RenderTarget & renderTarget )
{
    //Don't draw anything if hidden
    if ( hidden ) return true;

    renderTarget.draw( GetCurrentSFMLSprite(), sf::RenderStates(blendMode == 0 ? sf::BlendAlpha :
                                                               (blendMode == 1 ? sf::BlendAdd :
                                                               (blendMode == 2 ? sf::BlendMultiply :
                                                                sf::BlendNone))));

    /*sf::RectangleShape rectangle(sf::Vector2f(GetWidth(), GetHeight()));
    rectangle.setPosition(sf::Vector2f(GetDrawableX(), GetDrawableY()));
    rectangle.setOutlineThickness(5);
    rectangle.setOutlineColor(sf::Color(255,0,0));
    renderTarget.draw(rectangle);*/

    /*std::vector<Polygon2d> polygons = GetHitBoxes();
    for (unsigned int i = 0;i<polygons.size();++i)
    {
        sf::ConvexShape shape;
        shape.setOutlineThickness(5);
        shape.setOutlineColor(sf::Color(255,0,0));

        shape.setPointCount(polygons[i].vertices.size());
        for (unsigned int j = 0;j<polygons[i].vertices.size();++j)
            shape.setPoint(j, polygons[i].vertices[j]);

        renderTarget.draw(shape);
    }*/

    return true;
}
Exemplo n.º 2
0
void RuntimeSpriteObject::SetHeight(float newHeight)
{
    if ( newHeight > 0 )
    {
        scaleY = newHeight/GetCurrentSFMLSprite().getLocalBounds().height;
        if ( isFlippedY ) scaleY *= -1;
        needUpdateCurrentSprite = true;
    }
}
Exemplo n.º 3
0
void RuntimeSpriteObject::SetWidth(float newWidth)
{
    if ( newWidth > 0 )
    {
        scaleX = newWidth/GetCurrentSFMLSprite().getLocalBounds().width;
        if ( isFlippedX ) scaleX *= -1;
        needUpdateCurrentSprite = true;
    }
}
Exemplo n.º 4
0
float RuntimeSpriteObject::GetPointY(const gd::String & name) const
{
    if ( !name.empty() )
    {
        const Point & point = GetCurrentSprite().GetPoint(name);
        return GetCurrentSFMLSprite().getTransform().transformPoint(point.GetX(), point.GetY()).y;
    }

    return GetY();
}
Exemplo n.º 5
0
bool RuntimeSpriteObject::Draw( sf::RenderTarget & renderTarget )
{
    //Don't draw anything if hidden
    if ( hidden ) return true;

    renderTarget.draw( GetCurrentSFMLSprite(), sf::RenderStates(blendMode == 0 ? sf::BlendAlpha :
                                                               (blendMode == 1 ? sf::BlendAdd :
                                                               (blendMode == 2 ? sf::BlendMultiply :
                                                                sf::BlendNone))));

    return true;
}
Exemplo n.º 6
0
std::vector<Polygon2d> RuntimeSpriteObject::GetHitBoxes() const
{
    if ( currentAnimation >= animations.size() )
    {
        std::vector<Polygon2d> hitboxes; //Invalid animation, bail out.
        return hitboxes;
    }
    const sf::Sprite & currentSFMLSprite = GetCurrentSFMLSprite();

    std::vector<Polygon2d> polygons = GetCurrentSprite().GetCollisionMask();
    for (std::size_t i = 0;i<polygons.size();++i)
    {
        for (std::size_t j = 0;j<polygons[i].vertices.size();++j)
        {
            sf::Vector2f newVertice = currentSFMLSprite.getTransform().transformPoint(
                            !isFlippedX ? polygons[i].vertices[j].x : GetCurrentSprite().GetSFMLSprite().getLocalBounds().width-polygons[i].vertices[j].x,
                            !isFlippedY ? polygons[i].vertices[j].y : GetCurrentSprite().GetSFMLSprite().getLocalBounds().height-polygons[i].vertices[j].y);
            polygons[i].vertices[j] = newVertice;
        }
    }

    return polygons;
}
Exemplo n.º 7
0
float RuntimeSpriteObject::GetHeight() const
{
    return scaleY > 0 ? GetCurrentSFMLSprite().getLocalBounds().height*scaleY : -GetCurrentSFMLSprite().getLocalBounds().height*scaleY;
}
Exemplo n.º 8
0
float RuntimeSpriteObject::GetWidth() const
{
    return scaleX > 0 ? GetCurrentSFMLSprite().getLocalBounds().width*scaleX : -GetCurrentSFMLSprite().getLocalBounds().width*scaleX;
}