|Topic was automatically imported from the old Question2Answer platform.
My goal is to set up clickable polygons for a stategy game, one per province - I guess, even if this idea might be questionable.
My first approach was : generate a CollisionShape based on each cells’ corners (given by the module), then a RigidBody2D and add the CollisionShape as a child of it. At this point I have no idea how to connect the input (as a mouse click) of the RigidBody2D, because this newly generated RigidBody2D obviously doesn’t have a script. I thought that instantiating a general-purpose RigidBody2D scene with a script might be the solution, but I’m afraid that I would a heavy process to instantiate dozens, not to say hundreds, of scenes.
I guess another approach could be to use an UI texture button but I thought that 2D nodes were a cleaner and more appropriate solution, mainly because of the static nature of UI, but I may be completely wrong.
An ultimate but important point is that I need to be able to draw each polygon texture procedurally, I would like to implement a biome system, with cells as sea and moutain among others.
If you have any idea, knowledge or advice, it would be very appreciated.
Thanks for reading
post-scriptum : here is my project’s code so far, to give an idea:
- the very basic _draw() function
- the Voronoi module’s part
- an attempt to draw a single clickable polygon from scratch, not related to Voronoi yet
I have no idea how to connect the input, because this newly generated RigidBody2D obviously doesn’t have a script.
You don’t have to use a standard class! You could as well prepare a custom scene including scripts, preload that and add instances of it to your tree instead of plain RigidBody2Ds. And if you add an
func init(points_array) function to this custom scene, this function could not only take care of the signal connection, but also handle the creation of the Polygon2D and CollisionShape subnodes.
Thomas Karcher | 2020-11-27 16:40
Thanks for replying. If I understood correctly, that’s equivalent of what I said further in my post : creating a new scene.
I’m wondering about two things here:
- does creating approximatively 200-300 scenes would be heavier than another 200-300 repeated process ? I don’t know if scene instantating is actually a big memory consumer, and if there is other lighter ways
- how would I make these polygons clickable ? Within every scene’s
script ? Would it work ? If yes, what node could I use,
CollisionShape like we said or something else ?
Sorry in advance for all these intricate questions, and thanks again to whoever reach this far hahaha
edesse | 2020-11-27 18:21