I would like to use this topic as a means to receive help about implementing various platformer-related things using GDevelop.
I’ll update the topic as new questions/problems arise. I’ll number the questions for easy navigation/finding.
For starters, here are 3 questions:
How do I update the platformer’s main character’s sprite change when the mouse cursor points at a location in the scene?
I would like my character to change his sprite when he shoots at different angles by pointing with the mouse cursor, i.e. to change the sprite to player-shooting-up when the mouse cursor is above the character. How do I achieve that using the event editor?
I would like my character to shoot a bullet with the mouse when I press a specific button (or click using the left/right mouse button) and then I would like for something to appear on the position where the mouse cursor was pointed at (e.g. an explosion or an energy ball). How do I do that?
Following 2., I would like to create a 1st object where the mouse cursor was when the left mouse button was clicked and to create a 2nd object where the right mouse button was clicked, and then I would like the player to teleport to the location of object 1(/2) when the player touches object 2(/1). Then I would like the two objects to be destroyed when the left/right mouse button gets pressed again. How do I do that?
Thanks in advance for your answers! There are very appreciated! I’m working on a simple 2D platformer myself.
P.S. I’m pretty new to GDevelop, but I find it awesome! Also, I forgot to mention that my game will be open-source, so I’ll share it (along with the source .gdg file) when it’s done; I might also share alpha/beta/demo versions.
I don’t really have time to write step by step or make an example for you, but I can help you with the theory how it works:
Ideally your player body image and hands image are separated objects and you control the body that the hands follow and your rotate the hands to the position of the mouse by using “All objects/Angle/Rotate toward position” action and for X and Y you can use MouseX() and MouseY() expressions.
If you want to use different animation, you can simply change the animation using “Sprite/Animation and images/Change animation” action and to change animation only when the mouse is in certain position, you can use “Other/compare two expression” condition and simply check if the mouse X and Y position is greater then the player X and Y position, by using
“MouseX() > player.X() and MouseY() > player.Y()” expression for example, but probably you want to specify an exact position for the mouse so you should do something like MouseX() = player.X()+50 and MouseY() = player.Y()+50" obviously “player” is the name of your object used as player. Of course you also need to change the animation back to idle or whatever when the mouse is in different position but you can do it the same way
if you want ot shoot a bullet, first of all you need to add a “point” to your player object in the object editor where you want the bullet to be created, then you need a bullet object.
To create the bullet when the mouse is pressed, just simply check the mouse press using “Mouse/Mouse button” condition and to create the bullet you can use the “All objects/Object/Create an object” action to create the bullet object on mouse press, and to set it position on X and Y you can use “player.PointX(pointname) and player.PointY(pointname)” expression. “pointname” is the name of the point you have created in object editor. To move a bullet simply use the “All objects/Movement/Add a force(angle)” action and for angle I always use the bullet own direction “bullet.Direction()”. Of course “bullet” is the name of the object used as bullet. If your player is rotating or change it direction (probably the hands are) you also need to change the direction for each bullet to be the same as the player or hands direction using “Sprite/Direction/Change the direction” action and use “player(or hands).Direction()” as the direction of the bullet. You need to do this after each bullet is created, this way each bullet can have it own direction and equal to player or hands actual direction when it was created. To create an explosion or any object in the position of the mouse when is pressed, you can do it the same way as you create a bullet but for position you need to use the mouse X and Y coordinates “MouseX(), MouseY()”. If it an explosion you probably also want to delete the object once the animation is finished, you can do that by checking if the animation is finished using the “Sprite/Animation and images/Animation finished” condition and to delete just simply use the “All objects/Objects/Delete an object” action.
You can create an object on any mouse press just like I have explained above. To “teleport” the player, you just simply need to change it X,Y position to be the same as the object X and Y position you want to “teleport” to by using “All objects/Position/Position of an object” action. For X and Y you can use “object.X() and object.Y()” expression.
Of course “object” is the name of the object you want to teleport to. You can delete an object on mouse press just like when you create it, but you “Delete an object” this time. And you can check if player is in collision with other objects using “All objects/Collision/Collision” or “Sprite/Collision/Collision(pixel prefect)” condition.
Maybe it sounds a bit complicated at first but I hope it helps.