public void Instantiate(QBehavior script, QVector2 pos = default(QVector2), float rotation = 0) { script.Parent = QEntity.GetEntity(); script.Parent.World = this; script.Parent.Script = script; script.IsDestroyed = false; script.Transform.Reset(); script.SetName(); CreatorQueue.Enqueue(script.Parent); CreatorFlag = true; }
/*Internal Methods*/ /// <summary> /// Adds all the items in the queue into the scene on the next frame /// </summary> internal void ObjectCreator() { while (CreatorFlag) { //make temp array to store the queue QEntity[] temp = CreatorQueue.ToArray(); //Add all the queue to the main array //QGameObjectManager.For(CreatorQueue, o => GameObjects.Add(o.Script)); while (CreatorQueue.Count > 0) { Entities.Add(CreatorQueue.Dequeue().Script); } //reset the queue for objects that might get added from the OnStart() from the queued objects CreatorQueue = new Queue <QEntity>(); //Set the flag to false again, Instantiate makes it flip, means we need to load more objects CreatorFlag = false; temp.For(o => { if (o.Script is IQLoad l) { l.OnLoad(new QLoadContent(Engine, Content)); } }); //TODO check this Content.Atlases = QTextureAtlas.CreateAtlases(this); //Like if the textureAtlas is too big for one image, we create multiple atlases //and then pretend they are all on one array so the user doesnt have to worry about them //OnStart can potentially set flag to true temp.For(o => { if (o.Script is IQStart s) { s.OnStart(new QGetContent(Content)); } }); } }