Spaceship Building Game

I want to make a game where you can build your own spaceship and then use it as player character.

How can i make that i can use the created objects in this scene (Hangar) in another scene (World) and they behave together as they where one playable object,

I love the concept. What type of pieces are used? If they were simple enough, it would be great if they could be drawn onto a shape painter. It would be nicer looking and easier if they were just one object. Can you post a picture of the pieces or maybe a completed ship? IDK how far along in the process you are.

Otherwise, my only other thought is to store the objects key values like name, position and size to a global array of structures. It might sound tough. IDK your experience level but it’s only like 10 events.

You can then rebuild it in the other scene from the global variable. I would either choose a main piece or pick the first one and use it as the main piece and using the sticker behavior you could stick all of the other pieces to it. You then would only have to move the main piece.

If you need collision detection then you could create a group object with all the parts in it and use the group name in the collision condition.

Again, this might sound like a lot. IDK. But it’s not that many events. You could also save multiple arrays to storage and rebuild them later.

This should be the starting Block, its the reactor Block.

This are the Blocks i have implemented so far: Reactor Block (with yellow dot), Full Block (rectangular) and Half Block (Triangel).
Later i will implement a inverted or rotated Version of the half Block and Things Like weapons and maybe shield Generators. In the building Screen you can place them on a grid drawed by the shape painter. You can only place them if they next to each other but not If they are overlapping. The Objekts are simple Sprites of 32x32px. I want to improve the graphics later.

It looks like this for example If you place the Blocks.

My experience Level is like 0. Just started with gdevelop and i have no experience in coding but i know some of the Terms that are used, i know what an array is but i dont know how to use it.

Yeah the Sticker behavior for moving the reactor Block as Main Block Sound perfect and i think i’ll choose this variant to do it.

So my Problem at the First is to store where the Blocks are and to load it into another Scene.

Ok, this might be a bit advanced then but it’s a good way to learn. I added some comments. And either I or someone else can help explain things. I’m not saying this is the best way. This is one way.

Try it:


It uses the stick and draggable behavior, the blocks are in a group except the reactor.

Edit: I thought I should mention. If you divide this between scenes, you would have to make the ship objects global. It doesn’t change the instances or the way anything behaves. Instances can still only exist in the scene they were created. It just makes the objects available in the object list so they can be added to other scenes without having to create the actual objects in each scene. Objects don’t exist until added to a scene. This just makes them available.

(Global Objects - GDevelop documentation)

So this my Code i think this is excatly what you Show me. But it didnt Work for me.

The reactor block gets saved but If i load it its get multiple instances u can See it when you drag the reactor block.
And the other Blocks didnt load .
What did i wrong.

I’ll try the demo when I’m on my PC. It’s tough to read the events, some seem chopped off. Can you take a screenshot of the last group with the window wider, so there’s no choping and not so much wordwrap?

Are all the objects except the reactor object in the group named BlocksGroup? Let me check your demo on my PC and compare your events to mine and I’ll get back to you.

Yeah sorry for that but i take the screenshots at my Phone at the moment because im not on PC also.
Hope this ones are better to read.

Yeah i tryed it with reactor and without the reactor in the BlocksGroup. It has the Same results.

The reactor block has to be in the BlocksGroup because of the building Events (the Events i use to place the Blocks) or i make a Seconds group for that Events

In the save section, the variable Block.Height is missing an e I’m assuming you copied the lines, so, they’re both the same. It’s using zero for the real value. So, I believe the objects get created but don’t have any height. I’m not sure why the reactor still get’s created.



If the reactor object is in the group list, it’s not available to be linked to. I know that sounds counterintuitive but only the object being created from the group name is picked with the among objects create action. You can have multiple group lists. They’re just lists. They don’t interact with each other.

Edit: I see why the reactor gets loaded. Another minor typo. the missing e in height in this case made it work because they both had the same typo.

Oh thank you mate now the saving and loading works. When im back from work i will try to load the ship in another scene.
But if i drag the reactor something strange happen.

You’re welcome. What happens? I think you might have posted the wrong link.

Yes, that’s weird. Something is most likely adding a new reactor on every frame.

It’s split between 2 images but the for each child in the load section doesn’t look like it’s a subevent of the LoadShip is clicked event. I think it’s running on every frame. Nothing happens until the local array is created when the load button is clicked.

Just be careful because there’s an empty event in there as well. You did it slightly different than my example by putting the actions on the same line as the button click. It didn’t change anything. So, it doesn’t matter but I’m guessing that’s why there’s an empty event. You could probably delete the empty event and drag the rest up as a subevent of the click event. and it should work. (As long as you also removed the reactor form the BlocksGroup)

Yeah because it wasnt a subevent it didnt work. Now it works. Thank you so much

1 Like

(Solved: With the condition “At beginning of the scene” on the first line it works)

So i have another problem. Maybe you can help me with this too.
So i want the enemy to rotate towards player and if the player is near enough the enemy should start moving towards the player. The enemy is like the player builded from blocks, so they are sticked to the enemy reactorblock. My problem is that the blocks are rotate with the enemy but they did not change the position.

Just click play in the first scene and then move with wasd keys towards the enemy and look what happens.

It looks really good. Try adding some form of trigger once to the stick action. Maybe an at the beginning of the scene

1 Like

I have a new problem :smiley:

I use the pathfinding behavior on the enemyreactor to avoid going through the asteroids and this works fine for this block but i want it to avoid that the blocks that are sticked to the reactor also avoid to go
through the asteroids, how can i make that?

That’s not an easy one. You could use a hidden object as a hitbox. Move that with the pathfinder and stick all of the objects to it instead of the reactor. The bigger question is how to create one that matches it.

My first thought is to calculate the overall bounding box of all the objects and use a resized sprite as the hitbox. It would create a rectangular hit box. You would calculate it and save it with the ship and then hide it when the objects are created.

Something like the grey box.

The problem is if the ship can be any shape, I’m not sure how well that would work. Since it’s the easiest solution. You could test it and see if it looks right.

To calculate a hitbox, you could use a for each object to find the extreme points and then get the width and height from the highest minus lowest and right-most minus left-most. You can use the objects individual bounding box values to test for the extremes.

I was curious, so I created and tested this by adding another button. You could do this during the save to array function, save the hitbox and then hide it when created.

So the size of the Hitbox (Grey) is correct but the Position isnt

When I tested mine, the grey sprites’s origin point was set to the center. That’s just something I prefer to use. You could use the left and top values and combine it into one action.