GamePlayingScene* GamePlayingScene::createScene(){ auto thisScene = new GamePlayingScene(); thisScene->autorelease(); thisScene->initWithPhysics(); thisScene->initial(); return thisScene; }
bool MainScene::init() { if (!Scene::init()) return false; if (initWithPhysics()) { Global *global = Global::getInstance(); //添加主层 MainLayer *mainLayer = MainLayer::create(); this->addChild(mainLayer); Size visibleSize = Director::getInstance()->getVisibleSize(); //在主层初始化前设置相机,并给主场景增加相机 global->multiBtn= MultiFuncButton::create(); global->multiBtn->setBoundingGear("images/bounding.png"); global->multiBtn->setDirGear("images/testUI01.png"); global->multiBtn->setPowerGear("images/testUI01.png"); global->multiBtn->setFireButton("images/button.png"); //还有一个装饰的大齿轮,素材没调好,不展示 global->multiBtn->setIsEnable(true); global->multiBtn->setStep(90.f); global->multiBtn->setScale(0.5f); global->multiBtn->setPosition(visibleSize.width - 80, visibleSize.height / 2 - 120);//位置调整要在后 this->addChild(global->multiBtn); Size size = Director::getInstance()->getWinSize(); global->_physics3DWorld = this->getPhysics3DWorld(); global->_camera = Camera::createPerspective(30.0f, size.width / size.height, 1.0f, 1000.0f); global->_camera->setPosition3D(Vec3(0.0f, 80.0f, 160.0f)); global->_camera->lookAt(Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f)); global->_camera->setCameraFlag(CameraFlag::USER1); this->addChild(global->_camera); setPhysics3DDebugCamera(global->_camera); _navMesh = NavMesh::create("mesh/all_tiles_tilecache.bin", "mesh/geomset.txt"); _navMesh->setDebugDrawEnable(true); setNavMesh(_navMesh); setNavMeshDebugCamera(global->_camera); //创建主角 // global->_playerObj = Player::create("model/girl.c3b"); } return true; }
bool Physics3DTestDemo::init() { if (!TestCase::init()) return false; if (initWithPhysics()) { getPhysics3DWorld()->setDebugDrawEnable(false); physicsScene = this; Size size = Director::getInstance()->getWinSize(); _camera = Camera::createPerspective(30.0f, size.width / size.height, 1.0f, 1000.0f); _camera->setPosition3D(Vec3(0.0f, 50.0f, 100.0f)); _camera->lookAt(Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f)); _camera->setCameraFlag(CameraFlag::USER1); this->addChild(_camera); auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan = CC_CALLBACK_2(Physics3DTestDemo::onTouchesBegan, this); listener->onTouchesMoved = CC_CALLBACK_2(Physics3DTestDemo::onTouchesMoved, this); listener->onTouchesEnded = CC_CALLBACK_2(Physics3DTestDemo::onTouchesEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); TTFConfig ttfConfig("fonts/arial.ttf", 10); auto label = Label::createWithTTF(ttfConfig,"DebugDraw OFF"); auto menuItem = MenuItemLabel::create(label, [=](Ref *ref){ if (getPhysics3DWorld()->isDebugDrawEnabled()){ getPhysics3DWorld()->setDebugDrawEnable(false); label->setString("DebugDraw OFF"); }else{ getPhysics3DWorld()->setDebugDrawEnable(true); label->setString("DebugDraw ON"); } }); auto menu = Menu::create(menuItem, nullptr); menu->setPosition(Vec2::ZERO); menuItem->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT); menuItem->setPosition( Vec2(VisibleRect::left().x, VisibleRect::top().y-50) ); this->addChild(menu); _angle = 0.0f; return true; } physicsScene = nullptr; return false; }