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

Add support for ensuring sprite content size does not change on new texture #1897

Merged
merged 2 commits into from
May 16, 2024

Conversation

rh101
Copy link
Contributor

@rh101 rh101 commented May 15, 2024

Describe your changes

If a sprite is to be used for animations (such as the Animate action), and a specific sprite content size is set (usually with stretch mode enabled), then this adds support for ensuring that the content size of the sprite is not modified during the animation.

An explicit call to setContentSize will still work, but setting new textures on the sprite will not affect the content size due to this change:

void Sprite::setTextureRect(const Rect& rect, bool rotated, const Vec2& untrimmedSize)
{
    _rectRotated = rotated;

    if (_contentSizeDynamic || _contentSize == Vec2::ZERO)
    {
        Node::setContentSize(untrimmedSize);
    }
    _originalContentSize = untrimmedSize;

    setVertexRect(rect);
    updateStretchFactor();
    updatePoly();
}

The added method is:

void setContentSizeDynamic(bool dynamic) { _contentSizeDynamic = dynamic; }

I'm not completely sure about the naming of that method, setContentSizeDynamic, so if anyone has any alternate suggestions, then please put them forward. It should be something that indicates the sprite content size is not affected by new content (being a new texture etc.).

Also note that existing behaviour does not change, since the default is _contentSizeDynamic = true.

Issue ticket number and link

#1896

Checklist before requesting a review

For each PR

  • Add Copyright if it missed:
    - "Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md)."

  • I have performed a self-review of my code.

    Optional:

    • I have checked readme and add important infos to this PR.
    • I have added/adapted some tests too.

For core/new feature PR

  • I have checked readme and add important infos to this PR.
  • I have added thorough tests.

@halx99 halx99 added the enhancement New feature or request label May 16, 2024
@halx99 halx99 added this to the 2.1.3 milestone May 16, 2024
@halx99 halx99 linked an issue May 16, 2024 that may be closed by this pull request
@halx99 halx99 merged commit 49bd2bc into axmolengine:dev May 16, 2024
14 of 15 checks passed
@rh101 rh101 deleted the animate-fixed-size branch May 16, 2024 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for fixed sprite content size regardless of new texture content
2 participants