Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprite.markTextureRegionChanged() method added #210

Open
wants to merge 1 commit into
base: GLES2
Choose a base branch
from

Conversation

flomin
Copy link

@flomin flomin commented Apr 11, 2013

This method can be used after modifications to a Sprite texture to update the Sprite with a call to onUpdateTextureCoordinates().

E.g. with this method to truncate the Sprite texture:

public static void truncateSpriteTextureRegion(final Sprite pSprite, final ITextureRegion pOriginalTextureRegion, final float pLeftX, final float pRightX, final float pTopY, final float pBottomY, final VertexBufferObjectManager pVertexBufferObjectManager) {
    final float lTruncX, lTruncY, lTruncWidth, lTruncHeight;
    if (pOriginalTextureRegion.isRotated()) {
        lTruncHeight = pOriginalTextureRegion.getWidth() - pLeftX - pRightX;
        lTruncWidth = pOriginalTextureRegion.getHeight() - pTopY - pBottomY;
        lTruncX = pOriginalTextureRegion.getTextureX() + pBottomY;
        lTruncY = pOriginalTextureRegion.getTextureY() + pLeftX;
    } else {
        lTruncHeight = pOriginalTextureRegion.getHeight() - pTopY - pBottomY;
        lTruncWidth = pOriginalTextureRegion.getWidth() - pLeftX - pRightX;
        lTruncX = pOriginalTextureRegion.getTextureX() + pLeftX;
        lTruncY = pOriginalTextureRegion.getTextureY() + pTopY;
    }
    pSprite.getTextureRegion().set(lTruncX, lTruncY, lTruncWidth, lTruncHeight);
    pSprite.markTextureRegionChanged();
    if (pOriginalTextureRegion.isRotated()) {
        pSprite.setWidth(lTruncHeight);
        pSprite.setHeight(lTruncWidth);
    } else {
        pSprite.setWidth(lTruncWidth);
        pSprite.setHeight(lTruncHeight);
    }
}

This method can be used after modifications to a Sprite texture in order to update the Sprite with a call to onUpdateTextureCoordinates().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant