Setting the right resolution for all platforms: iOS, Android, desktop
by Pedro Vicente · in Torque 2D Beginner · 12/03/2013 (7:42 pm) · 4 replies
I am modifying the function initializeCanvas(), from canvas.cs, so that
1) sets the camera size the same size as the resolution
2) calls a custom function that defines several size variables according to resolution
I don't understand this piece of code
more specifically, this variable $pref::iOS::DeviceType, is not defined anywhere in the default scripts or the engine code... so how can that function call be ever called ?
here's the modified function
1) sets the camera size the same size as the resolution
2) calls a custom function that defines several size variables according to resolution
I don't understand this piece of code
if ( $pref::iOS::DeviceType !$= "" )
{
%resolution = iOSResolutionFromSetting($pref::iOS::DeviceType, $pref::iOS::ScreenOrientation);
}more specifically, this variable $pref::iOS::DeviceType, is not defined anywhere in the default scripts or the engine code... so how can that function call be ever called ?
here's the modified function
$canvasCreated = false;
function initializeCanvas(%windowName)
{
// Don't duplicate the canvas.
if($canvasCreated)
{
error("Cannot instantiate more than one canvas!");
return;
}
videoSetGammaCorrection($pref::OpenGL::gammaCorrection);
if ( !createCanvas(%windowName) )
{
error("Canvas creation failed. Shutting down.");
quit();
}
$pref::iOS::ScreenDepth = 32;
if ( $pref::iOS::DeviceType !$= "" )
{
%resolution = iOSResolutionFromSetting($pref::iOS::DeviceType, $pref::iOS::ScreenOrientation);
}
else if ($platform $= "Android")
{
%resolution = GetAndroidResolution();
}
else //$platform $= "windows" || $platform $= "macos"
{
if ($platform_simul $= "iphone")
%resolution = "320 480 32";
else if ($platform_simul $= "ipad")
%resolution = "768 1024 32";
else if ($platform_simul $= "desktop")
%resolution = "1024 768 32";
else %resolution = $pref::Video::windowedRes;
}
setScreenMode( %resolution._0, %resolution._1, %resolution._2, false );
$canvasCreated = true;
// Now that we have a Canvas, we need a viewport into the scene.
// Give it a global name "mainWindow" since we may want to access it directly in our scripts.
new SceneWindow(mainWindow);
mainWindow.profile = new GuiControlProfile();
Canvas.setContent(mainWindow);
// Set the canvas color
if ($debug::use_test_scene) Canvas.BackgroundColor = "CornflowerBlue";
Canvas.UseBackgroundColor = true;
// Finally, connect our scene into the viewport (or sceneWindow).
// Note that a viewport comes with a camera built-in.
mainWindow.setCameraPosition( 0, 0 );
mainWindow.setCameraSize( %resolution._0, %resolution._1 );
mainWindow.setUseObjectInputEvents(true);
$model.set_platform_spaces(%resolution._0, %resolution._1);
if ($platform $= "Android")
hideSplashScreen();
echo ( "platform: ", $platform);
echo ( "resolution: ", %resolution._0, "x", %resolution._1, "x", %resolution._2);
}
#2
shouldn't this case be included also in the function iOSResolutionFromSetting() ?
It probably would be a good idea to change the name "NewiPad" to something else :-), the name "New" is always a bad choice to naming... it will be "old" next year
12/03/2013 (8:14 pm)
related to this, constants.cs defines$iOS::constant::NewiPadWidth = 2048; $iOS::constant::NewiPadHeight = 1536;
shouldn't this case be included also in the function iOSResolutionFromSetting() ?
It probably would be a good idea to change the name "NewiPad" to something else :-), the name "New" is always a bad choice to naming... it will be "old" next year
#3
For instance, on Windows, it only detects up to Win2000; the engine has no idea if it's on windows 7 or 8.
12/03/2013 (8:30 pm)
Regarding the modifications, bear in mind that not every T2D developer has an iOS device; when you find outdated notions such as "NewiPad", feel free to make the modifications and submit a pull request to GG's github repository.For instance, on Windows, it only detects up to Win2000; the engine has no idea if it's on windows 7 or 8.
#4
The Android engine code at platformAndroidAndroidWindow.cpp has
but this seems not to be exported to a Torque script variable...
Note that this is not to set the resolution, as this does it
but just to know if I am in landscape or portrait to set custom game dimensions (in this case to set a grid X and Y axis depending on orientation)
12/03/2013 (9:02 pm)
What about Android screen orientation?The Android engine code at platformAndroidAndroidWindow.cpp has
S32 orientation = _AndroidGameGetOrientation();
if (orientation == ACONFIGURATION_ORIENTATION_PORT)
{
gScreenOrientation = 1;but this seems not to be exported to a Torque script variable...
Note that this is not to set the resolution, as this does it
%resolution = GetAndroidResolution();
but just to know if I am in landscape or portrait to set custom game dimensions (in this case to set a grid X and Y axis depending on orientation)
Torque 3D Owner Pedro Vicente
Space Research Software LLC
For iOS, this is defined in engine\source\platformiOS\iOSWindow.mm
Con::setIntVariable("$pref::iOS::DeviceType", 1);