Child class position based on class?

I create objects, instances ofNode , let them call them. Each map has its own properties, such as buttons, text, and images, which are drawn in the .draw() function.

If I change the location of the map, the children objects do not move. Is there a way to snap my position to a map object?

+4
source share
2 answers

Use the setParent method:

 ofNode parent; ofNode child; child.setParent(parent); parent.setGlobalPosition(10, 20, 30); child.setPosition(100, 200, 300); ofVec3f pos = child.getGlobalPosition(); // pos == (110, 220, 330) 

Note that setPosition is local, associated with its parent position, while setGlobalPosition is global.

+1
source

I assume that you mean movement graphically. It is very implementation dependent. I do not know open frameworks, but to take Qt as an example, you would combine all the graphic elements as children of the main structure, the map. For instance. let the card be inherited from some super-object (frame or sth.) and include all the children in the card. In Qt, this is done by parent child relationships.

0
source