3

In CocosBuilder, there is a Code Connections section. At second line, it has three options: Don't Assign, Doc root var and Owner var.

Sometimes, I got a error when I was selecting Owner var, but it works fine after I changed it to Doc root var.

I google a lot, but can't find a satisfied answer.

Does anyone can explain the difference clear?

pktangyue
  • 8,326
  • 9
  • 48
  • 71

2 Answers2

4

Don't assign simply means that you are not using the Code Connections.

Doc root var means that you are connecting a custom cocos2d class. This will glue/connect the object in your document (CCB stage/file) to your code. This option is convenient but you must make sure that root node's controller object is provided.

Sometimes you need to be able to access member variables from and get callbacks to another object than the root node of a ccb-file. To do this you will need to pass an owner to the CCBReader.

as explained in Connecting with cocos2d-x.

Owner var provides you with more flexibility by allowing you to connect to a variable other than the root node. You can glue it to any variable of your choosing.

The error you are getting is most likely caused by providing a name that is not available (the variable doesn't exist). Note that setting the property to Doc root var or Owner var and leaving the field empty will cause this error.

Jordan Arnesen
  • 413
  • 5
  • 10
ppl
  • 1,120
  • 5
  • 18
2

When linking member variables the Doc root var will add a member in the root node's controller object. You could access it via MainScene.myVar assuming that you JS Controller is MainScene. This is defined by your scene root layer JS Controller property.

Alternatively, you can do the same thing with a custom object that is not directly tied to the scene via the JS Controller connection. To achieve this, you would use the Owner var attribute.

Don't Assign is the default and doesn't do anything.

In essence, these features allows you to easily reference those CCB objects from your code.

Experimenting with the CocosBuilder JS Example Games may be of help. The documentation on how to connect with cocos2d-x might also be useful to you if you didn't read it yet.

ppl
  • 1,120
  • 5
  • 18
  • Thank you for your post, but I didn't want **Connecting with Cocos2d JS**, and in how to connect with cocos2d-x, it doesn't describe the difference. – pktangyue Mar 06 '13 at 02:36
  • Yes, unfortunately I've only noticed the cocos2d-x flag after writing my answer. Since it is now the only answer I figured it might still inspire you. I'll refrain from commenting about cocos2d-x since I did not use it in conjunction with CocosBuilder yet. However, the concepts are the same as with the JS bindings. – ppl Mar 06 '13 at 13:37