Help with game controls


#1

Hello everyone,

I am developing a platfrom game. My character is supposed to move left, right and jump on and over objects. I don’t want the controls to be visible.

The controls shouldn’t be visible but instead when the left part of the screen is pressed the player goes left, when the right part of the screen is pressed the player goes left and when the center of the screen is pressed the player jumps…something like that.

Please helps.

Thanks!


#2

That’s a little tricky to do, but I think I know how you can do it!

If you want to hide the controls in the screen, you can do that in the events. I can go in detail about how to do it if you want, but the basics of it are just to use the “Common Actions For All Objects > Visibility > Hide” action and choosee the controls. ^^

And now, in order to be able to move the character on the screen with the tap of a finger…

What we want is to get the X value of the tap when the player taps the screen, in order to know when they’re tapping the left, the right, or the center. We can do that!
I don’t know, however, your Scene’s width nor the height, which makes this a bit complicated - but I’ll try and do it just through expressions; so it will work in every case regardless of the screen size!

First of all, we need to make a new layer.
In order for any of the events below to work, the touch needs to be in ITS OWN LAYER. Let’s create another layer, and call it “Touch”.

ALL OF THESE EVENTS should be SUB-EVENTS of this event:

If touch or Left mouse button is down:

SUB-EVENTS:

// Move Left //
If cursor X position is < SceneWindowWidth() / 3
  simulate pressing Left key for Player
  flip horizontally Player: yes

( This means that if the player is pressing on the first third of the screen, the left part, the Player will move left. )

// Move Right //
If cursor X position is > SceneWindowWidth() - (SceneWindowWidth()/3)
  simulate pressing Right key for Player
  flip horizontally Player: no

( This means that if the player is pressing on the right side of the screen, greater than 2/3 of the screen, the player will move left. )

// Press Center - Jump //
If cursor X position is > SceneWindowWidth() / 3
If cursor X position is < SceneWindowWidth() - (SceneWindowWidth()/3)
  simulate pressing Jump key for Player

( This means that if the player is pressing on an area that's more than 1/3 of the screen and not more than 2/3 of the screen - the middle of the screen - the player will jump. )

All the conditions in the sub-events need to be in the layer “Touch”, or whatever new layer you made for it - or else this will not work.

Please, also remember to make these 3 events be Sub-Events of the “If touch or Left mouse button is pressed” event, otherwise it won’t work either!

The conditions to check where the cursor/touch is can be found in “Mouse and Touch > Cursor X Position”.
The action to simulate the pressing of the keys can be found in “Platform Behavior > Controls”. Please, make sure to use the Platform behavior-specific actions - not the Top-Down ones!

I hope this helps! ^^


#3

Thank you so much. I will try it and let you know.


#4

Hi!
If you don’t want the on-screen controls, simply go to the editor and delete the objects on the scene.

Instead of checking the cursor position as suggested, you can also add big invisible buttons for each part of the screen. :wink: Make big colored rectangles, configure them like any other button, and hide them at the beginning of the scene.


#5

Hi,

Thank you so much. It worked. I used the large rectangles because the first code didn’t work.

I’m not sure if you are familiar with Admob on gdevelop but I did the following to add Admob. I’m not sure if it’s correct. I’m using an interstitial

I already added the ad ID in the properties section.


#6

Not too familiar with it, no, I’m not here for the money :blush: but you should use the test mode until it works properly.
Also, I heard there can be an initial delay of a few days to set up your Admob account.
Good luck!


#7

I’ve gotten the same response from everyone, wait a few days for Admob to be set up. Thanks.

One last thing I’d like to ask for your help with. Saving the game state. This is what I’ve done

I want the game state to be saved when a player exits the game. So if the player was in level 2, position X, and they exit the game when they return to the game they should be in level 2, position X. I’ve included a save button so that when the player clicks the save button the game can be saved. I don’t know if this is necessary or if there’s an easier way to do it.


#8

Hi MayhemCats

I want to publish my app on the Microsoft PlayStore but the extension for the game is .exe and Microsoft only accepts the following extensions (.msix, .msixbundle, .msixupload, .appx, .appxbundle, .appxupload, .xap)

Do you know how I can change the extension? The game has already been packaged.

Thanks!