HelloWorldScene.cpp

walzer@cocos2d-x.org, 2011-07-12 18:45

Download (2.2 kB)

 
1
#include "HelloWorldScene.h"
2

    
3
USING_NS_CC;
4

    
5
CCScene* HelloWorld::scene()
6
{
7
        // 'scene' is an autorelease object
8
        CCScene *scene = CCScene::node();
9
        
10
        // 'layer' is an autorelease object
11
        HelloWorld *layer = HelloWorld::node();
12

    
13
        // add layer as a child to scene
14
        scene->addChild(layer);
15

    
16
        // return the scene
17
        return scene;
18
}
19

    
20
// on "init" you need to initialize your instance
21
bool HelloWorld::init()
22
{
23
        //////////////////////////////
24
        // 1. super init first
25
        if ( !CCLayer::init() )
26
        {
27
                return false;
28
        }
29

    
30
        /////////////////////////////
31
        // 2. add a menu item with "X" image, which is clicked to quit the program
32
        //    you may modify it.
33

    
34
        // add a "close" icon to exit the progress. it's an autorelease object
35
        CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(
36
                                                                                "CloseNormal.png",
37
                                                                                "CloseSelected.png",
38
                                                                                this,
39
                                                                                menu_selector(HelloWorld::menuCloseCallback) );
40
        pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );
41

    
42
        // create menu, it's an autorelease object
43
        CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
44
        pMenu->setPosition( CCPointZero );
45
        this->addChild(pMenu, 1);
46

    
47
        /////////////////////////////
48
        // 3. add your codes below...
49

    
50

    
51

    
52
        // add "HelloWorld" splash screen"
53
        CCSize size=CCDirector::sharedDirector()->getWinSize();
54

    
55
        CCSprite* pSprite = CCSprite::spriteWithFile("HelloWorld.png");
56
        pSprite->setAnchorPoint(ccp(0,0));
57
        pSprite->retain();
58
        CCRenderTexture *        textureRenderer =CCRenderTexture::renderTextureWithWidthAndHeight(pSprite->getContentSize().width,pSprite->getContentSize().height);
59
        textureRenderer->setPosition(ccp(size.width/2,size.height/2));
60
        textureRenderer->retain();
61
        textureRenderer->setSprite(pSprite);
62
        textureRenderer->clear(1,1,1,0.5);
63
        textureRenderer->begin();
64
        pSprite->visit();
65
        textureRenderer->end();
66
        addChild(textureRenderer);
67

    
68
        
69
        return true;
70
}
71

    
72
void HelloWorld::menuCloseCallback(CCObject* pSender)
73
{
74

    
75

    
76
        CCDirector::sharedDirector()->end();
77
        //CCDirector::sharedDirector()->replaceScene(HelloWorld::scene());
78

    
79
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
80
        exit(0);
81
#endif
82
}