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 clipRect improvements #3363

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

Conversation

Sword352
Copy link
Contributor

  • Don't round clipRect to ensure smooth clipping no matter the scale
  • Put clipRect back into the pool when the sprite is destroyed

Here is a sample demonstrating the visual changes of this pull request:

package;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;

class PlayState extends FlxState
{
	var sprite:FlxSprite;
	var speed:Float = 1 / 4;
	var total:Float = 0;

	override function create():Void
	{
		super.create();

		sprite = new FlxSprite();
		sprite.loadGraphic("flixel/images/logo/default.png");
		sprite.scale.set(12, 12);
		sprite.updateHitbox();
		sprite.screenCenter();
		add(sprite);

		sprite.clipRect = flixel.math.FlxRect.get(0, 0, sprite.frameWidth, sprite.frameHeight);
	}

	function updateClipRect(increment:Float):Void
	{
		total += increment;
		sprite.clipRect.y = total;
		sprite.clipRect = sprite.clipRect;
	}

	override function update(elapsed:Float):Void
	{
		super.update(elapsed);

		if (FlxG.keys.pressed.DOWN)
			updateClipRect(sprite.frameHeight * speed * elapsed);

		if (FlxG.keys.pressed.UP)
			updateClipRect(sprite.frameHeight * -speed * elapsed);
	}
}

Without this change, the sprite from the sample clips in "chuncks"
https://github.com/user-attachments/assets/36343c09-b20e-4c6a-80f0-d219225f2620

With this change, the sprite now clips much smoother
https://github.com/user-attachments/assets/304f8b45-75c4-4cfe-bd1b-3f0a01b07c20

swordcube added a commit to swordcubes-grave-of-shite/flixel that referenced this pull request Feb 11, 2025
@Geokureli Geokureli added this to the Post 6.0.0 stuff milestone Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants