記事一覧

ObjCOSC and Cocos2d Scene

シーン(Cocos2dのSceneですね)を切り替える場合、ObjCOSCの入力ポートの扱いはどうするのが正しいんでしょうね?
入力ポートを使うのは1つのシーンだけなので、該当シーンの init に入力ポート作成処理、dealloc に破棄処理を書いてみたのだけど、別のシーンに行って戻ってきたときにポートの再開に失敗する。
エラー的には
"Could not bind UDP socket for OSC".
というもので、これはおそらく最初に作ったポートが生きていて、もう一度作ろうとしても作れないという理由なんじゃないか・・・と思うのだけど詳しく調べる気力がないので別の方法で逃げました;
別の方法というのは、シングルトンを1コ作って、そっちに OSC受信を担当させるというもの。メッセージが来たらそれをディスパッチする。
で、実際に受信時処理が必要なシーンに入ったら、そのシーンをデリゲートとして登録してディスパッチを受ける。逆に要らないときはデリゲートを nil にする、という感じ。

What's the right way to manage ObjCOSC Input Port when changing the scene (<- I mean Cocos2d Scene)?
I need to activate OSC Input Port in only one scene, so I put the codes to make the port in the scene's init routine,and releasing codes in dealloc routine.
But it fails to restart the port when go to and back from other scenes.
The error is
"Could not bind UDP socket for OSC".
What does this mean?
My guess is, the port I first made still remains alive and cannot make new one.
If I did some tests I may be able to figure it out, but I don't have the energy to give it a go;
So I've added a singleton to my project and let it have the OSC Input Port so that the port keeps alive between scenes.
The singleton only does the dispatching OSC messages to the delegate. When entering the scene register itself as the delegate, and when leaving reset it to nil.