In my platformer, I want each enemy sprite to have an enemyBox sprite to use for movement positioning, along with an enemyLabel text. To make things easier, I was hoping to use containers.
Since an object can't be part of more than 1 container, and I have many different enemy objects, I can't just create a generic enemyBox sprite and add it to each enemy's container. Therefore I was planning to create 3 families: enemies, enemyBoxes, and enemyLabels. Then I would make individual containers for each enemy type. I.e., zombie, zombieBox, and zombieLabel would be 1 container.
My prototype works except for the code that positions the enemy on the enemyBox. When pressing 'z' or 'w' to create the first enemy, it places it fine. If I continue to press the same key to create the same enemy type, the new enemies are created and placed as expected. But when I press the other key to create the other enemy type, the new enemyBox is created properly but the enemy is placed on the previously created enemyBox. Pic and c3p attached.
What am I doing wrong here?
Question 2: is using containers + families a good approach for what I'm looking to do, or is there a better way? I originally tried using a common instance variable called uniqueID to tie the different objects together, but I ran into picking inconsistencies. The container approach seemed like a promising solution, but this issue is giving me pause.
Thanks
https://drive.google.com/file/d/1glQSeDO72Fvi3SsmARA-Xsh_s_3nDdIJ/view?usp=sharing