Example #1
0
void LuaHostWin32::onViewChangeDirection(int directionMode)
{
    BOOL isLandscape = m_project.isLandscapeFrame();
    if ((directionMode == ID_VIEW_PORTRAIT && isLandscape) || (directionMode == ID_VIEW_LANDSCAPE && !isLandscape))
    {
        CCSize frameSize = m_project.getFrameSize();
        frameSize.setSize(frameSize.height, frameSize.width);
        relaunch();
    }
}
Example #2
0
// Initialize the right player's background for the main game scene
//
// return - false if there was an error in initializing, true otherwise
bool BackgroundRLayer::init()
{
    ClipNode* clipNode;               // boundary to clip the image if outside the boundary
    CCSize    screenSize;             // the size of the window
    CCSize    layerSize;              // size of this layer

    if(!CCLayer::init())
    {
        return false;
    }

    // get the window size from the director
    screenSize = CCDirector::sharedDirector()->getWinSize();

    // set layerSize to be the full height and half the width of screenSize, and position the layer to
    //   the right side of the screen
    layerSize.setSize(screenSize.width * POS_HALF_SCREEN, screenSize.height);
    setContentSize(layerSize);
    setPosition(screenSize.width * POS_HALF_SCREEN, 0);

    // create the clip node and add it
    clipNode = new ClipNode();
    clipNode->autorelease();
    clipNode->setPosition(0, 0);
    clipNode->setClipsToBounds(true);
    clipNode->setClippingRegion( CCRect(screenSize.width, 0, layerSize.width, layerSize.height) );
    addChild(clipNode);

    // create and add the first background sprite
    m_background1 = CCSprite::create(RIGHT_BACKGROUND);
    m_background1->setScale(screenSize.height / m_background1->boundingBox().size.height);
    m_background1->setPosition( ccp(getPosition().x, screenSize.height * POS_HALF_SCREEN) );
    clipNode->addChild(m_background1);

    // create, position before first background, and add the second background
    m_background2 = CCSprite::create(RIGHT_BACKGROUND);
    m_background2->setScale(screenSize.height / m_background2->boundingBox().size.height);
    m_background2->setPosition( ccp(getPosition().x - m_background2->boundingBox().size.width,
                                                           screenSize.height * POS_HALF_SCREEN) );
    clipNode->addChild(m_background2);

    return true;
}
Example #3
0
CCObject* CCSize::copyWithZone(CCZone* pZone)
{
    CCSize* pRet = new CCSize();
    pRet->setSize(this->width, this->width);
    return pRet;
}
Example #4
0
bool CPullMachHelpLayer::init()
{
	if (!CCLayer::init())
		return false;

	CCSize barDownSize;	//µ×Ãæ±ß¿ò³ß´ç
	CCSize barUpSize;	//ÉÏÃæ±ß¿ò³ß´ç
	CCSize infoBgSize;	//ÐÅÏ¢±³¾°³ß´ç
	CCSize infoViewSize;	//ÐÅÏ¢¿ÉÊӳߴç

	CCSprite * pSprite = NULL;
	if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Base, PullMach_Bg_Help_Bar_Down, pSprite))
	{
		barDownSize = pSprite->getContentSize();
		pSprite->setAnchorPoint(CCPointZero);
		pSprite->setPosition(CCPointZero);
		this->addChild(pSprite);
	}

	{
		float fHeight = this->getContentSize().height - 200;
		infoBgSize.setSize(barDownSize.width, (fHeight > 600) ? 600 : fHeight);
		CCLayerColor * bgLayer = CCLayerColor::create(ccc4(0, 24, 85, 255), infoBgSize.width, infoBgSize.height);
		bgLayer->setPosition(ccp(0, barDownSize.height));
		this->addChild(bgLayer);
	}

	if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Base, PullMach_Bg_Help_Bar_Up, pSprite))
	{
		barUpSize = pSprite->getContentSize();
		pSprite->setAnchorPoint(CCPointZero);
		pSprite->setPosition(ccp(0, barDownSize.height + infoBgSize.height));
		this->addChild(pSprite);
	}

	//Ìí¼Ó¹ö¶¯ÄÚÈÝ
	infoViewSize.setSize(infoBgSize.width - 20, infoBgSize.height);
	if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Base, PullMach_Bg_Help_Info, pSprite))
	{
		pSprite->setAnchorPoint(ccp(0.5f, 0.0f));
		pSprite->setPosition(ccp(infoViewSize.width / 2, 0));
	}

	CCLayerColor * layerColor = CCLayerColor::create(ccc4(0, 13, 32, 255), infoViewSize.width, pSprite->getContentSize().height);
	layerColor->setPosition(CCPointZero);
	layerColor->addChild(pSprite);

	m_pScroll = CCScrollView::create();
	m_pScroll->setViewSize(infoViewSize);
	m_pScroll->setPosition(ccp(10, barDownSize.height));
	m_pScroll->setDirection(kCCScrollViewDirectionVertical);
	m_pScroll->addChild(layerColor);
	m_pScroll->setContentSize(layerColor->getContentSize());
	m_pScroll->setContentOffset(m_pScroll->minContainerOffset());
	m_pScroll->setTouchPriority(kCCMenuHandlerPriority - 1);
	this->addChild(m_pScroll);

	this->setContentSize(CCSize(infoBgSize.width, barDownSize.height + barUpSize.height + infoBgSize.height));

	//Ìí¼Ó¹Ø±Õ°´Å¥
	CCControlButton* pCloseButton = m_pResManager->CreateControlButton(PullMach_Bt_Help_Close_N, PullMach_Bt_Help_Close_C);
	pCloseButton->setAnchorPoint(ccp(1, 1));
	pCloseButton->setPosition(getContentSize().width - 10, getContentSize().height - 4);
	pCloseButton->addTargetWithActionForControlEvents(this, cccontrol_selector(CPullMachHelpLayer::OnTouchClose), CCControlEventTouchUpInside);
	pCloseButton->setScaleX(1.5f);
	this->addChild(pCloseButton);

	return true;
}
Example #5
0
bool MyWorld::init()
{
	if (!oPlatformWorld::init())
	{
		return false;
	}

	this->setTouchEnabled(true);

	// Create Back Menu
	CCPoint visibleOrigin = CCEGLView::sharedOpenGLView()->getVisibleOrigin();
	CCSize visibleSize = CCEGLView::sharedOpenGLView()->getVisibleSize();
	CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(MyWorld::toExtensionsMainLayer));
	itemBack->setPosition(ccp(visibleOrigin.x+visibleSize.width - 50, visibleOrigin.y+25));
	CCMenu *menuBack = CCMenu::create(itemBack, NULL);
	menuBack->setPosition(CCPointZero);
	this->getUILayer()->addChild(menuBack);

	// Set Contact Info
	/* By default all groups won`t collide each other.
	 You could set the contact info before game start or
	 change it later.
	 Group number can only be 0 to 15.
	*/
	GROUP_TERRAIN = 0;
	GROUP_ONE = 1;
	GROUP_TWO = 2;
	GROUP_TEST_SENSOR = 15;
	this->setShouldContact(GROUP_TERRAIN, GROUP_TERRAIN, true);
	this->setShouldContact(GROUP_TWO, GROUP_TERRAIN, true);
	this->setShouldContact(GROUP_TEST_SENSOR, GROUP_ONE, true);// Body from GROUP_ONE will be detected by test sensor.

	// Create Borders
	oBodyDef* bodyDef = oBodyDef::create();
	bodyDef->type = b2_staticBody;
	vector<b2Vec2> vertices(5);
	vertices[0].Set(0, 0);
	vertices[1].Set(visibleSize.width, 0);
	vertices[2].Set(visibleSize.width, visibleSize.height);
	vertices[3].Set(0, visibleSize.height);
	vertices[4].Set(0, 0);
	bodyDef->attachChain(vertices, 0.4f, 0.4f);
	oBody* body = bodyDef->toBody(this, GROUP_TERRAIN, 0, 0, 0);
	CCSprite* sprite = CCSprite::create("Images/Icon.png");
	sprite->setPosition(ccp(100,40));
	body->addChild(sprite);
	this->addChild(body);

	// Create Body
	sprite = CCSprite::create("Images/Icon.png");
	CCSize size = sprite->getContentSize();
	bodyDef = oBodyDef::create();
	bodyDef->type = b2_dynamicBody;
	bodyDef->attachPolygon(size.width, size.height, 1.0f, 0.4f, 0.4f);//Body define use bodyDef->attach
	body = bodyDef->toBody(this, GROUP_ONE, visibleSize.width*0.5f-20.0f, visibleSize.height*0.5f+20.0f, 50.0f);
	//body->attach(CCBodyDef::polygon(size.width, size.height, 1.0f, 0.4f, 0.4f)); //Body instance use body->attach
	body->addChild(sprite);
	this->addChild(body);

	body = bodyDef->toBody(this, GROUP_TERRAIN, visibleSize.width*0.5f+50.0f, visibleSize.height*0.5f+20.0f);
	sprite = CCSprite::create("Images/Icon.png");
	sprite->runAction(
		CCRepeatForever::create(
			CCSequence::create(
				CCRotateTo::create(3.0f, 45),
				CCRotateTo::create(3.0f, 0),
				nullptr)));
	body->addChild(sprite);
	this->addChild(body);

	// Create Test Sensor
	int SENSOR_TAG = 1;
	bodyDef = oBodyDef::create();
	bodyDef->type = b2_staticBody;
	//bodyDef->attachPolygonSensor(SENSOR_TAG, visibleSize.width, 40.0f);
	body = bodyDef->toBody(this, GROUP_TEST_SENSOR, visibleSize.width*0.5f, 20.0f);
	//CCSensor* sensor = body->getSensorByTag(SENSOR_TAG);
	oSensor* sensor = body->attachSensor(SENSOR_TAG, oBodyDef::polygon(visibleSize.width, 40.0f));

	oSharedEffectCache.load("main.effect");

	sensor->bodyEnter += [&](oSensor* sensor, oBody* body)
	{
		// When body enters sensor area, remove the body
		//body->getParent()->removeChild(body);
		this->query(CCRect(0.0f,0.0f,100.0f,100.0f), [&](oBody* body)
		{
			if (body->getGroup() != GROUP_TERRAIN)
			{
				body->getParent()->removeChild(body);
				return true;
			}
			return false;
		});
		// Create a jumping grossini using its def
		_character = _characterDef->toBody(this, GROUP_TWO, 100.0f, 200.0f);
		CCSprite* sprite = CCSprite::create("Images/grossini.png");
		_character->addChild(sprite);
		this->getCamera()->setFollowRatio(ccp(0.1f,0.1f));
		this->getCamera()->follow(_character);
		this->addChild(_character);

		oEffect::create(1)->attachTo(_character)->autoRemove()->start();
	};
	//sensor->bodyEnter += std::make_pair(this, &MyWorld::onBodyEnter);
	this->addChild(body);

	/* Create a Platform Character`s Define
	 (The method to make a platform character will be included in
	 Box2D Nodes extension in the future)
	*/
	TAG_GROUND_SENSOR = 2;
	float BOTTOM_OFFSET = 4.0f;
	float GROUND_SENSOR_HEIGHT = 4.0f;
	size.setSize(65,116);//The physical size of our character
	_characterDef = oBodyDef::create();
	_characterDef->type = b2_dynamicBody;
	//_characterDef->fixedRotation = true;
	float hw = size.width * 0.5f;
	float hh = size.height * 0.5f;
	b2Vec2 verts[] =
	{
		b2Vec2(-hw, hh),
		b2Vec2(-hw + BOTTOM_OFFSET, -hh),
		b2Vec2(hw - BOTTOM_OFFSET, -hh),
		b2Vec2(hw, hh)
	};
	_characterDef->attachPolygon(verts, 4, 1.0f, 0.4f, 0.4f);
	_characterDef->attachPolygonSensor(
		TAG_GROUND_SENSOR,
		size.width - BOTTOM_OFFSET * 2,
		GROUND_SENSOR_HEIGHT,
		b2Vec2(0, -hh - GROUND_SENSOR_HEIGHT * 0.5f));

	sprite = CCSprite::create("Images/Icon.png");
	//sprite->setOpacity(0);

	sprite->runAction(
		oSequence::create(
			CCSpawn::create(
				oKeyPos::create(2.0f, 300.0f, 300.0f, oEase::OutBack),
				oKeyScale::create(2.0f, 3.0f, 3.0f, oEase::InOutElastic),
				nullptr),
			CCSpawn::create(
				oKeyPos::create(2.0f, 100.0f, 100.0f, oEase::OutBack),
				oKeyScale::create(2.0f, 1.0f, 1.0f, oEase::InOutElastic),
				nullptr),
			nullptr));
	this->addChild(sprite);

	this->getCamera()->setBoudary(CCRectMake(-1000, -1000, 2000, 2000));

	sprite = CCSprite::create("Images/Icon.png");
	sprite->setScale(100.0f);
	this->addChild(sprite, -100);
	this->setLayerRatio(-100, ccp(-1.5f, -1.5f));
/*
	CCSpriteBatchNode* batchNode = CCSpriteBatchNode::createWithTexture(CCTextureCache::sharedTextureCache()->addImage("Images/grossini.png"));
	sprite = CCSprite::create("Images/grossini.png");
	CCSprite* childSp = CCSprite::create("Images/grossini.png");
	childSp->setRotation(45.0f);
	childSp->setPosition(ccp(20,30));
	sprite->addChild(childSp);
	batchNode->addChild(sprite);
	this->addChild(batchNode);*/

	oModelDef* modelDef = oSharedModelCache.load("nvjing.model");
	_model = modelDef->toModel();
	_model->setPosition(ccp(200,200));
	_model->setRecovery(0.2f);
	_model->setFaceRight(false);
	_model->setLook("happy");
	_model->setLoop(true);
	_model->play("walk");
	this->addChild(_model);

	return true;
}