Can't get menu to show anything

Topics: Actions and Control Logic, Platform UI
Feb 3, 2014 at 12:43 PM
Hi all, I love the library, but cant get the menu system to work.

This is my code, it is inside an IntroLayer from a template projects:
        public IntroLayer()
            var stream = File.OpenRead(@".\Content\rooster.png");

            CCTexture2D x = new CCTexture2D();
            if (x.InitWithStream(stream) == false)
                return; // Does not get called.

            sprite = new CCSprite();

            CCMenuItemFont item = new CCMenuItemFont("asdasdasd");
            item.FontSizeObj = 35;
            item.FontNameObj = "Helvetica";

            CCMenuItemSprite img = new CCMenuItemSprite(sprite, sprite);

            var menu = new CCMenu(item, img);
            menu.Position = new CCPoint(160, 58);


            // setup our color for the background
            Color = new CCColor3B(Microsoft.Xna.Framework.Color.DimGray);
            Opacity = 255;
If I add the sprite directly to the layer, or add a CCLabelTTF to the layer, they both work and show just fine, so I know the layer code is being called etc. But I cant get any menu items, or the menu itself to show.

I am running on a Windows 7 machine, VS2012.

Any help much appreciated!!
Feb 3, 2014 at 6:59 PM

First error:

CCMenuItemSprite img = new CCMenuItemSprite(sprite, sprite);

You can't use the same sprite there, so just change that to:

CCMenuItemSprite img = new CCMenuItemSprite(sprite, null);

Once you do that you should be able to see the menu. Make sure that you are adding your menu at a z offset that is not occluded by other children.

Next, there is this:

var stream = File.OpenRead(@".\Content\rooster.png");
        CCTexture2D x = new CCTexture2D();
        if (x.InitWithStream(stream) == false)
            return; // Does not get called.

You can use:

var sprite = new CCSprite("rooster.png");

That should work to pull in your rooster image if your content path is set to "Content" and you are copying the rooter.png file over to your content directory at the end of your compile. File.OpenRead() will not always work on every platform due to some security restrictions on some of the more tightly-managed platforms. The content manager knows how to properly interop with the supported platforms and will pull the image in from a stream.
Marked as answer by drmkkk on 2/5/2014 at 7:49 AM
Feb 3, 2014 at 10:47 PM
Great. Now my rooster menu item is showing, thanks allot.
Sadly, the text based menu item (CCMenuItemFont) is still nowhere to be seen, any clue what might be wrong there?
I tried using a CCMenuItemLabel and that seems to be fine.
Feb 3, 2014 at 11:16 PM
        CCMenuItemFont item = new CCMenuItemFont("asdasdasd");
        item.FontSizeObj = 35;
        item.FontNameObj = "Helvetica";

This class is very confusing and old, so we'll need to do something with it in the next release. It is just a wrapper for CCMenuItemLabel with a CCLabelTTF. The "FontName" you have must correspond to a TTF font , e.g. "Content/Helvetica-35.xnb". If you don't have the Helvetica xnb font file then it will not work.

CCMenuItemLabel l = new CCMenuItemLabel(new CCMenuItemTTF("My Label", "Helvetica", 35));
Feb 4, 2014 at 2:11 PM
Got it, maybe mark the CCMenutItemFont with [Obsolete] or something.

The lib so far looks very good, I've been looking for a solution like this for so long, as I am keen on making c# 2D games, and portability is excellent option to have too.

BTW, is this the same project as this one?

Can be a bit confusing as there are now quite a few versions of Cocos. I was expecting there is also a c# wrapper version of Cocos2D-X, but looks like no such thing (or I just havent found it).
Feb 4, 2014 at 4:21 PM
cocos2d-x-for-xna was our first version. We diverted from that repository long ago because we needed to make the project more platform neutral and take on better design strategy for the framework.

Technically cocos2d-xna is really a 2D and 3D game engine. Because it is XNA 4 it does 3D as well, you just add a new drawable component to your game and you can draw 3D in there. That could draw atop the 2D world as well.

There is a cocos2d-net and cocos2d-this-and-that. We are not part of any of those any longer and we don't maintain the cocos2d-x-for-xna project any longer.
Feb 4, 2014 at 10:49 PM
I see. Well, thanks again.

I'll be betting my chances on your project. I have tons of experience, but little time, so the idea I have in mind will probably take 1.5-2 years to complete. Hopefully some early Alpha within an year. Maybe my work with your project will help improve some things, I'll try to provide feedback / fixes during the development process as much as I can.