Skip to content

Fix scaling bug on FlxView3D on High DPI displays #665

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions source/flx3d/FlxView3D.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import away3d.containers.View3D;
import away3d.library.assets.IAsset;
import flixel.FlxG;
import openfl.display.BitmapData;
import openfl.system.Capabilities;
#end
import flixel.FlxSprite;

Expand All @@ -19,6 +20,7 @@ class FlxView3D extends FlxSprite
{
#if THREE_D_SUPPORT
@:noCompletion private var bmp:BitmapData;
@:noCompletion private final dpiScale:Float = 72.0 / Capabilities.screenDPI;

/**
* The Away3D View
Expand Down Expand Up @@ -52,6 +54,10 @@ class FlxView3D extends FlxSprite
FlxG.stage.addChildAt(view, 0);

bmp = new BitmapData(Std.int(view.width), Std.int(view.height), true, 0x0);

view.width *= dpiScale;
view.height *= dpiScale;

loadGraphic(bmp);
}

Expand Down Expand Up @@ -109,13 +115,16 @@ class FlxView3D extends FlxSprite
@:noCompletion override function set_width(newWidth:Float):Float
{
super.set_width(newWidth);
return view != null ? view.width = width : width;
if (view != null) view.width = width * dpiScale;
return width;
//return view != null ? (view.width = width * dpiScale) / dpiScale : width;
}

@:noCompletion override function set_height(newHeight:Float):Float
{
super.set_height(newHeight);
return view != null ? view.height = height : height;
if (view != null) view.height = height * dpiScale;
return height;
}
#end
}