码迷,mamicode.com
首页 > 其他好文 > 详细

Cocos2d-x学习笔记(七)菜单

时间:2015-01-03 23:54:27      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:

文本菜单示例:

#include "HelloWorldScene.h"

USING_NS_CC;

Scene* HelloWorld::createScene()
{
    auto scene = Scene::create();
    auto layer = HelloWorld::create();
    scene->addChild(layer);
    return scene;
}

bool HelloWorld::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    Sprite *bg = Sprite::create("bg.jpg");
    bg->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height/2));
    this->addChild(bg);

    MenuItemFont::setFontName("Times New Roman");
    MenuItemFont::setFontSize(80);
    MenuItemFont *item1 = MenuItemFont::create("Start", CC_CALLBACK_1(HelloWorld::menuItem1Callback, this));
  MenuItemAtlasFont *item2 = MenuItemAtlasFont::create("Help", "fonts/tuffy_bold_italic-charmap.png",48, 65 ,‘ ‘, CC_CALLBACK_1(HelloWorld::menuItem2Callback, this));

Menu *mn = Menu::create(item1, item2, NULL); mn->alignItemsVertically(); this->addChild(mn); return true; } void HelloWorld::menuItem1Callback(cocos2d::Ref *pSender) { MenuItem *item = (MenuItem*)pSender; log("Touch Start Menu Item %p", item); } void HelloWorld::menuItem2Callback(cocos2d::Ref *pSender) { MenuItem *item = (MenuItem*)pSender; log("Touch Help Menu Item %p", item); }

运行效果:

技术分享

图1 文本菜单示例

 

Cocos2d-x学习笔记(七)菜单

标签:

原文地址:http://www.cnblogs.com/AmitX-moten/p/4200150.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!