Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17079

How to schedule a task on Cocos2d's thread without using an object (i.e. scene, layer, sprite, etc) but with a delay?

$
0
0

@royitaqi wrote:

We have Scheduler.performFunctionInCocosThread() method which performs a task in Cocos thread without having to have a Cocos object. http://www.cocos2d-x.org/reference/native-cpp/V3.9/dc/d82/classcocos2d_1_1_scheduler.html#aaa90af752a1db93d085d44b09d208420

Question: can I perform the same thing but with a delay?

I know there are different variations of Scheduler.schedule() functions, but they all require something like an object.

I assume using a thread sleep in a task given to Scheduler.performFunctionInCocosThread() will block the UI thread.

The reason for asking for a delay is that sometimes I need to perform some game logic in the future.

The reason for it to be done in Cocos2d thread is that I want it to be in the message queue rather than a worker thread so to avoid possible multi-threading issues.

The reason for without having a Cocos2d object is that let's say I use the current running scene as the object, then the delayed logic will not be performed if a scene switch happens before the delay is completed.

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 17079

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>