cocos2d-x:从另一个线程加载sprite不可能,任何模式? [英] cocos2d-x: loading sprite from another thread not possible, any pattern?

查看:141
本文介绍了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
});

这篇关于cocos2d-x:从另一个线程加载sprite不可能,任何模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