Beispiel #1
0
//------------------------------------------------------------------
//
// LayerTest1
//
//------------------------------------------------------------------
void LayerTest1::onEnter()
{
	LayerTest::onEnter();

	setIsTouchEnabled(true);
	
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	CCLayerColor* layer = CCLayerColor::layerWithColorWidthHeight( ccc4(0xFF, 0x00, 0x00, 0x80), 200, 200); 
	
	layer->setIsRelativeAnchorPoint(true);
	layer->setPosition( CCPointMake(s.width/2, s.height/2) );
	addChild(layer, 1, kTagLayer);
}
Beispiel #2
0
// on "init" you need to initialize your instance
bool Bug914Layer::init()
{
    // always call "super" init
    // Apple recommends to re-assign "self" with the "super" return value
    if (BugsTestBaseLayer::init())
    {
        setTouchEnabled(true);
        // ask director the the window size
        CCSize size = CCDirector::sharedDirector()->getWinSize();
        CCLayerColor *layer;
        for( int i=0;i < 5;i++)
        {
            layer = CCLayerColor::create(ccc4(i*20, i*20, i*20,255));
            layer->setContentSize(CCSizeMake(i*100, i*100));
            layer->setPosition(ccp(size.width/2, size.height/2));
            layer->setAnchorPoint(ccp(0.5f, 0.5f));
            layer->setIsRelativeAnchorPoint(true);
            addChild(layer, -1-i);
        }

        // create and initialize a Label
        CCLabelTTF *label = CCLabelTTF::create("Hello World", "Marker Felt", 64);
        CCMenuItem *item1 = CCMenuItemFont::create("restart", this, menu_selector(Bug914Layer::restart));

        CCMenu *menu = CCMenu::create(item1, NULL);
        menu->alignItemsVertically();
        menu->setPosition(ccp(size.width/2, 100));
        addChild(menu);

        // position the label on the center of the screen
        label->setPosition(ccp( size.width /2 , size.height/2 ));

        // add the label as a child to this Layer
        addChild(label);
        return true;
    }
    return false;
}