Hello.
I read manual, i understood that to creating of game objects need factory.
But if a i have many small g.o., must i create many factories for each g.o. ?
Do exist attribute in game object, which contain name of game object, which i can use like argument to factory ?
Like factory.create(“factory-” … object.get_name())
Thanks
Yes, you need a factory component for each different kind of G.O. you want to create. You can spawn as many instances of that G.O. as you want of course.
If you have many different objects that are very similar, you can generally use only one G.O. for all of them. You can use the ‘properties’ argument to factory.create
() to give different data to each object that you spawn. Then, on the object’s init()
you can use that data to change sprites, colors, properties, behavior, etc.
In addition to the properties mentioned in the above answer, each call to factory.create() also returns the game object ID of the object (such as “/instance1”). If you write
local obj = factory.create(...)
you will be able to get and change its position, pass messages to your created object, store it in a list, etc. For a full reference to factories, see the factory reference.