void ScreenSizeManager::DoInitFixedScreenSize(float myScreenWidth,
                                              float myScreenHeight)
{
    _isInit = true;
    // cocos2d-x v3.0.0 이상만 지원.
    CCAssert(0x00030000 <= COCOS2D_VERSION, "ScreenSizeManager need to cocos2d-x 3.0.0 or higher!");
    
    Director* kDirector = CCDirector::getInstance();
    
    CCAssert(kDirector->getOpenGLView(), "ScreenSizeManager need to kDirector->getOpenGLView() is not NULL");
    
    Size kWinSize = kDirector->getWinSize();
    
    _screenSize.width = kWinSize.width;
    _screenSize.height = kWinSize.height;
    
    _imageResolutionSize.width = myScreenWidth;
    _imageResolutionSize.height = myScreenHeight;
    
    log("DoInitFixedScreenSizeManager %f %f", _imageResolutionSize.width, _imageResolutionSize.height);
    
    // Cocos2d상의 포인트영역이 _imageResolutionSize.width, _imageResolutionSize.height 으로 설정된다.
    // CCDirector::sharedDirector()->getWinSize()의 width, height 가 _imageResolutionSize.width, _imageResolutionSize.height 로 된다.
    
    ResolutionPolicy kResolutionPolicy = ResolutionPolicy::NO_BORDER;
    
    GLView* kGLView = kDirector->getOpenGLView();
    kGLView->setDesignResolutionSize(_imageResolutionSize.width, _imageResolutionSize.height, kResolutionPolicy);
    
    
}
Пример #2
0
bool Scene::initWithPhysics()
{
#if CC_USE_PHYSICS
    _physicsWorld = PhysicsWorld::construct(this);
#endif
    
    bool ret = false;
    do
    {
        Director * director;
        CC_BREAK_IF( ! (director = Director::getInstance()) );
        
        this->setContentSize(director->getWinSize());
        
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
        Physics3DWorldDes info;
        CC_BREAK_IF(! (_physics3DWorld = Physics3DWorld::create(&info)));
        _physics3DWorld->retain();
#endif
        
        // success
        ret = true;
    } while (0);
    return ret;
}
Пример #3
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    Director* director = Director::getInstance();
    EGLView* glView = EGLView::getInstance();

    director->setOpenGLView(glView);
    
    Size size = director->getWinSize();

	setDesignResolution();

    // Set the design resolution
	glView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
	
    // turn on display FPS
    //director->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    // create a scene. it's an autorelease object
#if(CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
	Scene *scene = MainTitleScene::create();
#else
    Scene *scene = HelloWorld::scene();
