[Solved] Text placement in a grand strategy game


#1

So I’ve started making a grand strategy game for fun kinda like the Paradox ones.
What a grand strategy is is like a game where there’s countries on the map and you play as one and do stuff (sorry for bad explanation.)
My issue is where the countries’ names get displayed.
So far all you can do is select a country and start taking provinces by just clicking on them.
Now, Portugal and Aragon name placement is fine, but Castile is not.
Here is my code and the game all in one image because of the stupid one image requirement for new users:


Now, what the text is wrongly doing is selecting all the provinces that are of it’s country, BUT the name gets placed closest to the “center province” of the game. The center province is where Castile’s name starts and is literally just the middle. The reason I know this is because when I took that one province close to the center province as Portugal, the name flocked there, besides that the actual land to the west was way bigger. Aragon’s and Portugal’s names are fine at the start, but as soon as you take one province closer to the center one they immediately flock there. How can I fix this? This seems like such a simple issue. Also, GDevelop, please add the ability to draw text on the screen with code instead of having to make text objects for every text because goodness labeling every country is going to be tedious.


#2

You maybe need to center the text object look here


#3

Sorry, I’m very new, I don’t know how to add that thing to my game???

Edit: I figured out that you just open it with GDevelop, you don’t drag it in or something, but it doesn’t work!
image


#4
  1. The rule of one image per post for new users is not stupid at all. I will explain why: because there are a lot of new users asking for help without even showing their events or sharing their projects to be helped (and as a former user of GDevelop and this forum I can tell you it was not always the case), and also because is excruciatingly frustrating trying to blindly help someone who doesn’t understand why something isn’t working. And it can be the simplest thing in the world, which is fine because we all started learning somewhere, but that’s why these and other rules are important to keep the forum consistent, such as the one that says posts should have descriptive titles and not just sentences like “I have a problem”, “Help me”, “I don’t know what to do”.

  2. It is perfectly possible to dynamically write things on the scene during runtime. This is done by creating a single text object and creating instances of it and changing the text of each instance using events. Examples included in each GDevelop distribution include projects that demonstrate how to manipulate the text object dynamically.

  3. Unfortunately, the file the user @UlisesFreitas very kindly shared with you is an old version that cannot be opened with GDevelop 5.

  4. Regarding the positioning problem, it is difficult to know why your project shows this behavior, because we cannot see what other events are affecting the objects and the variables. To begin with, I can see the text labels align to the position of the “Provinces” object and that you are dynamically pushing the “Provinces” object through the scene instead of locating it in coordinates. I have no idea how that work or exactly what you intend to achieve, but it doesn’t seem like an efficient way to locate objects in a simple strategy game. For later help is necessary to take a look at the project.

  5. Si te cuesta explicarte en inglés, podés escribirme en español por mensaje privado y te puedo ayudar con tu problema.


#5

Provinces is a group of objects that comprises of every object individually. Every province is a separate object. There are no other events effecting those. The only other code I have in my project are WASD to move, and then right click to select a country, and left click to take provinces, which have nothing to do with where the text is placed. Thanks, I will do the instance thing to make more texts. However, the positioning problem still isn’t solved.

I’ll try to send the project to you. It will appear here in like 5-10 minutes maybe?


#6

hmm… how do I share my game?


#7

You can upload it into your Google Drive (compressed in a zip or rar file) and then share (via pm, or here in this thread) a public link to it.

Here is how: https://www.appypie.com/faqs/how-can-i-make-my-google-drive-document-public


#8

I’m sorry I’m making things so difficult but I don’t have Google Drive. I’ll post image of literally everything in the game (it isn’t much.)


All provinces have this:

ALL of my code:


I hope this is enough. Provinces is a group of objects that includes all of the 100 or so province objects so far in the game…


#9

the code is 2 screenshots so some code is doubled in the middle so you know. I don’t have 2 sections of code that are exactly the same.


#10

When you use Provinces.X/Y(), GDevelop picks one of the Provinces objects that met the conditions.
If you want the name to go to the biggest block of provinces, you need to find an algorithm for that and then tell GDevelop to place the text there.

Looks promising anyway :clap:


#11

I think you’re doing unnecesary steps.

  1. If you have an object for every iberic province then it isn’t necessary to set the correspondent text label by referencing all the Provinces group and then trying to filter them by a variable… just go for the right object. Example: “Change the X position of CastileText to Castile.X()”, and so on.

  2. Instead of moving all your objects around you can use the “Center camera on an object” action to move the camera. You can set a invisible object (opacity = 0) and set the camera to always be centered on it, then just move around that object to hover the camera over the map.

  3. The use of dynamic variables will make the work a lot easier.

  4. I improvised a simple game showing some techniques that you can adapt to your game: [Example] Bomb dropping game

  5. Get a Google Drive.


#13

No no! :anguished: region.top (and bottom, and left, and right) is an implementation of this project: https://forum.gdevelop-app.com/t/example-flies-primitive-ia-and-object-defined-regions/25191.

Is just a variable filled with the result of a calculation during runtime, not an actual GD expression or property. It’s not so easy!


#14

I actually did it! I made the text show right in the middle!!! I explained a little more how in the DM