Create or delete objects? Cocos Creator is thread safe?

Hi guys, I have some noob questions.

I create the new objects within an event. I don’t know if the events happen in a different thread or it is a call inside the game loop. For example, if I’ve to create a shot/blast I do:

    onKeyDown (event: cc.Event.EventKeyboard) {    
        switch (event.keyCode) {
            ...
            case cc.macro.KEY.space:
                this.onShot();
                break;         
        }
    }
    onShot() : void {
        let shotNode: cc.Node = cc.instantiate (this.shotPrefab);  
        cc.Canvas.instance.node.getChildByName ('Shots').addChild (shotNode); // Agrega al prefab dentro del Node 
        shotNode.x = this.node.x;
        shotNode.y = this.node.getBoundingBox().yMax;
        this.shoots.push (shotNode);
    }

My questions:

  1. Allocation in game loop?
  2. Is there a special thread to create or delete objects?
  3. Events happen in a different thread or it’s called from the game loop?
  4. if events are in different thread, is it thread safe?

Thanks :slight_smile:

this documentation has answered all my questions: https://docs.cocos.com/creator/manual/en/scripting/pooling.html

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.