Browse Source

Ensure full display of Urho2D samples whatever the user's resolution

Mike3D 11 years ago
parent
commit
08813e8e4b

+ 1 - 0
Bin/Data/LuaScripts/25_Urho2DParticle.lua

@@ -44,6 +44,7 @@ function CreateScene()
     local camera = cameraNode:CreateComponent("Camera")
     camera.orthographic = true
     camera.orthoSize = graphics.height * PIXEL_SIZE
+    camera.zoom = 1.2 * Min(graphics.width / 1280, graphics.height / 800) -- Set zoom according to user's resolution to ensure full visibility (initial zoom (1.2) is set for full visibility at 1280x800 resolution)
 
     local particleEffect = cache:GetResource("ParticleEffect2D", "Urho2D/sun.pex")
     if particleEffect == nil then

+ 1 - 0
Bin/Data/LuaScripts/27_Urho2DPhysics.lua

@@ -40,6 +40,7 @@ function CreateScene()
     local camera = cameraNode:CreateComponent("Camera")
     camera.orthographic = true
     camera.orthoSize = graphics.height * PIXEL_SIZE
+    camera.zoom = 1.2 * Min(graphics.width / 1280, graphics.height / 800) -- Set zoom according to user's resolution to ensure full visibility (initial zoom (1.2) is set for full visibility at 1280x800 resolution)
 
     -- Create 2D physics world component
     scene_:CreateComponent("PhysicsWorld2D")

+ 1 - 0
Bin/Data/LuaScripts/28_Urho2DPhysicsRope.lua

@@ -41,6 +41,7 @@ function CreateScene()
     local camera = cameraNode:CreateComponent("Camera")
     camera.orthographic = true
     camera.orthoSize = graphics.height * 0.05
+    camera.zoom = 1.5 * Min(graphics.width / 1280, graphics.height / 800) -- Set zoom according to user's resolution to ensure full visibility (initial zoom (1.5) is set for full visibility at 1280x800 resolution)
 
     -- Create 2D physics world component
     local physicsWorld = scene_:CreateComponent("PhysicsWorld2D")

+ 1 - 1
Bin/Data/LuaScripts/32_Urho2DConstraints.lua

@@ -37,7 +37,7 @@ function CreateScene()
     camera = cameraNode:CreateComponent("Camera")
     camera.orthographic = true
     camera.orthoSize = graphics.height * PIXEL_SIZE
-    camera.zoom = 1.2
+    camera.zoom = 1.2 * Min(graphics.width / 1280, graphics.height / 800) -- Set zoom according to user's resolution to ensure full visibility (initial zoom (1.2) is set for full visibility at 1280x800 resolution)
     renderer:SetViewport(0, Viewport:new(scene_, camera))
     renderer.defaultZone.fogColor = Color(0.1, 0.1, 0.1) -- Set background color for the scene
 

+ 4 - 2
Bin/Data/LuaScripts/33_Urho2DSpriterAnimation.lua

@@ -8,7 +8,7 @@ require "LuaScripts/Utilities/Sample"
 
 local spriteNode = nil
 local animationIndex = 0
-local animationNames = 
+local animationNames =
 {
     "idle",
     "run",
@@ -53,6 +53,7 @@ function CreateScene()
     local camera = cameraNode:CreateComponent("Camera")
     camera.orthographic = true
     camera.orthoSize = graphics.height * PIXEL_SIZE
+    camera.zoom = 1.5 * Min(graphics.width / 1280, graphics.height / 800) -- Set zoom according to user's resolution to ensure full visibility (initial zoom (1.5) is set for full visibility at 1280x800 resolution)
 
     local animationSet = cache:GetResource("AnimationSet2D", "Urho2D/imp/imp.scml")
     if animationSet == nil then
@@ -69,8 +70,9 @@ end
 function CreateInstructions()
     -- Construct new Text object, set string to display and font to use
     local instructionText = ui.root:CreateChild("Text")
-    instructionText:SetText("Click mouse to play next animation, \nUse WASD keys and mouse to move, Use PageUp PageDown to zoom.")
+    instructionText:SetText("Mouse click to play next animation, \nUse WASD keys and mouse to move, Use PageUp PageDown to zoom.")
     instructionText:SetFont(cache:GetResource("Font", "Fonts/Anonymous Pro.ttf"), 15)
+    instructionText.textAlignment = HA_CENTER -- Center rows in relation to each other
 
     -- Position the text relative to the screen center
     instructionText.horizontalAlignment = HA_CENTER

+ 1 - 0
Bin/Data/LuaScripts/36_Urho2DTileMap.lua

@@ -40,6 +40,7 @@ function CreateScene()
     local camera = cameraNode:CreateComponent("Camera")
     camera.orthographic = true
     camera.orthoSize = graphics.height * PIXEL_SIZE
+    camera.zoom = 1.0 * Min(graphics.width / 1280, graphics.height / 800) -- Set zoom according to user's resolution to ensure full visibility (initial zoom (1.0) is set for full visibility at 1280x800 resolution)
 
     -- Get tmx file
     local tmxFile = cache:GetResource("TmxFile2D", "Urho2D/isometric_grass_and_water.tmx")

+ 1 - 0
Bin/Data/Scripts/25_Urho2DParticle.as

@@ -48,6 +48,7 @@ void CreateScene()
     Camera@ camera = cameraNode.CreateComponent("Camera");
     camera.orthographic = true;
     camera.orthoSize = graphics.height * PIXEL_SIZE;
+    camera.zoom = 1.2f * Min(graphics.width / 1280.0f, graphics.height / 800.0f); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.2) is set for full visibility at 1280x800 resolution)
 
     ParticleEffect2D@ particleEffect = cache.GetResource("ParticleEffect2D", "Urho2D/sun.pex");
     if (particleEffect is null)