#endif
    // run
    director->runWithScene(scene);

    return true;
}
Пример #4
0
void WelcomeMenu::_startGameMenuCallback(Ref* pSender)
{
    Director* director = Director::getInstance();
    GLView*   glView   = director->getOpenGLView();
    Size frameSize      = glView->getFrameSize();
    Size winSize       = director->getWinSize();
    log("winSize %f=%f ",winSize.width, winSize.height );
    log("frameSize %f=%f", frameSize.width, frameSize.height);
}
Пример #5
0
Size Screen::getFullScreenSize(float scale) {
    if (0.0f == scale) {
        return Size::ZERO;
    }
    Director* director = Director::getInstance();
    Size windowSize = director->getWinSize();
    windowSize.width *= scale;
    windowSize.height *= scale;
    return windowSize;
}
Пример #6
0
bool Layer::init()
{
    bool ret = false;
    do 
    {        
        Director * director;
        CC_BREAK_IF(!(director = Director::getInstance()));
        this->setContentSize(director->getWinSize());
        // success
        ret = true;
    } while(0);
    return ret;
}
void ScreenSizeManager::DoInitFlexibleScreenSize(float myImageResolutionWidth,
                                                 float myImageResolutionHeight)
{
    _isInit = true;
    // cocos2d-x v3.0.0 이상만 지원.
    CCAssert(0x00030000 <= COCOS2D_VERSION, "ScreenSizeManager need to cocos2d-x 3.0.0 or higher!");
    
    Director* kDirector = Director::getInstance();
    
    CCAssert(kDirector->getOpenGLView(), "ScreenSizeManager need to kDirector->getOpenGLView() is not NULL");
    
    Size kWinSize = kDirector->getWinSize();
    
    _screenSize.width = kWinSize.width;
    _screenSize.height = kWinSize.height;
    
    _imageResolutionSize.width = myImageResolutionWidth;
    _imageResolutionSize.height = myImageResolutionHeight;
    
    float kDefaultDesignResRatio = _imageResolutionSize.width / _imageResolutionSize.height;
    float kScreenRatio = _screenSize.width / _screenSize.height;
    
    if ( kDefaultDesignResRatio <= kScreenRatio)
    {
        float kHeightRatio = _screenSize.height  / _imageResolutionSize.height;
        // 폭이 넓은 경우
        _imageResolutionSize.width = (int)(_screenSize.width / kHeightRatio);
        _isScaleHeight = true;
    }
    else
    {
        // 높이가 긴 경우
        float kWidthRatio = _screenSize.width / _imageResolutionSize.width;
        // 폭이 넓은 경우
        _imageResolutionSize.height = (int)(_screenSize.height  / kWidthRatio);
        _isScaleHeight = false;
    }
    
    log("DoInitResourceSizeScreen %f %f", _imageResolutionSize.width, _imageResolutionSize.height);
    
    // Cocos2d상의 포인트영역이 _imageResolutionSize.width, _imageResolutionSize.height 으로 설정된다.
    // CCDirector::sharedDirector()->getWinSize()의 width, height 가 _imageResolutionSize.width, _imageResolutionSize.height 로 된다.
    ResolutionPolicy kResolutionPolicy = ResolutionPolicy::NO_BORDER;
   
    GLView* kGLView = kDirector->getOpenGLView();
    kGLView->setDesignResolutionSize(_imageResolutionSize.width, _imageResolutionSize.height, kResolutionPolicy);
  
    
}
Пример #8
0
bool Layer::init()
{
    bool bRet = false;
    do 
    {        
        Director * pDirector;
        CC_BREAK_IF(!(pDirector = Director::getInstance()));
        this->setContentSize(pDirector->getWinSize());
        setTouchEnabled(false);
        setAccelerometerEnabled(false);
        // success
        bRet = true;
    } while(0);
    return bRet;
}
bool MapScene::init()
{
	if (!Scene::init()){
		return false;
	}

	Director *director = Director::getInstance();
	Size winSize = director->getWinSize();

	Layer *mapLayer = Layer::create();

	Sprite *map = Sprite::create("Map/Main_Main.png");
	map->setAnchorPoint(Vec2::ZERO);
	mapLayer->addChild(map);

	Sprite *regionNormal = Sprite::create("Map/Main_flag.png");
	Sprite *regionSelected = Sprite::create("Map/Main_flag.png");
	regionSelected->setScale(1.2f);
	std::function<void(Ref *ref)>
		onRegionTouched = [this](Ref *ref)->void
	{
		if (_readyMenu) {
			delete _readyMenu;
			_readyMenu = nullptr;
		}
		RegionInfo regionInfo;
		HeroInfo heroInfo;
		regionInfo.stageName = "Stage1.json";
		heroInfo.heroName = "normal";
		_readyMenu = new ReadyMenu(regionInfo, heroInfo);
		Layer *readyLayer = _readyMenu->getLayer();
		addChild(readyLayer);
	};
	MenuItemSprite *regionMenuItem = MenuItemSprite::create(regionNormal, regionSelected, onRegionTouched);
	Menu *regionMenu = Menu::create(regionMenuItem, nullptr);
	regionMenu->setPosition(Vec2(700.0f, 220.0f));
	mapLayer->addChild(regionMenu);

	ScrollView *scrollView = ScrollView::create(winSize, mapLayer);
	scrollView->setTouchEnabled(true);
	scrollView->setContentSize(map->getContentSize());
	scrollView->setPosition(Vec2::ZERO);
	scrollView->setDirection(ScrollView::Direction::BOTH);
	scrollView->setBounceable(false);
	addChild(scrollView);
    
	return true;
}
Пример #10
0
bool Scene::initWithPhysics()
{
    bool ret = false;
    do
    {
        Director * director;
        CC_BREAK_IF( ! (director = Director::getInstance()) );

        this->setContentSize(director->getWinSize());
        CC_BREAK_IF(! (_physicsWorld = PhysicsWorld::construct(*this)));

        // success
        ret = true;
    } while (0);
    return ret;
}
            void WebViewImpl::draw(Renderer *renderer, Mat4 const &transform, uint32_t flags)
            {
                if (_createSucceeded && (flags & Node::FLAGS_TRANSFORM_DIRTY))
                {
                    Director *directorInstance = cocos2d::Director::getInstance();
                    GLView *glView = directorInstance->getOpenGLView();
                    const Size &frameSize = glView->getFrameSize();
                    const Size &winSize = directorInstance->getWinSize();
                    Vec2 leftBottom = this->_webView->convertToWorldSpace(Point::ZERO);
                    Vec2 rightTop = this->_webView->convertToWorldSpace(Point(_webView->getContentSize().width, _webView->getContentSize().height));
                    float uiLeft = frameSize.width / 2 + (leftBottom.x - winSize.width / 2) * glView->getScaleX();
                    float uiTop = frameSize.height / 2 - (rightTop.y - winSize.height / 2) * glView->getScaleY();

                    _systemWebControl->setWebViewRect(uiLeft, uiTop,
                        (rightTop.x - leftBottom.x) * glView->getScaleX(),
                        (rightTop.y - leftBottom.y) * glView->getScaleY());
                }
            }
