void BaseDemo::onEnter() { Layer::onEnter(); auto demo_info_label = LabelTTF::create(demo_info(), "Helvetica", 20, Size(500, 200), TextHAlignment::LEFT); this->addChild(demo_info_label); demo_info_label->setAnchorPoint(Point(0.0f, 1.0f)); demo_info_label->setColor(Color3B(255, 255, 255)); demo_info_label->setPosition(VisibleRect::leftTop() + Point(60, -60)); }
bool HitMeScene::init() { if (!Layer::init()) { return false; } Size size = VisibleRect::getVisibleRect().size; _bgColorLayer = LayerColor::create(Color4B(0, 0, 0, 255)); addChild(_bgColorLayer); //加入封闭的盒子,用作墙壁 auto body = PhysicsBody::createEdgeBox(size, PHYSICSBODY_MATERIAL_DEFAULT, 3); body->setContactTestBitmask(0x000001); auto wallNode = Node::create(); wallNode->setPosition(size.width/2, size.height/2); wallNode->setPhysicsBody(body); this->addChild(wallNode); auto demo_info_label = Label::create(demo_info(), "Helvetica", 25, Size(500, 200), TextHAlignment::LEFT); this->addChild(demo_info_label); demo_info_label->setAnchorPoint(Point(0.0f, 1.0f)); demo_info_label->setColor(Color3B(255, 255, 255)); demo_info_label->setPosition(VisibleRect::leftTop() + Point(60, -60)); _hitItem = MenuItemImage::create("hit_me.png", "hit_me.png", CC_CALLBACK_1(HitMeScene::hitMeFire, this)); auto backMenuItem = MenuItemImage::create("backNormal.png", "backSelected.png", CC_CALLBACK_1(HitMeScene::backCallback, this)); auto restartMenuItem = MenuItemImage::create("refreshNormal.png", "refreshSelected.png", CC_CALLBACK_1(HitMeScene::restartCallback, this)); _hitItem->setPosition(VisibleRect::center()); restartMenuItem->setPosition(VisibleRect::rightTop() + Point(-200, -80)); backMenuItem->setPosition(restartMenuItem->getPosition() + Point(90, 0)); auto menu = Menu::create(backMenuItem, restartMenuItem, _hitItem, NULL); menu->setPosition(Point::ZERO); this->addChild(menu, 300); setPhysicsForHitItem(); auto contactListener = EventListenerPhysicsContact::create(); contactListener->onContactBegin = CC_CALLBACK_1(HitMeScene::onContactBegin, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(contactListener, this); return true; }
bool PRKitDemoScene::init() { if(!Layer::init()) { return false; } auto color_bg = LayerColor::create(Color4B(125, 125, 125, 125)); addChild(color_bg); auto demo_info_label = Label::create(demo_info(), "Helvetica", 25, Size(500, 200), TextHAlignment::LEFT); this->addChild(demo_info_label); demo_info_label->setAnchorPoint(Point(0.0f, 1.0f)); demo_info_label->setColor(Color3B(255, 255, 255)); demo_info_label->setPosition(VisibleRect::leftTop() + Point(60, -60)); auto backMenuItem = MenuItemImage::create("backNormal.png", "backSelected.png", CC_CALLBACK_1(PRKitDemoScene::backCallback, this)); auto restartMenuItem = MenuItemImage::create("refreshNormal.png", "refreshSelected.png", CC_CALLBACK_1(PRKitDemoScene::restartCallback, this)); restartMenuItem->setPosition(VisibleRect::rightTop() + Point(-200, -80)); backMenuItem->setPosition(restartMenuItem->getPosition() + Point(90, 0)); auto menu = Menu::create(backMenuItem, restartMenuItem, NULL); menu->setPosition(Point::ZERO); this->addChild(menu, 300); //--------------------- START Vector2dVector polygonPoints; polygonPoints.push_back(Vector2d(100, 100)); polygonPoints.push_back(Vector2d(200, 100)); polygonPoints.push_back(Vector2d(300, 200)); polygonPoints.push_back(Vector2d(400, 300)); polygonPoints.push_back(Vector2d(500, 500)); Texture2D *texture = Director::getInstance()->getTextureCache()->addImage("pattern1.png"); PRFilledPolygon *filledPolygon = PRFilledPolygon::filledPolygonWithPointsAndTexture(polygonPoints, texture); addChild(filledPolygon); //---------------------- END return true; }