2014년 2월 3일 월요일

메뉴 터치 구현

helloworld.cpp에서


#include "HelloWorldScene.h"



USING_NS_CC;

CCScene* HelloWorld::scene()
{
   
    CCScene *scene = CCScene::create();
    
    HelloWorld *layer = HelloWorld::create();


    scene->addChild(layer);

    return scene;
}







bool HelloWorld::init()
{
       if ( !CCLayer::init() )
    {
        return false;
    }
    
    //터치
    setTouchEnabled(true);
    
    
    //사이즈 가져오기
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    
    
    
    
    //해변 배경 테스트 
    
    CCSprite* bg_aqua = CCSprite::create("aqua.jpg");
    bg_aqua->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    this->addChild(bg_aqua, -2);

    
    
    
    //타일맵 깔기
    
    CCTMXTiledMap *map = CCTMXTiledMap::create("kiwanTest4.tmx");
    map->setPosition(ccp(visibleSize.width/2, visibleSize.height/2));
    map->setAnchorPoint(ccp(0.5f, 0.5f));
    map->setScale(0.65f);
    addChild(map,-1);
    
    
    //플레이 화면 깔기
    CCSprite* pSprite = CCSprite::create("pg2_non.png");
    pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    this->addChild(pSprite, 0);
    
    
    
    //메뉴 버튼 만들기
    
    CCMenuItemImage* bt_RUN =
    CCMenuItemImage::create("running_bt.png", "running_bt2.png",this, menu_selector(HelloWorld::goToRun));
    
    
    
    
    CCMenu* menuMain = CCMenu::create(bt_RUN,NULL);
    
    
    
    
    //버튼 위치를 바꾸려면 ccMenu위치를 바꿔야
    menuMain->setPosition(ccp(100.0f , 100.0f ));
    
    addChild(menuMain,1);
    
    
    
    
    
    
    return true;
}




void HelloWorld::goToRun(CCObject* pSender){
    
    
    CCLog("goToRun Runs....");
    CCScene* runScene = ExerciseScene::rScene();
    CCTransitionScene* pTran = CCTransitionFade::create(1.5f, runScene);
    CCDirector::sharedDirector()->replaceScene(pTran);
    
    
}




void HelloWorld::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *event){
    
    
    
}

void HelloWorld::ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *event){
    
    
    
    
    
    
}

void HelloWorld::ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *event){
    
    
}

void HelloWorld::ccTouchesCancelled(cocos2d::CCSet *pTouches, cocos2d::CCEvent *event){
    
    
}





댓글 없음:

댓글 쓰기