0

I am making a game which has a drop down menu in it. And so I want the menu to have a background image to it as it is transparent for now.

//CCSMenu stethMenu
stethMenu->alignItemsInColumns(2,2,2);
stethMenu->setPosition(winsize.width/2,winsize.height/2);

stethMenu is the Menu that I want to have a background. I have the background image in a CCSprite. I tried to make the sprite a child of stethMenu but that did not work gave an exception.

One method from the top of my head is to make the sprite a separate child of the current Layer and set its position to the same as menu. I was hoping for a better way of doing it, so that I do not have to set the position of sprite same as the menu every time its position changes.

4

2 回答 2

2

我会考虑您考虑的方法,即使用 CCSprite 作为 CCLayer 的子项作为最忠实于 cocos2d 设计原则的解决方案。

但是,与其将 CCSprite 和 CCMenu 添加为 CCLayer 的单独子项,我建议将 CCMenu 添加为 CCSprite 的子项。使用这种方法,您实际上只需要更改 CCSprite 的位置,它的所有子项都将相对于它定位。

节点图如下所示:

  • CCL图层
    • CCSprite
      • CC菜单
        • CCMenuItem
        • CCMenuItem
        • CCMenuItem
        • ETC...
于 2013-07-06T10:20:55.587 回答
0

创建CCSprite并将其添加到CCMenu的父级,使背景精灵的z-order小于CCMenu。

于 2013-07-05T16:46:41.230 回答