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

FlxSprite: Allow changes to cliprect to take effect without setter #3381

Merged
merged 2 commits into from
Feb 27, 2025

Conversation

Geokureli
Copy link
Member

@Geokureli Geokureli commented Feb 27, 2025

Fixes #3162

Will probably break clipRect unit tests

This is part of a larger effort, to add slice rects to FlxSprites so there's semi-unrelated changes like:

  • Moves logic from drawComplex to drawFrameComplex (will eventually replace it)
  • Add FlxFrame.clip to eventually replace the badly named clipTo, also optimizes some of the logic in them
package states;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.math.FlxRect;
import openfl.geom.Rectangle;

class ClipRectRoundTestState extends flixel.FlxState
{
    var sprite:FlxSprite;
    
    override function create()
    {
        super.create();
        
        sprite = new FlxSprite(10, 10);
        sprite.makeGraphic(100, 100);
        sprite.graphic.bitmap.fillRect(new Rectangle(20, 20, 60, 60), 0xFF0000ff);
        sprite.graphic.bitmap.fillRect(new Rectangle(40, 40, 20, 20), 0xFFffffff);
        add(sprite);
        sprite.clipRect = FlxRect.get(10, 10, 80, 80);
    }
    
    override function update(elapsed)
    {
        super.update(elapsed);
        
        sprite.clipRect.x += (FlxG.keys.pressed.D ? 1.0 : 0.0) - (FlxG.keys.pressed.A ? 1.0 : 0.0);
        sprite.clipRect.y += (FlxG.keys.pressed.S ? 1.0 : 0.0) - (FlxG.keys.pressed.W ? 1.0 : 0.0);
        
        sprite.clipRect.width += (FlxG.keys.pressed.RIGHT ? 1.0 : 0.0) - (FlxG.keys.pressed.LEFT ? 1.0 : 0.0);
        sprite.clipRect.height += (FlxG.keys.pressed.DOWN  ? 1.0 : 0.0) - (FlxG.keys.pressed.UP   ? 1.0 : 0.0);
    }
}
Screen.Recording.2025-02-27.at.9.46.36.AM.mov

TODO

  • unit tests don't know how to test graphical things
  • test flash manually

@Geokureli Geokureli added this to the Next Patch milestone Feb 27, 2025
@Geokureli Geokureli merged commit db6a5de into HaxeFlixel:dev Feb 27, 2025
11 checks passed
@Geokureli Geokureli deleted the cliprect branch February 27, 2025 15:54
@Geokureli Geokureli modified the milestones: Next Patch, 6.1.0 Mar 5, 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.

Detect changes to clipRect without needing to reset the field in order to take effect
1 participant