V
V
Vladimir Vorotnikov2019-01-31 13:26:20
Python
Vladimir Vorotnikov, 2019-01-31 13:26:20

Creating a rectangular grid in cocos2d (python), what's the best way?

I am getting acquainted with the cocos2d library in python.
You need to create a rectangular area divided into squares (and then react differently to clicking different squares, for example, display a certain sprite on the pressed square).
Now a separate layer (ColorLayer) has been created for the rectangular area in the following way:

class MainSceneField(ColorLayer):
    is_event_handler = True

    def __init__(self):
        super(MainSceneField, self).__init__(*GREEN, *FIELD_SIZE)

        self.x = FIELD_OFFSET
        self.y = FIELD_OFFSET

Tell me, please, how best to create square cells on it?
While 2 options are spinning in my head:
1. Draw horizontal and vertical lines using the draw function. Catch mouse click coordinates. Knowing the size of the rectangular area - to understand by the coordinates which cell was clicked on and take appropriate actions
2. Use what the library calls Tiled Maps ( python.cocos2d.org/doc/programming_guide/tiled_map ... then profit, in particular when processing events? Will it really be easier to work with them in the end?
The task seems very typical, maybe there is some other standard tool for solving it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question