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

fix flxBar pixel-perfect rendering #2853

Merged
merged 1 commit into from
Jul 3, 2023
Merged

Conversation

Geokureli
Copy link
Member

@Geokureli Geokureli commented Jul 3, 2023

closes #2849

FlxBar.draw was using what seems to be an old copy of FlxSprite.draw, where the position was rounded to the nearest pixel, but origin, was not. and since FlxBar's defualt height is 5, origin was - by default - 2.5. this caused the front bar to be half a pixel off in most cases

here is my test case:

package states;

import flixel.FlxG;
import flixel.group.FlxGroup;
import flixel.ui.FlxBar;
import flixel.util.FlxCollision;

class PixelPerfectRenderTestState2849 extends flixel.FlxState
{
    var bar:Bar;
    var walls:FlxGroup;
    override function create()
    {
        super.create();
        
        FlxG.camera.pixelPerfectRender = true;
        bar = new Bar(0, 100);
        bar.velocity.set(100, 100);
        bar.elasticity = 1;
        add(bar);
        
        walls = FlxCollision.createCameraWall(FlxG.camera, 10);
    }
    
    override function update(elapsed)
    {
        super.update(elapsed);
        
        FlxG.collide(bar, walls);
        
        if (FlxG.keys.justPressed.P)
            openSubState(new PauseSubState());
        
        bar.angularVelocity = 180 * ((FlxG.keys.pressed.RIGHT ? 1 : 0) - (FlxG.keys.pressed.LEFT ? 1 : 0));
    }
}

class PauseSubState extends flixel.FlxSubState
{
    override function update(elapsed:Float)
    {
        if (FlxG.keys.justPressed.Q)
            close();
    }
}

@:forward
abstract Bar(FlxBar) to FlxBar
{
    public function new(min = 0, max = 100):Void
    {
        this = new FlxBar(0, 0, LEFT_TO_RIGHT, 20, 5, null, "", min, max, true);
        this.createFilledBar(0xff510000, 0xfff40000, true);
        
        this.value = (max - min) / 2;
    }
}

@Geokureli Geokureli merged commit 12586a0 into HaxeFlixel:dev Jul 3, 2023
16 checks passed
@Geokureli Geokureli deleted the pix-perf-bar branch July 3, 2023 18:41
Geokureli added a commit that referenced this pull request Jul 3, 2023
@Geokureli Geokureli added this to the 5.4.0 milestone Jan 4, 2024
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.

None yet

1 participant