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

Oddities when using clipRect + scale. #2301

Open
ianharrigan opened this issue Apr 11, 2021 · 1 comment · May be fixed by #2643
Open

Oddities when using clipRect + scale. #2301

ianharrigan opened this issue Apr 11, 2021 · 1 comment · May be fixed by #2643

Comments

@ianharrigan
Copy link
Contributor

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.

@Geokureli
Copy link
Member

Geokureli commented Sep 30, 2022

FWIW, uncommenting just _s.origin.set(0, 0); has the same effect as uncommenting both, for me, and even then it doesn't seem "fixed".

I'd like to establish better terms than "behave strangely". I assume the bug here is that clipRect's position is scaled by the sprites scale. and the desired behavior is that if a sprite's position moves down and right by 10px, and the clipRect position goes up and left, the drawn rect should stay in the same screen position. Is that right?

I think I know how to fix this

@Geokureli Geokureli linked a pull request Oct 1, 2022 that will close this issue
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 a pull request may close this issue.

2 participants