+ 1 - 0
Bin/Data/Scripts/27_Urho2DPhysics.as

@@ -43,6 +43,7 @@ void CreateScene()
     Camera@ camera = cameraNode.CreateComponent("Camera");
     camera.orthographic = true;
     camera.orthoSize = graphics.height * PIXEL_SIZE;
+    camera.zoom = 1.2f * Min(graphics.width / 1280.0f, graphics.height / 800.0f); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.2) is set for full visibility at 1280x800 resolution)
 
     // Create 2D physics world component
     scene_.CreateComponent("PhysicsWorld2D");

+ 1 - 0
Bin/Data/Scripts/28_Urho2DPhysicsRope.as

@@ -44,6 +44,7 @@ void CreateScene()
     Camera@ camera = cameraNode.CreateComponent("Camera");
     camera.orthographic = true;
     camera.orthoSize = graphics.height * 0.05f;
+    camera.zoom = 1.5f * Min(graphics.width / 1280.0f, graphics.height / 800.0f); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.5) is set for full visibility at 1280x800 resolution)
 
     // Create 2D physics world component
     PhysicsWorld2D@ physicsWorld = scene_.CreateComponent("PhysicsWorld2D");

+ 1 - 1
Bin/Data/Scripts/32_Urho2DConstraints.as

@@ -38,7 +38,7 @@ void CreateScene()
     camera = cameraNode.CreateComponent("Camera");
     camera.orthographic = true;
     camera.orthoSize = graphics.height * PIXEL_SIZE;
-    camera.zoom = 1.2f;
+    camera.zoom = 1.2f * Min(graphics.width / 1280.0f, graphics.height / 800.0f); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.2) is set for full visibility at 1280x800 resolution)
     renderer.viewports[0] = Viewport(scene_, camera);
     renderer.defaultZone.fogColor = Color(0.1f, 0.1f, 0.1f); // Set background color for the scene
 

+ 3 - 1
Bin/Data/Scripts/33_Urho2DSpriterAnimation.as

@@ -9,7 +9,7 @@
 Node@ spriteNode;
 int animationIndex = 0;
 
-Array<String> animationNames = 
+Array<String> animationNames =
 {
     "idle",
     "run",
@@ -57,6 +57,7 @@ void CreateScene()
     Camera@ camera = cameraNode.CreateComponent("Camera");
     camera.orthographic = true;
     camera.orthoSize = graphics.height * PIXEL_SIZE;
+    camera.zoom = 1.5f * Min(graphics.width / 1280.0f, graphics.height / 800.0f); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.5) is set for full visibility at 1280x800 resolution)
 
     AnimationSet2D@ animationSet = cache.GetResource("AnimationSet2D", "Urho2D/imp/imp.scml");
     if (animationSet is null)
@@ -75,6 +76,7 @@ void CreateInstructions()
     Text@ instructionText = ui.root.CreateChild("Text");
     instructionText.text = "Mouse click to play next animation, \nUse WASD keys to move, use PageUp PageDown keys to zoom.";
     instructionText.SetFont(cache.GetResource("Font", "Fonts/Anonymous Pro.ttf"), 15);
+    instructionText.textAlignment = HA_CENTER; // Center rows in relation to each other
 
     // Position the text relative to the screen center
     instructionText.horizontalAlignment = HA_CENTER;

+ 4 - 3
Bin/Data/Scripts/36_Urho2DTileMap.as

@@ -43,18 +43,19 @@ void CreateScene()
     Camera@ camera = cameraNode.CreateComponent("Camera");
     camera.orthographic = true;
     camera.orthoSize = graphics.height * PIXEL_SIZE;
+    camera.zoom = 1.0f * Min(graphics.width / 1280.0f, graphics.height / 800.0f); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.0) is set for full visibility at 1280x800 resolution)
 
     // Get tmx file
     TmxFile2D@ tmxFile = cache.GetResource("TmxFile2D", "Urho2D/isometric_grass_and_water.tmx");
-    if (tmxFile == null)
+    if (tmxFile is null)
         return;
-    
+
     Node@ tileMapNode = scene_.CreateChild("TileMap");
     tileMapNode.position = Vector3(0.0f, 0.0f, -1.0f);
 
     TileMap2D@ tileMap = tileMapNode.CreateComponent("TileMap2D");
     tileMap.tmxFile = tmxFile;
