This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I am messing around with making a mobile game, which means touch controls. I have stages set up as individual scenes, and each scene has a Player node with touch controls attached. My problem is that, when I transition scenes to change levels, the game stops registering the screen touch event. Here is the relevant code:

if Input.is_action_pressed("ui_left") || $"TControls/Left".is_pressed():
    velocity.x = -SPEED
elif Input.is_action_pressed("ui_right") || $"TControls/Right".is_pressed():
    velocity.x = SPEED
velocity.y += GRAVITY
velocity = move_and_slide(velocity, FLOOR)

That's in the Player object. I've obviously removed some unrelated code, but this is essentially how I'm dealing with the touch controls. What I think is happening is that, when I load a new scene, it creates a new Player object, which in turn creates new touch controls which don't get registered as pressed until the player re-touches the button.

It's not a major issue, but, it would help the flow of the gameplay a lot if the movement persisted. Does anyone have any ideas on how to get around this issue? Thanks a bunch in advance.

in Engine by (15 points)

1 Answer

+1 vote
Best answer

This is probably not a very convient answer but I'd use a single parent scene which instances the level scenes as child nodes. The input handling should be done by the parent scene and handed over the currently active level. Naturally you can do also other tasks in the parent scene (score counting etc.)

by (3,370 points)
selected by

Amusingly enough, I came to this conclusion as well, but my attempts to do so had me pulling my hair out. Given how this project is designed and implemented, it might be easier to start from scratch. I have a plethora of questions concerning the best way to organize this task - too many to feel comfortable asking, in all honesty. I'll continue to mess around and see what I can do on my own. Thanks for your answer and your time!

Update: I got it! I was massively over-complicating things. The level handling I had set up beforehand was perfectly acceptable. The problem was with the touch controls being attached to the player - all I had to do was create a scene with the touch controls in it, make it a singleton, and set the onpressed and onreleased signals to use actionpress and actionrelease to simulate the proper inputs on my input map:

func _on_Left_pressed():
    Input.action_press("ui_left")
func _on_Left_released():
    Input.action_release("ui_left")

etc etc. It really was that simple. In fact, it's more simple than my original setup! I've been banging my head against the wall for 3 days with this. Thank you so much for your help.

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.