Skip to content

Oddities when using clipRect + scale. #2301

Open
@ianharrigan

Description

@ianharrigan

So ive noticed some strange things happening when using clip rects and scales, here is the test app (source code below) working:

flixel-clip-scale-3

And here is the same test when the _scale var is set to 3:

flixel-clip-scale-4

Whats even more strange is that its possible to "fix" the app by uncommenting the lines in the test app below, which, honestly, doesnt make any sense to me as you have to have both of the lines, and i would have thought that one would have been enough...

Cheers,
Ian

  • Haxe version: 4.2.0-rc.1+e34463538
  • Flixel version: git@2c451b5b019805b4ac22701494204102387262e7
  • OpenFL version: git@36d184817973d80746340ef92b0dd7550a87af82
  • Lime version: git@c743fe10c404fb73003e24100f319a472cb4203f
  • Affected targets: all tested

Code snippet reproducing the issue:

class PlayState extends FlxState {
    private var _s:FlxSpriteGroup = null;
    
    private var _scale:Int = 3;
    
    override public function create():Void {
        var s:FlxSprite = new FlxSprite();
        
        s.loadGraphic(AssetPaths.haxeui_invert__png);
        s.origin.set(0, 0);
        s.scale.set(_scale, _scale);
        
        _s = new FlxSpriteGroup();
        _s.clipRect = new FlxRect(0, 0, 50, 50);
        _s.add(s);
        
        var g = new FlxSpriteGroup();
        var t = new FlxText();
        t.origin.set(0, 0);
        t.scale.set(_scale, _scale);
        t.text = "Foo!";
        t.color = 0xFFFF0000;
        g.add(t);
        _s.add(g);
        
        add(_s);
        
        super.create();
    }
    
	override public function update(elapsed:Float):Void {
		super.update(elapsed);
        
        // uncommenting out _both_ these lines "fixes" the issue, but it needs both, which doesnt make alot of sense to me
        //_s.origin.set(_s.frameWidth * 0.5, _s.frameHeight * 0.5);
        //_s.origin.set(0, 0);
        
        if (FlxG.keys.pressed.RIGHT) {
            _s.x += 1;
        } else if (FlxG.keys.pressed.LEFT) {
            _s.x -= 1;
        }
        
        if (FlxG.keys.pressed.DOWN) {
            _s.y += 1;
        } else if (FlxG.keys.pressed.UP) {
            _s.y -= 1;
        }
        
        if (FlxG.keys.pressed.D) {
            _s.clipRect.x += 1;
            _s.clipRect = _s.clipRect;
        } else if (FlxG.keys.pressed.A) {
            _s.clipRect.x -= 1;
            _s.clipRect = _s.clipRect;
        }
        
        if (FlxG.keys.pressed.S) {
            _s.clipRect.y += 1;
            _s.clipRect = _s.clipRect;
        } else if (FlxG.keys.pressed.W) {
            _s.clipRect.y -= 1;
            _s.clipRect = _s.clipRect;
        }
    }
}

Observed behavior:
When increasing the scale the clipping seems to behave strangely.

Expected behavior:
Clipping to be consistent regardless of scale.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions