토글 아이템메뉴 사용하기



c++)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "test100.hpp"
 
USING_NS_CC;
 
Scene* Test100::createScene()
{
    auto scene = Scene::create();
    
    auto layer = Test100::create();
    scene->addChild(layer);
    
    return scene;
}
 
 
bool Test100::init()
{
    if ( !Layer::init())
    {
        return false;
    }
    
    
    //토글 아이템에 사용할 메뉴아이템 (ps. 콜백함수 없음)
    auto toggle1 = MenuItemImage::create("btn-play-normal.png""btn-play-selected.png");   //메뉴아이템1
    auto toggle2 = MenuItemImage::create("btn-highscores-normal.png""btn-highscores-selected.png");   //메뉴아이템2
    //토글 아이템 생성
    //createWithCallback(콜백 함수, 메뉴아이템1, 메뉴아이템2, NULL)
    auto item1 = MenuItemToggle::createWithCallback(CC_CALLBACK_1(Test100::menuCallback, this), toggle1, toggle2, NULL);
    
    
    auto menu = Menu::create(item1, NULL);
    //메뉴위치 자동정렬
    //alignItemsVertically() : 세로로 자동정렬 , alignItemsHorizontally() : 가로로 자동정렬
    //메뉴 간격
    //alignItemsVerticallyWithPadding() : 세로간격 , alignItemsHorizontallyWithPadding() : 가로간격
    menu->alignItemsVertically();
    
    //메뉴위치지정
    //setPosition() , setAnchorPoint()
    
    this->addChild(menu);
    
    
    return true;
}
 
 
//콜백함수
void Test100::menuCallback(Ref* sender){
    CCLOG("menu callback");
}
cs



결과

메뉴를 클릭하면 메뉴아이템이 바뀐다


+ Recent posts