Пример #12
0
// on "init" you need to initialize your instance
bool LogoLayer::init()
{
    if ( !Layer::init() )
    {
        return false;
    }

    Sprite* logo = Sprite::create("logo.png");
    
    Director* director = Director::getInstance();
    Size winSize = director->getWinSize();
    logo->setPosition(Point(winSize.width * 0.5, winSize.height * 0.5));
    addChild(logo);
    
    EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
    listener->onTouchBegan = CC_CALLBACK_2(LogoLayer::onTouchBegan, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, logo);
    
    return true;
}
bool PhysicsNode::initWithPhysics()
{
    bool ret = false;
//    ret = Scene::initWithPhysics();
    
    do
    {
        Director * director;
        CC_BREAK_IF( ! (director = Director::getInstance()) );
        this->setContentSize(director->getWinSize());
        CC_BREAK_IF(! (_physicsWorld = spritebuilder::CCBPhysicsWorld::construct(*this)));
        
        this->scheduleUpdate();
        // success
        ret = true;
    } while (0);
    return ret;
    
    this->setContentSize(Size(0, 0));
    //this->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);

    return ret;
}
Пример #14
0
bool Layer::init()
{
    Director * director = Director::getInstance();
    setContentSize(director->getWinSize());
    return true;
}
Пример #15
0
Position Screen::getEdgePosition(int zorder) {
    Director* director = Director::getInstance();
    Size windowSize = director->getWinSize();
    return Position(Vec2(windowSize.width, windowSize.height), zorder);
}
Пример #16
0
Scene* SceneManager::generateLevel(int levelIndex, int score)
{
	if (levelIndex == 0) {
		Director* director = Director::getInstance();

		float height = director->getWinSize().height;
		float width = director->getWinSize().width;

		// Create start scene
		ParallaxBackground* bckMenu = new ParallaxBackground();
		bckMenu->addImage("night.png", Vec2(width / 2, height / 1.3), Vec2(0.05, 0));
		bckMenu->addImage("city.png", Vec2(width / 2, height / 1.6), Vec2(0.3, 0));
		bckMenu->addImage("street.png", Vec2(width / 2, height / 2.6), Vec2(1.0, 0), true);
		bckMenu->scheduleUpdate();

		auto startScene = IntermediaryScene::create(IntermediaryScene::MENU);
		startScene->setBackground(bckMenu);

		// Create dummy player
		auto dummy = DummyPlayer::create();
		dummy->setPosition(Vec2(width / 2, 130));
		startScene->setPlayer(dummy);

		// Create music
		CocosDenshion::SimpleAudioEngine* audioEngine = CocosDenshion::SimpleAudioEngine::getInstance();
		audioEngine->playBackgroundMusic("level0.mp3", true);

		Label* playButtonLabel = Label::createWithTTF("Play", "font.ttf", 35);
		MenuItem* playButton = MenuItemLabel::create(playButtonLabel, [&](Ref* sender){SceneManager::getInstance().fillStack();});

		Label* optionsButtonLabel = Label::createWithTTF("Options", "font.ttf", 35);
		MenuItem* optionsButton = MenuItemLabel::create(optionsButtonLabel);

		Label* exitButtonLabel = Label::createWithTTF("Exit", "font.ttf", 35);
		MenuItem* exitButton = MenuItemLabel::create(exitButtonLabel, [&](Ref* sender){Director::getInstance()->end(); });

		startScene->addMenuItem(playButton);
		startScene->addMenuItem(optionsButton);
		startScene->addMenuItem(exitButton);
		startScene->createMenu();

		return startScene;
	}
	if (levelIndex == 1) {
		Director* director = Director::getInstance();

		// Create a new GameLayer
		GameLayer* firstLevelLayer = GameLayer::create();

		// Create a background
		ParallaxBackground* bckFirstLevel = new ParallaxBackground();

		float height = director->getWinSize().height;
		float width = director->getWinSize().width;

		// Create animations and bullets
		bckFirstLevel->addImage("night.png", Vec2(width / 2, height / 1.3), Vec2(0.05, 0));
		bckFirstLevel->addImage("city.png", Vec2(width / 2, height / 1.6), Vec2(0.3, 0));
		bckFirstLevel->addImage("street.png", Vec2(width / 2, height / 2.6), Vec2(1.0, 0),true);
		bckFirstLevel->scheduleUpdate();

		// Create music
		CocosDenshion::SimpleAudioEngine* audioEngine = CocosDenshion::SimpleAudioEngine::getInstance();
		audioEngine->playBackgroundMusic("level1.mp3", true);

		// Create player
		Player* hero = Player::create();
		hero->setPosition(Vec2(width / 2, 130));
		hero->setTag(PLAYER_TAG);
		hero->setScore(score);

		// Create boss
		Boss* boss = Boss::create(OBJECT_FIRSTBOSS);

		BossCannon* cannon1 = BossCannon::create(OBJECT_FIRSTBOSS_CANNON_1, OBJECT_FIRSTBOSS_CANNON_1_D, OBJECT_BOSSBULLET_LASER);
		cannon1->setPosition(Vec2(123, 105));
		cannon1->setFireMethod(1, 10, 50);

		BossCannon* cannon2 = BossCannon::create(OBJECT_FIRSTBOSS_CANNON_2, OBJECT_FIRSTBOSS_CANNON_2_D, OBJECT_BOSSBULLET_SPIKEBALL);
		cannon2->setPosition(Vec2(150, 183));
		cannon2->setFireMethod(2, 10, 50);

		BossCannon* cannon3 = BossCannon::create(OBJECT_FIRSTBOSS_CANNON_3, OBJECT_FIRSTBOSS_CANNON_3_D, OBJECT_BOSSBULLET_BALL);
		cannon3->setPosition(Vec2(59, 148));
		cannon3->setFireMethod(3, 3, 50);

		boss->addCannon(1, cannon2);
		boss->addCannon(2, cannon1);
		boss->addCannon(3, cannon3);

		// Create Interactive object factory
		InteractiveObjectFactory* mailboxFactory = InteractiveObjectFactory::create(OBJECT_MAILBOX, director->getWinSize().height * 1.6 / 800, false, MAILBOX_COLLISION_BITMASK, true, false, true);
		mailboxFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		mailboxFactory->setSpawnFrequency(5);
		mailboxFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));

		InteractiveObjectFactory* rocketFactory = InteractiveObjectFactory::create(OBJECT_ROCKET, director->getWinSize().height * 1.6 / 800, false, ROCKET_COLLISION_BITMASK, true, false, false);
		rocketFactory->setPositionInterval(Vec2(100, height));
		rocketFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 25.0 / 800), 0));
		rocketFactory->setSpawnFrequency(20);

		InteractiveObjectFactory* spikesFactory = InteractiveObjectFactory::create(OBJECT_SPIKES, director->getWinSize().height * 0.5 / 800, false, SPIKES_COLLISION_BITMASK, false, true, true);
		spikesFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		spikesFactory->setSpawnFrequency(5);
		spikesFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));


		firstLevelLayer->setBackground(bckFirstLevel);
		firstLevelLayer->setPlayer(hero);
		firstLevelLayer->setBoss(boss);
		firstLevelLayer->setDistanceToBoss(1000);
		firstLevelLayer->addObjectFactory(mailboxFactory);
		firstLevelLayer->addObjectFactory(rocketFactory);
		firstLevelLayer->addObjectFactory(spikesFactory);

		//Create Scene
		GameLevel* firstLevel = GameLevel::create(firstLevelLayer);

		return firstLevel;
	}
	if (levelIndex == 2)
	{
		Director* director = Director::getInstance();

		// Create a new GameLayer
		GameLayer* secondLevelLayer = GameLayer::create();

		// Create a background
		ParallaxBackground* bckSecondLevel = new ParallaxBackground();

		float height = director->getWinSize().height;
		float width = director->getWinSize().width;

		// Create animations and bullets
		bckSecondLevel->addImage("night.png", Vec2(width / 2, height / 1.3), Vec2(0.05, 0));
		bckSecondLevel->addImage("city.png", Vec2(width / 2, height / 1.6), Vec2(0.3, 0));
		bckSecondLevel->addImage("street.png", Vec2(width / 2, height / 2.6), Vec2(1.0, 0), true);
		bckSecondLevel->scheduleUpdate();

		// Create music
		CocosDenshion::SimpleAudioEngine* audioEngine = CocosDenshion::SimpleAudioEngine::getInstance();
		audioEngine->playBackgroundMusic("level2.mp3", true);

		// Create player
		Player* hero = Player::create();
		hero->setPosition(Vec2(width / 2, 130));
		hero->setTag(PLAYER_TAG);
		hero->setScore(score);

		// Create boss
		Boss* boss = Boss::create(OBJECT_SECONDBOSS,true);

		BossCannon* cannon1 = BossCannon::create(OBJECT_SECONDBOSS_CANNON_1, OBJECT_SECONDBOSS_CANNON_1_D, OBJECT_BOSSBULLET_ENERGYBALL);
		cannon1->setPosition(Vec2(85, 38));
		cannon1->setFireMethod(1, 10, 50);

		BossCannon* cannon2 = BossCannon::create(OBJECT_SECONDBOSS_CANNON_2, OBJECT_SECONDBOSS_CANNON_2_D, OBJECT_BOSSBULLET_SAWBLADE);
		cannon2->setPosition(Vec2(34, 137));
		cannon2->setFireMethod(2, 10, 50);

		BossCannon* cannon3 = BossCannon::create(OBJECT_SECONDBOSS_CANNON_3, OBJECT_SECONDBOSS_CANNON_3_D, OBJECT_BOSSBULLET_FLAMEBALL);
		cannon3->setPosition(Vec2(20, 135));
		cannon3->setFireMethod(3, 3, 50);

		boss->addCannon(1, cannon1);
		boss->addCannon(2, cannon2);
		boss->addCannon(3, cannon3);

		// Create Interactive object factory
		InteractiveObjectFactory* mailboxFactory = InteractiveObjectFactory::create(OBJECT_MAILBOX, director->getWinSize().height * 1.6 / 800, false, MAILBOX_COLLISION_BITMASK, true, false, true);
		mailboxFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		mailboxFactory->setSpawnFrequency(5);
		mailboxFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));

		InteractiveObjectFactory* rocketFactory = InteractiveObjectFactory::create(OBJECT_ROCKET, director->getWinSize().height * 1.6 / 800, false, ROCKET_COLLISION_BITMASK, true, false, false);
		rocketFactory->setPositionInterval(Vec2(100, height));
		rocketFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 25.0 / 800), 0));
		rocketFactory->setSpawnFrequency(20);

		InteractiveObjectFactory* spikesFactory = InteractiveObjectFactory::create(OBJECT_SPIKES, director->getWinSize().height * 0.5 / 800, false, SPIKES_COLLISION_BITMASK, false, true, true);
		spikesFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		spikesFactory->setSpawnFrequency(5);
		spikesFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));


		secondLevelLayer->setBackground(bckSecondLevel);
		secondLevelLayer->setPlayer(hero);
		secondLevelLayer->setBoss(boss);
		secondLevelLayer->setDistanceToBoss(100);
		secondLevelLayer->addObjectFactory(mailboxFactory);
		secondLevelLayer->addObjectFactory(rocketFactory);
		secondLevelLayer->addObjectFactory(spikesFactory);

		//Create Scene
		GameLevel* firstLevel = GameLevel::create(secondLevelLayer);

		return firstLevel;
	}
	if (levelIndex == 3)
	{
		Director* director = Director::getInstance();

		// Create a new GameLayer
		GameLayer* thirdLevelLayer = GameLayer::create();

		// Create a background
		ParallaxBackground* bckThirdLevel = new ParallaxBackground();

		float height = director->getWinSize().height;
		float width = director->getWinSize().width;

		// Create animations and bullets
		bckThirdLevel->addImage("night.png", Vec2(width / 2, height / 1.3), Vec2(0.05, 0));
		bckThirdLevel->addImage("city.png", Vec2(width / 2, height / 1.6), Vec2(0.3, 0));
		bckThirdLevel->addImage("street.png", Vec2(width / 2, height / 2.6), Vec2(1.0, 0), true);
		bckThirdLevel->scheduleUpdate();

		// Create music
		CocosDenshion::SimpleAudioEngine* audioEngine = CocosDenshion::SimpleAudioEngine::getInstance();
		audioEngine->playBackgroundMusic("level3.mp3", true);

		// Create player
		Player* hero = Player::create();
		hero->setPosition(Vec2(width / 2, 130));
		hero->setTag(PLAYER_TAG);
		hero->setScore(score);

		// Create boss
		Boss* boss = Boss::create(OBJECT_THIRDBOSS);

		BossCannon* cannon1 = BossCannon::create(OBJECT_THIRDBOSS_CANNON_1, OBJECT_THIRDBOSS_CANNON_1_D, OBJECT_BOSSBULLET_BOMB);
		cannon1->setPosition(Vec2(68, 218));
		cannon1->setFireMethod(2, 10, 10);

		BossCannon* cannon2 = BossCannon::create(OBJECT_THIRDBOSS_CANNON_2, OBJECT_THIRDBOSS_CANNON_2_D, OBJECT_BOSSBULLET_RASENGAN);
		cannon2->setPosition(Vec2(28, 148));
		cannon2->setFireMethod(3, 1, 10);

		boss->addCannon(1, cannon1);
		boss->addCannon(2, cannon2);

		// Create Interactive object factory
		InteractiveObjectFactory* mailboxFactory = InteractiveObjectFactory::create(OBJECT_MAILBOX, director->getWinSize().height * 1.6 / 800, false, MAILBOX_COLLISION_BITMASK, true, false, true);
		mailboxFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		mailboxFactory->setSpawnFrequency(5);
		mailboxFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));

		InteractiveObjectFactory* rocketFactory = InteractiveObjectFactory::create(OBJECT_ROCKET, director->getWinSize().height * 1.6 / 800, false, ROCKET_COLLISION_BITMASK, true, false, false);
		rocketFactory->setPositionInterval(Vec2(100, height));
		rocketFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 25.0 / 800), 0));
		rocketFactory->setSpawnFrequency(20);

		InteractiveObjectFactory* spikesFactory = InteractiveObjectFactory::create(OBJECT_SPIKES, director->getWinSize().height * 0.5 / 800, false, SPIKES_COLLISION_BITMASK, false, true, true);
		spikesFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		spikesFactory->setSpawnFrequency(5);
		spikesFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));

		thirdLevelLayer->setBackground(bckThirdLevel);
		thirdLevelLayer->setPlayer(hero);
		thirdLevelLayer->setBoss(boss);
		thirdLevelLayer->setDistanceToBoss(1000);
		thirdLevelLayer->addObjectFactory(mailboxFactory);
		thirdLevelLayer->addObjectFactory(rocketFactory);
		thirdLevelLayer->addObjectFactory(spikesFactory);

		//Create Scene
		GameLevel* firstLevel = GameLevel::create(thirdLevelLayer);

		return firstLevel;
	}

	return nullptr;
}
Пример #17
0
Position Screen::getCenterPosition(int zorder) {
    Director* director = Director::getInstance();
    Size windowSize = director->getWinSize();
    return Position(Vec2(windowSize.width * 0.5f, windowSize.height * 0.5f), zorder);
}
Пример #18
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    Director* pDirector = gDirector;
    
    GLView* pGLView = pDirector->getOpenGLView();
    if( NULL == pGLView )
    {
        pGLView = GLView::create("game(v1.0.0.0)---test for inner");
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
        pGLView->setFrameSize(1334, 750);
#endif
        
        pDirector->setOpenGLView(pGLView);
    }
    
    // turn on display FPS
    pDirector->setDisplayStats(true);
    
    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);
    
    // resolution information  
    Size size;  
    size= pDirector->getWinSize();
	log("***IDONG: Director getWinSize:w=%f,h=%f",size.width,size.height);  

	size = pDirector->getWinSizeInPixels();  
	log("***IDONG: Director getWinSizeInPixels:w=%f,h=%f",size.width,size.height);  

	size = pDirector->getVisibleSize();  
	log("***IDONG: Director getVisibleSize:w=%f,h=%f",size.width,size.height);  

	Point point = pDirector->getVisibleOrigin();  
	log("***IDONG: Director getVisibleOrigin:x=%f,y=%f",point.x,point.y);  


	log("***IDONG: Director BS: getContentScaleFactor: scaleFactor=%f",pDirector->getContentScaleFactor());  

	auto framsize = pGLView->getFrameSize();
	auto dwinsize = pDirector->getWinSize();
	auto designsize = Size(SCREEN_WIDTH, SCREEN_HEIGHT);
	auto widthRate = framsize.width/designsize.width;
	auto heightRate = framsize.height/designsize.height;

	auto  resolutionRate = 1.f;
	if(widthRate > heightRate) 
	{
		pGLView->setDesignResolutionSize(designsize.width,
		 designsize.height*heightRate/widthRate, ResolutionPolicy::NO_BORDER);
		 resolutionRate = heightRate/widthRate;
	}
	else
	{
		pGLView->setDesignResolutionSize(designsize.width*widthRate/heightRate, designsize.height,
		 ResolutionPolicy::NO_BORDER);
		 resolutionRate = widthRate/heightRate;
	}

	//pGLView->setDesignResolutionSize(SCREEN_WIDTH, SCREEN_HEIGHT, ResolutionPolicy::FIXED_HEIGHT);

	log("***IDONG:/n");  
	log("***IDONG: Director AS: getContentScaleFactor: scaleFactor=%f",pDirector->getContentScaleFactor());  

	size= pDirector->getWinSize();  
	log("***IDONG: Director getWinSize:w=%f,h=%f",size.width,size.height);  

	size = pDirector->getWinSizeInPixels();  
	log("***IDONG: Director getWinSizeInPixels:w=%f,h=%f",size.width,size.height);  

	size = pDirector->getVisibleSize();  
	log("***IDONG: Director getVisibleSize:w=%f,h=%f",size.width,size.height);  

	point = pDirector->getVisibleOrigin();  
	log("***IDONG: Director getVisibleOrigin:x=%f,y=%f",point.x,point.y);  

	// ‘ˆº”À—À˜¬∑æ∂
	gFileUtils->addSearchPath("assets");

	// …Ë÷√◊ ‘¥ƒø¬�?
	// ≥ı ºªØ◊ ‘¥ƒø¬�?dumpŒƒº˛…˙≥…ƒø¬�?
	string logfile = "";
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
	gGameManager->SetResourceRoot("/mnt/sdcard/com.zm.mszb/");
	gGameManager->CreateDirectory(gGameManager->GetResourceRoot());
	gGameManager->CreateDirectory(gGameManager->GetLogPath());
	logfile = gGameManager->GetLogPath()+"/log.txt";
	gLog->Open(logfile.c_str());
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
	gGameManager->SetResourceRoot("");
	gGameManager->CreateDirectory(gGameManager->GetResourceRoot());
	gGameManager->CreateDirectory(gGameManager->GetLogPath());
	logfile = gGameManager->GetLogPath()+"/log.txt";
	gLog->Open(logfile.c_str());
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
	gGameManager->SetResourceRoot(gFileUtils->getWritablePath());
	gGameManager->CreateDirectory(gGameManager->GetResourceRoot());
	gGameManager->CreateDirectory(gGameManager->GetLogPath());
	logfile = gGameManager->GetLogPath()+"/log.txt";
	gLog->Open(logfile.c_str());
#endif
	gGameManager->LogMachineInfo();
	// ø™ º∏¸–�?
	gGameManager->Start();

    return true;
}