Hi!
I have a problem with OpenFL/Starling
My game has designed as portrait but I need to support desktops. So I render Starling viewport
at center of available screen and use stageWidth and stageHeight according to my graphics spritesheets.
Initialization:
stage.scaleMode = StageScaleMode.NO_SCALE;
.....
_starling = new Starling(Game, stage, null, null, Context3DRenderMode.AUTO, "auto");
_starling.stage.stageWidth = 960;
_starling.stage.stageHeight = 960;
var viewPort:Rectangle = RectangleUtil.fit(new Rectangle(0, 0, 960, 960), new Rectangle(0, 0, stage.stageWidth, stage.stageHeight));
_starling.viewPort = viewPort;
_starling.supportBrowserZoom = true;
_starling.supportHighResolutions = true;
And function to resize/positioning game (including after resize/fullscreen events):
public static final DEFAULT_WIDTH:Int = 540;
public static final DEFAULT_WIDTH_MAX:Int = 960;
public static final DEFAULT_HEIGHT:Int = 960;
public static final DEFAULT_HEIGHT_MAX:Int = 960;
....
private function updateGameSize(force:Bool = false):Void
{
var nativeWidth:Int = Starling.current.nativeStage.stageWidth;
var nativeHeight:Int = Starling.current.nativeStage.stageHeight;
var browserZoom:Float = Starling.current.nativeStage.contentsScaleFactor;
if (nativeWidth == 0 || nativeHeight == 0)
{
return;
}
if (force || Math.abs(_lastStageWidth - nativeWidth) > 20 || Math.abs(_lastStageHeight - nativeHeight) > 20)
{
_lastStageWidth = nativeWidth;
_lastStageHeight = nativeHeight;
var fullScreenWidth:Int;
var fullScreenHeight:Int;
fullScreenWidth = Std.int(Math.min(nativeWidth, nativeHeight * (Game.DEFAULT_WIDTH_MAX / Game.DEFAULT_HEIGHT)));
fullScreenHeight = Std.int(Math.min(nativeHeight, nativeWidth * (Game.DEFAULT_HEIGHT_MAX / Game.DEFAULT_WIDTH)));
Starling.current.viewPort = new Rectangle(browserZoom * (nativeWidth - fullScreenWidth) / 2, browserZoom * (nativeHeight - fullScreenHeight) / 2,
fullScreenWidth, fullScreenHeight);
var stageSizeCoeff:Float = Math.max(1, Game.DEFAULT_HEIGHT / fullScreenHeight);
if (fullScreenHeight >= Game.DEFAULT_HEIGHT_MAX)
{
stageSizeCoeff = Game.DEFAULT_HEIGHT_MAX / fullScreenHeight;
}
Starling.current.stage.stageWidth = Std.int(fullScreenWidth * stageSizeCoeff);
Starling.current.stage.stageHeight = Std.int(fullScreenHeight * stageSizeCoeff);
}
}
All is good except case when system/browser zoom set to not 100%:
For my notebook with 150% system zoom all InteractiveDisplayObject hover/click area is moved to right:
So seems the problem appears if starling.viewPort.x != 0
What is wrong?
Thx!