-    
+
     // Set camera's position;
     TileMapInfo2D@ info = tileMap.info;
     float x = info.mapWidth * 0.5f;

+ 1 - 0
Source/Samples/25_Urho2DParticle/Urho2DParticle.cpp

@@ -83,6 +83,7 @@ void Urho2DParticle::CreateScene()
 
     Graphics* graphics = GetSubsystem<Graphics>();
     camera->SetOrthoSize((float)graphics->GetHeight() * PIXEL_SIZE);
+    camera->SetZoom(1.2f * Min((float)graphics->GetWidth() / 1280.0f, (float)graphics->GetHeight() / 800.0f)); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.2) is set for full visibility at 1280x800 resolution)
 
     ResourceCache* cache = GetSubsystem<ResourceCache>();
     ParticleEffect2D* particleEffect = cache->GetResource<ParticleEffect2D>("Urho2D/sun.pex");

+ 1 - 0
Source/Samples/27_Urho2DPhysics/Urho2DPhysics.cpp

@@ -86,6 +86,7 @@ void Urho2DPhysics::CreateScene()
 
     Graphics* graphics = GetSubsystem<Graphics>();
     camera->SetOrthoSize((float)graphics->GetHeight() * PIXEL_SIZE);
+    camera->SetZoom(1.2f * Min((float)graphics->GetWidth() / 1280.0f, (float)graphics->GetHeight() / 800.0f)); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.2) is set for full visibility at 1280x800 resolution)
 
     // Create 2D physics world component
     /*PhysicsWorld2D* physicsWorld = */scene_->CreateComponent<PhysicsWorld2D>();

+ 1 - 0
Source/Samples/28_Urho2DPhysicsRope/Urho2DPhysicsRope.cpp

@@ -84,6 +84,7 @@ void Urho2DPhysicsRope::CreateScene()
 
     Graphics* graphics = GetSubsystem<Graphics>();
     camera->SetOrthoSize((float)graphics->GetHeight() * 0.05f);
+    camera->SetZoom(1.5f * Min((float)graphics->GetWidth() / 1280.0f, (float)graphics->GetHeight() / 800.0f)); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.5) is set for full visibility at 1280x800 resolution)
 
     // Create 2D physics world component
     PhysicsWorld2D* physicsWorld = scene_->CreateComponent<PhysicsWorld2D>();

+ 1 - 1
Source/Samples/32_Urho2DConstraints/Urho2DConstraints.cpp

@@ -107,7 +107,7 @@ void Urho2DConstraints::CreateScene()
 
     Graphics* graphics = GetSubsystem<Graphics>();
     camera_->SetOrthoSize((float)graphics->GetHeight() * PIXEL_SIZE);
-    camera_->SetZoom(1.2f);
+    camera_->SetZoom(1.2f * Min((float)graphics->GetWidth() / 1280.0f, (float)graphics->GetHeight() / 800.0f)); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.2) is set for full visibility at 1280x800 resolution)
 
     // Set up a viewport to the Renderer subsystem so that the 3D scene can be seen
     SharedPtr<Viewport> viewport(new Viewport(context_, scene_, camera_));

+ 3 - 1
Source/Samples/33_Urho2DSpriterAnimation/Urho2DSpriterAnimation.cpp

@@ -91,8 +91,9 @@ void Urho2DSpriterAnimation::CreateScene()
 
     Graphics* graphics = GetSubsystem<Graphics>();
     camera->SetOrthoSize((float)graphics->GetHeight() * PIXEL_SIZE);
+    camera->SetZoom(1.5f * Min((float)graphics->GetWidth() / 1280.0f, (float)graphics->GetHeight() / 800.0f)); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.5) is set for full visibility at 1280x800 resolution)
 
-    ResourceCache* cache = GetSubsystem<ResourceCache>();  
+    ResourceCache* cache = GetSubsystem<ResourceCache>();
     AnimationSet2D* animationSet = cache->GetResource<AnimationSet2D>("Urho2D/imp/imp.scml");
     if (!animationSet)
         return;
@@ -113,6 +114,7 @@ void Urho2DSpriterAnimation::CreateInstructions()
     Text* instructionText = ui->GetRoot()->CreateChild<Text>();
     instructionText->SetText("Mouse click to play next animation, \nUse WASD keys to move, use PageUp PageDown keys to zoom.");
     instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);
+    instructionText->SetTextAlignment(HA_CENTER); // Center rows in relation to each other
 
     // Position the text relative to the screen center
     instructionText->SetHorizontalAlignment(HA_CENTER);

+ 1 - 0
Source/Samples/36_Urho2DTileMap/Urho2DTileMap.cpp

@@ -83,6 +83,7 @@ void Urho2DTileMap::CreateScene()
 
     Graphics* graphics = GetSubsystem<Graphics>();
     camera->SetOrthoSize((float)graphics->GetHeight() * PIXEL_SIZE);
+    camera->SetZoom(1.0f * Min((float)graphics->GetWidth() / 1280.0f, (float)graphics->GetHeight() / 800.0f)); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.0) is set for full visibility at 1280x800 resolution)
 
     ResourceCache* cache = GetSubsystem<ResourceCache>();
     // Get tmx file