cocos2d-x:从另一个线程加载sprite不可能,任何模式?

cocos2d-x:从另一个线程加载sprite不可能,任何模式?

问题描述:

我的程序的事实


  1. Cocos2d-x主循环在自己的线程中运行。我们把它称为cocos2d-x-thread 。

  2. 我有一个 task_scheduler 在自己的线程中运行,您可以在其中提交轻量级任务。让我们把它称为task_scheduler-thread 。

  3. 每x毫秒,回调从 task_scheduler 。让我们称之为 task_scheduler-tick-callback

  1. Cocos2d-x main loop runs in its own thread. Let's call it cocos2d-x-thread.
  2. I have a task_scheduler that runs in its own thread, in which you can submit lightweight tasks. Let's call it task_scheduler-thread.
  3. Every x milliseconds, a callback is emitted from the task_scheduler thread. Let's call it task_scheduler-tick-callback.

我想做什么

当我发送task_scheduler-tick-callback 时,我想加载一个sprite,但是我不能从该线程中执行,所以我将必须提交由 cocos2d-x线程执行的某种工作

I want to load a sprite when task_scheduler-tick-callback is emitted, but I cannot do it from that thread, so I will have to submit some kind of work to be performed by cocos2d-x thread.

问题


  1. 在接收到这个工作时,如何使cocos2d-x-thread / em>,要执行?因为cocos2d-x已经运行了自己的循环,而且我想避免将自定义代码注入到cocos2d-x生成的项目中。

  1. How can I make cocos2d-x-thread, when receiving this work, to be executed? Because cocos2d-x is already running its own loop and I want to avoid injecting custom code to the cocos2d-x generated project at all costs.

任何模式?

编辑:Idea - >任何回调函数调用cocos2d-x中的每个循环迭代?是否存在?

Idea -> any callback function called for each loop iteration in cocos2d-x? Does that exist? I could integrate the call to my work piece like that.

使用这个来执行你的代码在主线程中:

Use this to execute your code in main thread:

Director::getInstance()->getScheduler()->performFunctionInCocosThread([]{
    // your code
});