GAMEPAD CONTROLS: ADDING IN FUNCTIONS
Now let’s look at what you can do in a larger-scale game where your controller is more than just a ‘Gamepad’ because there are very few platforms with only ‘Gamepad’ controls these days.
Therefore, what I usually do in this situation is add a function.
You can see how everything works.
I move it here and then I’ll call it ‘MoveplayerSpeed’
I can add a ‘Touch’ control, a ‘Keyboard’ control, or whatever control I want. Then, instead of writing the code a million times, I write it all at once.
Let’s see how this rotation is done.
We move it here. We can make this ‘Player’ rotate.
Then ‘Set angle’ is 0.
The others we can also do the same.
As you can see, this is a simple program.
It is easier to call the function.
The ‘Player’ moves around. Now you’ve seen how one little simple thing made all the difference and made the game look better. If we want to add projectiles, which is probably the easiest thing you would do. Let’s add the 8 x 8 ‘Sprite’ here.
It’s probably good.
That’s going to be a projectile. Now inside this projectile.
We want to make sure that ‘Origin’ is set correctly. We call this the ‘Projectile’
In this ‘Behaviors’ will add the ‘Bullet’ behavior.
We set the angle.
Add in the ‘Gamepad’ ‘On button pressed’, and it will be ‘Right shoulder trigger’
‘Player’ spawns another object and one object will be a projectile.
Take a look at that here, as you can see. Perfect.
The projectile does not change the direction or angle of motion. Speed and bullet are too slow.
We go to ‘Projectile’ and set the motion angle.
Let’s see if it works.
Now things are going pretty well. As you can see, I’m faster than bullets, and that’s not good. Therefore, the projectiles probably have to go about a thousand to make this work.
But there is another problem the projectile is spawned in the middle of the ‘Player’
That’s where the image point comes in. We see ‘Image point’ is one on the ‘Gamepad’ here, and then we go back to the ‘Player’
We add on new image points.
We move it up here and make it 36 x 16, and ‘Image point’ projectiles will spawn outside.
As you can see, it is a good way to use the ‘Gamepad’ there. See in the next story.