How can I prevent a sprite from sticking out of the screen?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By keito940
:warning: Old Version Published before Godot 3 was released.

A small question,
How can I prevent the paddle’s KinematicBody2D sprites from breaking out of the screen beyond the screen?
Note: How do you receive the size of the stage when you create a game to scroll?
(in the future.)

:bust_in_silhouette: Reply From: Michael Paul

You can find the size of the viewport with:


I don’t know what “paddles” you mean, but you can clamp movement to the viewport in your positioning code. The sample Dodge Game has a good example of how to use it. Keep in mind that Dodge is written for V3.0, but “clamp” works the same for the stable version.

So I’m trying the Dodge Game example but clamping isn’t working. I tried the code myself and even copy-pasted from the tutorial. It says “Unexpected Token: Identifier: Position”

I’m not sure what’s happening. I’ve read the tutorial up and down.
The tutorial in question:

cfbrkfld | 2018-02-05 00:16