Reputation: 8524
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?
Upvotes: 3
Views: 3455
Reputation: 1120
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.
Upvotes: 4
Reputation: 1120
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.
Upvotes: 2