Browse Source

Reinsert clamp in exporting docs (#3032)

Before this change clamping the players position got removed with the following explanation:
"We don't need to clamp the player's position because you can't click outside the screen."

While it is true that the player cannot click outside the window, the player can still click outside the playable area. Because we set Aspect to "keep" in the Project Settings, Godot will create Black borders if the window (or phone screen) doesn't match the desired aspect ratio. A player can now click on either of the borders and because clamp got removed the Player node will move out of the playable area and hide in the black border.

This is why the clamp should not be removed.
Flo 5 years ago
parent
commit
d24bbdfc2a
1 changed files with 6 additions and 4 deletions
  1. 6 4
      getting_started/step_by_step/exporting.rst

+ 6 - 4
getting_started/step_by_step/exporting.rst

@@ -105,10 +105,12 @@ changed:
             $AnimatedSprite.stop()
             $AnimatedSprite.stop()
 
 
         position += velocity * delta
         position += velocity * delta
-        # We don't need to clamp the player's position
-        # because you can't click outside the screen.
-        # position.x = clamp(position.x, 0, screensize.x)
-        # position.y = clamp(position.y, 0, screensize.y)
+        # We still need to clamp the player's position here because on devices that don't
+        # match your game's aspect ratio, Godot will try to maintain it as much as possible 
+        # by creating black borders, if necessary.
+        # Without clamp(), the player would be able to move under those borders.
+        position.x = clamp(position.x, 0, screen_size.x)
+        position.y = clamp(position.y, 0, screen_size.y)
 
 
         if velocity.x != 0:
         if velocity.x != 0:
             $AnimatedSprite.animation = "right"
             $AnimatedSprite.animation = "right"