cocos2d / CocosBuilder

CocosBuilder, the visual editor for cocos2d
forum.cocos2d-objc.org
Other
1.01k stars 595 forks source link

Loading CCMenu fails due to unsupported 'init' call #18

Closed adamlwgriffiths closed 12 years ago

adamlwgriffiths commented 12 years ago

Using the latest git checkout, I get the following assertion when loading a 'cci' file with the latest CCBReader.

* Assertion failure in -[CCMenu init], /Users/adamgriffiths/Workspace/Kobold2D/Kobold2D-1.1.0/Kobold2D/libs/cocos2d-iphone/cocos2d/CCMenu.m:53 ERROR: Uncaught exception CCMenu: Init not supported. * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'CCMenu: Init not supported.'

vlidholt commented 12 years ago

Right now cocos2d 1.1 is not supported by CocosBuilder.

adamlwgriffiths commented 12 years ago

http://nooooooooooooooo.com/vader.jpg

adamlwgriffiths commented 12 years ago

Perhaps you could help me understand how CCBuilder is working now.

I've 'swizzled' an init method into CCMenu and CCLabelTFF which stops the above exception (just routing init to initWithItems: nil, etc).

But CCLabelTTF is getting an error regarding an invalid value being set. It seems the latest CCBuilder is rather dynamic and sets values rather than having code per object type. Ie: [node setValue:[NSValue valueWithCGPoint:pt] forKey:name];

It seems LabelTTF is receiving a property it doesn't like and it is triggering this error:

2012-03-30 19:03:23.351 ProgressQuest-iOS[548:1c403] ERROR: Uncaught exception [<CCLabelTTF 0xa26e7f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key fontName. 2012-03-30 19:03:23.351 ProgressQuest-iOS[548:1c403] *\ Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<CCLabelTTF 0xa26e7f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key fontName.'

Tracing it I can see this is when it's attempting to set the 'fnt' property.

    else if (type == kCCBPropTypeFontTTF)
    {
        NSString* fnt = [self readCachedString];

        if (setProp)
        {
            [node setValue:fnt forKey:name];
        }
    }
Printing description of fnt:
/Users/adamgriffiths/Workspace/Kobold2D/Kobold2D-1.0.4/<snip>/Projectfiles-iOS/Resources/CCBuilder/pixelsix00.ttf
Printing description of node:
<CCLabelTTF = 0A182B80 | FontSize = 12.0>
Printing description of name:
fontName

Any ideas?

vlidholt commented 12 years ago

Yes, you will need the latest version of cocos2d 2.0 from GitHub https://github.com/cocos2d/cocos2d-iphone/tree/gles20 There has been some modifications done to cocos2d to better support CocosBuilder.

adamlwgriffiths commented 12 years ago

Ah.. heh.. I meant without upgrading to 2.0 =P

I understand you've got your priorities and cocos1 isn't one of them. Just trying to squeeze your brain a bit =)

Never mind, I'll poke around myself. If I get no where I'll just revert to the older CocosBuilder. Just doesn't support as many widgets, but it gets the job done. Cheers, Adam

adamlwgriffiths commented 12 years ago

This is just for anyone else's reference.

This is what I've worked out so far. (excuse my n00bishness, I'm new to ObjC).

It seems Cocos2 somehow links the existing 'memberVariable' to a property 'memberVariable' (without the ) for Key/Value Coding (https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Protocols/NSKeyValueCoding_Protocol/Reference/Reference.html#//apple_ref/occ/instm/NSObject/setValue:forUndefinedKey:)

I'm not sure how this has been done, but I've overloaded the 'setValue:forKey:' method of CCNode which "fixes" startup issues.

Catergories used to do this are here. https://gist.github.com/2250978

This seems to work. I've gotten a dialog up with a menu, sprite, layers. But the CCControlButtons are not showing. Using the code I can see the properties just aren't being set.

[CCControlButton] INFO: Setting value for key visible
[CCControlButton] INFO: Setting value for key enabled
[CCControlButton] INFO: Setting value for key selected
[CCControlButton] INFO: Setting value for key title|1
[CCControlButton] WARNING: Key title|1 not valid, trying title|1_
[CCControlButton] ERROR: Key title|1 failed!
<etc etc etc>

I'm not sure how the pipe (|) symbol is meant to work here. I know there are multiple titles and this will correspond to title 1, 2, 3 etc. But the variable names do not reflect this. Most curious.