Hello,
I'm discovering cocos2d for python, my project have to create a cocos2d
application inside a process and communicate with it with a Queue. I search
a way to read this Queue in event loop.
Some code to explain:
from multiprocessing import Queue
from multiprocessing import Process
from queue import Empty
import time
def start_cocos(input_queue: Queue):
import cocos
class HelloWorld(cocos.layer.Layer):
def __init__(self):
super().__init__()
label = cocos.text.Label(
'Hello, world',
font_name='Times New Roman',
font_size=32,
anchor_x='center', anchor_y='center'
)
label.position = 320, 240
self.add(label)
cocos.director.director.init()
hello_layer = HelloWorld()
main_scene = cocos.scene.Scene(hello_layer)
def loop_hook(director_or_scene_or_whatever):
while True:
try:
new_label_text = input_queue.get(block=False, timeout=None)
# ? Change label text ?
except Empty:
return # Finished to read Queue
loop_hook(None)
# ? Give to director loop_hook ?
cocos.director.director.run(main_scene)
output_queue = Queue()
process = Process(target=start_cocos, kwargs=dict(
input_queue=output_queue,
))
process.start()
time.sleep(2)
output_queue.put('New text for hello world')
time.sleep(2)
output_queue.put('New text again for hello world')
time.sleep(10)
In this example code, i search to give to director or something else the
loop_hook function. This loop_hook function should be executed a each loop
iteration. And inside it's loop_hook, i should be able to modify label text
value.
Is it possible ?
Regards,
Bastien.
--
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/cocos-discuss.
For more options, visit https://groups.google.com/d/optout.