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

Implement pixel-perfect/subpixel rendereing toggle for FlxCamera #1060

Merged
merged 1 commit into from
May 8, 2014

Conversation

schonstal
Copy link
Contributor

This change adds pixelPerfect to FlxCamera, allowing you to set pixel-perfect rendering per-camera, and changes instances of pixelPerfectRender to use a pixelPerfect-aware check, while preserving the existing behavior.

Notes:
I had spoken to Gama11 about this in IRC, and was recommended an approach similar to antialiasing (antialiasing || camera.antialiasing).

If I had done Camera.pixelPerfect && pixelPerfectRender, it would exclude the case where you had set Camera.pixelPerfect = false, but wanted to set pixelPerfectRender = true on your object; this allows pixelPerfectRender to take precedence regardless of what value Camera.pixelPerfect has been assigned.

@gamedevsam
Copy link
Contributor

Glorious!!!

@@ -348,7 +348,7 @@ class FlxObject extends FlxBasic
* Only affects tilesheet rendering and rendering using BitmapData.draw() in blitting.
* (copyPixels() only renders on whole pixels by nature). Causes draw() to be used if false, which is more expensive.
*/
public var pixelPerfectRender(default, set):Bool = true;
public var pixelPerfectRender(default, set):Null<Bool>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just return Bool, not Null<Bool>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it nullable so isPixelPerfect could see if a value had been set.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little odd, but makes sense. I have no idea why you'd want some sprites to be pixel perfect and others to not be pixel perfect, but it doesn't hurt to have that capability...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can make sense on Flash. pixelPerfect forces them to be draw()n, which is rather expensive, so you might only want the most important stuff (player char etc) to use subpixel-rendering.

@Gama11
Copy link
Member

Gama11 commented May 8, 2014

Nice! I like the Null<Bool> approach, it's in a way more intuitive than the antialiasing one... I think I'm going to change that to use the same.

I thought about implementing this the other way around - have the camera's pixelPerfect be a Null<Bool> and null by default, and if you set it, it overrides the setting of all sprites on it. But I think this approach makes more sense.

I don't like that you chose a different name for camera.pixelPerfect (as opposed to pixelPerfectRender).

@Gama11
Copy link
Member

Gama11 commented May 8, 2014

This doesn't really work in its current state... It would require changing isSimpleRender() to isSimpleRender(Camera), since pixelPerfectRender affects the results of isSimpleRenderBlit():

public function isSimpleRenderBlit():Bool
{
    return ((angle == 0) || (bakedRotationAngle > 0)) && (scale.x == 1) && (scale.y == 1) && (blend == null) && pixelPerfectRender;
}

@Gama11 Gama11 merged commit ab75d07 into HaxeFlixel:dev May 8, 2014
Gama11 added a commit to HaxeFlixel/flixel-addons that referenced this pull request May 8, 2014
@schonstal
Copy link
Contributor Author

isSimpleRenderBlit is used in stamp, which I don't think should care about which camera the sprite is on?

Null evaluates to false so this might make stamp behave strangely.

Maybe it should be changed to:

public function isSimpleRenderBlit():Bool
{
    return ((angle == 0) || (bakedRotationAngle > 0)) && (scale.x == 1) && (scale.y == 1) && (blend == null) && (pixelPerfectRender == null || pixelPerfectRender);
}

LaughingLeader pushed a commit to LaughingLeader/flixel-addons that referenced this pull request Jun 28, 2014
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 this pull request may close these issues.

3 participants