The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

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.)

in Engine by (48 points)

1 Answer

+1 vote
Best answer

You can find the size of the viewport with:

get_viewport_rect().size

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.

by (318 points)
selected by

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:
http://docs.godotengine.org/en/3.0/getting_started/step_by_step/your_first_game.html

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.