Пример #1
0
////////////////////////////////////////////////////////////////////////////////
// マウスジョイント取得
b2MouseJoint* HelloWorld::getMouseJoint(cocos2d::CCPoint p) {
    b2Vec2 locationWorld = b2Vec2(p.x/PTM_RATIO, p.y/PTM_RATIO);
    CCNode* parent = getChildByTag(kTagParentNode);
    CCArray* children  = parent->getChildren();
    CCObject* data = NULL;
    CCARRAY_FOREACH(children, data)
    {
        PhysicsSprite* spr = (PhysicsSprite*)data;
        if (spr != NULL) {
            // スプライトに付与されているBodyを取得
            b2Body* b = spr->getBody();
            b2Fixture *f = b->GetFixtureList();
            if (f->TestPoint(locationWorld)) {
            
                b2MouseJointDef md;
                b2BodyDef groundBodyDef;
                b2MouseJoint* mouseJoint;
                b2Body* groundBody = world->CreateBody(&groundBodyDef);
                md.bodyA = groundBody;//ground Body
                md.bodyB = b;
                md.target = locationWorld;
                md.collideConnected = true;
                md.maxForce = 1000.0f * b->GetMass();
            
                b->SetAwake(true);
            
                // ジョイント取得
                mouseJoint = (b2MouseJoint *)world->CreateJoint(&md);
                return mouseJoint;
            }
        }
    }
Пример #2
0
void GameMenu::menuEnter(){
    //菜单进入后,菜单项点击有效
    CCNode* mainmenu = this->getChildByTag(3);
    CCArray* temp = mainmenu->getChildren();
    for(int i = 0;i < temp->count();i ++)
        ((CCMenuItemImage *)temp->objectAtIndex(i))->setEnabled(true);
}
Пример #3
0
void GameMenuLayer::menuEnter()
{
    CCNode *mainMenu = this->getChildByTag(3);
    CCArray *items = mainMenu->getChildren();
    for (int i = 0; i < items->count(); i++)
        ((CCMenuItemImage *)items->objectAtIndex(i))->setEnabled(true);
}
Пример #4
0
void GameAbout::onEnter()
{
    CCLayer::onEnter();
    //使按钮有效
    CCNode *mainmenu = this->getChildByTag(4);
    CCArray *temp = mainmenu->getChildren();
    ((CCMenuItemImage *)temp->objectAtIndex(0))->setEnabled(true);
}
Пример #5
0
void MainMenu::menuEnter()
{
	CCNode* mainMenu = this->getChildByTag(MAIN_MENU_TAG);
	CCArray* temp = mainMenu->getChildren();
	for(int i = 0; i < (int)temp->count(); i++)
	{
		((CCMenuItem*)temp->objectAtIndex(i))->setEnabled(true);
	}
}
Пример #6
0
CCNode* ListViewLayer::getListItemByIndex(int index)
{
	CCTableViewCell* lastCell = mTableView->cellAtIndex(index);
	if (lastCell)
	{
		CCNode* wrap = lastCell->getChildByTag(TAG_LIST_CELL_ITEM_WRAP);
		return (CCNode*)wrap->getChildren()->objectAtIndex(0);
	}
	// 已经释放了
	return NULL;
}
Пример #7
0
void CMainCityUI::runMovePreAction(int tag)
{
	CCNode *sBtn = dynamic_cast<CCNode*>( m_ui->getChildByTag(tag));
	sBtn->setVisible(true);

	CCArray *children = sBtn->getChildren();
	for (int i = 0; i < sBtn->getChildrenCount(); i++)
	{	
		CCNode *child = (CCNode*)children->objectAtIndex(i);
		CCMoveBy *move = CCMoveBy::create(0.3f,ccp(-m_moveX[tag-1],0));
		child->runAction(move);
		child->setAnchorPoint(CCPointCenter);
		child->setVisible(true);
	}
}
Пример #8
0
CCTableViewCell* ListViewLayer::tableCellAtIndex(CCTableView *table, unsigned int idx)
{
	CCTableViewCell *cell = table->dequeueCell();
	if (cell == NULL) {
		cell = new CCTableViewCell();
		cell->autorelease();

		if (mSource.creator)
		{
			CCNode* item = mSource.creator->getItemContentByIndex(idx);

			// 包裹
			CCNode* wraped = CCNode::create();
			wraped->setContentSize(item->getContentSize());
			wraped->addChild(item,0);

			// 有个0.5,0.5的偏移
			wraped->setPosition(ccp(wraped->getContentSize().width/2,wraped->getContentSize().height/2));

			cell->addChild(wraped,0,TAG_LIST_CELL_ITEM_WRAP);
		}else
		{
			CCAssert(false,"");
		}

		CCLog("ListViewLayer::tableCellAtIndex ---> create!");
	}
	else
	{
		CCLog("ListViewLayer::tableCellAtIndex ---> refesh!");

		CCNode* warped = cell->getChildByTag(TAG_LIST_CELL_ITEM_WRAP);
		CCNode* item = (CCNode*)warped->getChildren()->objectAtIndex(0);

		if (mSource.creator)
		{
			mSource.creator->refreshItem(item,idx);
		}else
		{
			CCAssert(false,"");
		}
	}

	return cell;
}
Пример #9
0
void CMainCityUI::runMoveAction(int fromTag, int toTag,float moveTime)
{
	CCNode *sBtn =  m_ui->getChildByTag(fromTag);
	CButton *dBtn = dynamic_cast<CButton*>( m_ui->getChildByTag(toTag));

	CCArray *children = sBtn->getChildren();

	CCNode *child = nullptr;
	for (int i = 0; i < sBtn->getChildrenCount(); i++)
	{	
		child = (CCNode*)children->objectAtIndex(i);
		CCMoveBy *move = CCMoveBy::create(moveTime,ccp(dBtn->getPositionX() -child->getPositionX(),0));
		CCCallFuncN *hideCall = CCCallFuncN::create(this,callfuncN_selector(CMainCityUI::hideBtn));
		CCSequence *ccseque = CCSequence::create(move,hideCall,nullptr);
		child->runAction(ccseque);
	}
	m_moveX[fromTag-1] = dBtn->getPositionX() - child->getPositionX();
} 
Пример #10
0
	void UIScrollLayer::checkChildrenPos()
	{
		//CCArray* array = m_PageLayer->getChildren();
		CCObject* obj;
		CCARRAY_FOREACH(m_PageLayer,obj)
		{		
			CCLayer* layer = dynamic_cast<CCLayer*>(obj);
			if(layer)
			{
				CCArray* itemArray = layer->getChildren();
				CCObject* itemObj;
				CCARRAY_FOREACH(itemArray,itemObj)
				{
					CCNode* iconButton = dynamic_cast<CCNode*>(itemObj);
					if(iconButton)
					{
						CCArray* menuArray = iconButton->getChildren();
						CCObject* menuObj;
						CCARRAY_FOREACH(menuArray,menuObj)
						{
							CCMenu* menu = dynamic_cast<CCMenu*>(menuObj);
							if(menu)
							{
								CCArray* menuItemArray = menu->getChildren();
								CCObject* menuItmeObj;
								bool claim = false;
								CCARRAY_FOREACH(menuItemArray,menuItmeObj)
								{
									CCMenuItem* item = dynamic_cast<CCMenuItem*>(menuItmeObj);
									if(item)
									{
										CCPoint pt = layer->convertToWorldSpace(menu->getPosition());
										claim = touchIsInContent(pt);
										if(claim)
										{
											break;
										}
									}
								}
								menu->setEnabled(claim);
							}
						}
					}
Пример #11
0
void CMMonsterBasic::MonsterTurn()
{
	do 
	{
		CCNode *pMonsterRoot = dynamic_cast<CCNode*>(getChildByTag(enTagMainNode));
		CC_BREAK_IF(pMonsterRoot==NULL);
		
		//遍历所有精灵的子节点 使其翻转
		CCArray *pArrayChild = pMonsterRoot->getChildren();
		CC_BREAK_IF(pArrayChild==NULL);

		CCObject *pItem=NULL;
		CCARRAY_FOREACH(pArrayChild,pItem)
		{
			CCSprite *pSprite = dynamic_cast<CCSprite*>(pItem);
			if(pSprite==NULL)continue;
			pSprite->setFlipX(true);
		}
		return;
	} while (false);
Пример #12
0
void HpLightObject::updateDisplayedLight(const ccColor3B &parentLight)
{
    _displayedLight.r = clampf(_realLight.r + parentLight.r, 0, 255);
	_displayedLight.g = clampf(_realLight.g + parentLight.g, 0, 255);
	_displayedLight.b = clampf(_realLight.b + parentLight.b, 0, 255);
    
    if (_cascadeLightEnabled)
    {
        CCObject *obj = NULL;
        CCNode* pThis = dynamic_cast<CCNode*>(this);
        CCArray* children = pThis->getChildren();
        CCARRAY_FOREACH(children, obj)
        {
            HpLightProtocol *item = dynamic_cast<HpLightProtocol*>(obj);
            if (item)
            {
                item->updateDisplayedLight(_displayedLight);
            }
        }
    }
Пример #13
0
bool MainScene::init(CCScene* pScene)
{
    iBGIndex = 1;
    m_scene = pScene;
    
    if (CCLayer::init())
    {      
        m_rootNode = (NodeReader::getInstance()->createNode("R/MainScene_1.json"));
        addChild(m_rootNode);
        
        Layout *root = static_cast<Layout*>(m_rootNode->getChildren()->objectAtIndex(0));
        m_root = root;
        
        btnImport = initButton(BUTTON_IMPORT, root, this, toucheventselector(MainScene::touchEvent));
		btnImport->setTitleText(xStr("start"));
        initButton(BUTTON_PRV, root, this, toucheventselector(MainScene::touchEvent));
        initButton(BUTTON_NEXT, root, this, toucheventselector(MainScene::touchEvent));
        initButton(BUTTON_PREVIEW, root, this, toucheventselector(MainScene::touchEvent));
        initButton(BUTTON_REMOVE, root, this, toucheventselector(MainScene::touchEvent));
        initButton(BUTTON_CLEAN, root, this, toucheventselector(MainScene::touchEvent));
        initButton(BUTTON_SAVE, root, this, toucheventselector(MainScene::touchEvent));
        initButton(BUTTON_PREVIEW_ALL, root, this, toucheventselector(MainScene::touchEvent));
        initButton(CHANGE_BG, root, this, toucheventselector(MainScene::touchEvent));
        initButton(MOTION_PREVIEW, root, this, toucheventselector(MainScene::touchEvent));
        Button * btn = initButton(APPLY_TO_ALL, root, this, toucheventselector(MainScene::touchEvent));
        btn->setScale(0.5f);

        btn2x = initButton(BUTTON_2X, root, this, toucheventselector(MainScene::touchEvent));
        btn2x->setScale(0.3f, 0.5f);
        btnAddMotion = initButton(BUTTON_ADD_MOTION, root, this, toucheventselector(MainScene::touchEvent));
        btnAddMotion->setEnabled(false);
        btnDelMotion = initButton(BUTTON_DEL_MOTION, root, this, toucheventselector(MainScene::touchEvent));
        
        btnPre5 = initButton(BUTTON_PRV_5, root, this, toucheventselector(MainScene::touchEvent));
        btnNext5 = initButton(BUTTON_NEXT_5, root, this, toucheventselector(MainScene::touchEvent));
        
        //输入区
        m_ebAnchor[0] = InputBox::create(ANCHOR_X, root, this, m_rootNode);
        m_ebAnchor[1] = InputBox::create(ANCHOR_Y, root, this, m_rootNode);
        m_ebPosition[0] = InputBox::create(POSITION_X, root, this, m_rootNode);
        m_ebPosition[1] = InputBox::create(POSITION_Y, root, this, m_rootNode);
        m_ebRotate = InputBox::create(ROTATE, root, this, m_rootNode);
        m_ebScale = InputBox::create(SCALE, root, this, m_rootNode);
        m_ebDelay = InputBox::create(DELAY, root, this, m_rootNode);
        m_ebName = InputBox::create(SKILL_PART_NAME, root, this, m_rootNode);
        m_ebDegree = InputBox::create(DEGREE, root, this, m_rootNode);
        m_ebSpeed = InputBox::create(SPEED, root, this, m_rootNode);
        m_ebAttackDuration = InputBox::create(ATTACK_DURATION, root, this, m_rootNode);
        m_ebAttackInterval = InputBox::create(ATTACK_INTERVAL, root, this, m_rootNode);
        m_ebBulletType = InputBox::create(BULLET_TYPE, root, this, m_rootNode);
        m_ebBulletType->setText("0");

        m_pHolder = static_cast<CCSprite*>(m_rootNode->getChildByTag(SPRITE_HOLDER));
        m_pHolder->initWithFile("R/cross.png");
        m_iFrameBG = (ImageView*)UIHelper::seekWidgetByTag(root, FRAME_BG);
        m_iFrameBG->addTouchEventListener(this, toucheventselector(MainScene::touchEvent));

        m_iPreviewBG = (ImageView*)UIHelper::seekWidgetByTag(root, PREVIEW_BG);
        m_iPreviewBG->loadTexture("R/bg_1.jpg");
        m_iPreviewBG->setPosition(ccp(m_iPreviewBG->getPositionX() - 240, m_iPreviewBG->getPositionY()));
        m_iPreviewBG1 = ImageView::create();
        m_iPreviewBG1->loadTexture("R/bg_1.jpg");
        m_iPreviewBG1->setPosition(ccp(1440, 0));
        m_iPreviewBG->addChild(m_iPreviewBG1);
        
        m_lFrameCount = (Label*)UIHelper::seekWidgetByTag(root, LABEL_FRAME_COUNT);
        m_preview = static_cast<CCSprite*>(m_rootNode->getChildByTag(PREVIEW));
        m_preview->initWithFile("R/cross.png");
        m_preview->setVisible(false);
        
        xSkill->init(m_pHolder->getPosition(), m_preview->getPosition(), m_rootNode);
        
        //checkbox
        m_cbFlags[0] = initCheckBox(177, root, this, checkboxselectedeventselector(MainScene::selectedStateEvent));
        m_cbFlags[1] = initCheckBox(179, root, this, checkboxselectedeventselector(MainScene::selectedStateEvent));
        m_cbFlags[2] = initCheckBox(183, root, this, checkboxselectedeventselector(MainScene::selectedStateEvent));
        m_cbFlags[3] = initCheckBox(185, root, this, checkboxselectedeventselector(MainScene::selectedStateEvent));
        m_cbFlags[4] = initCheckBox(187, root, this, checkboxselectedeventselector(MainScene::selectedStateEvent));
        m_cbFlags[5] = initCheckBox(ISOLATE, root, this, checkboxselectedeventselector(MainScene::selectedStateEvent));
        m_cbFlags[6] = NULL;    //FI_BULLET_TYPE
        m_cbFlags[7] = initCheckBox(HIGH_LIGHT, root, this, checkboxselectedeventselector(MainScene::selectedStateEvent));

        m_cbNormal = initCheckBox(NORMAL_ATTACK, root, this, checkboxselectedeventselector(MainScene::selectedNormal));
        CCUserDefault::sharedUserDefault()->setBoolForKey(NORMAL, false);
        
        m_cbAttack = initCheckBox(ATTACK_FRAME, root, this, checkboxselectedeventselector(MainScene::selectedAttackFrame));
        
        m_lError = (Label*)(UIHelper::seekWidgetByTag(root, LABEL_ERROR));
        m_lError->setVisible(false);
        
        //列表
        listView = (UIListView*)UIHelper::seekWidgetByTag(root, PARTS_LIST);
        CCNode *node = (NodeReader::getInstance()->createNode("R/FolderBrowser_2.ExportJson"));
        listroot = static_cast<Layout*>(node->getChildren()->objectAtIndex(0));
        Layout* defaultItem = (Layout*)UIHelper::seekWidgetByTag(listroot, 32);         //还有转一层, 一来至少加2个Panel
        listView->setItemModel(defaultItem);
        
        _listAudio = (UIListView*)UIHelper::seekWidgetByTag(root, T_LIST_AUDIO);
        _listAudio->setItemModel(defaultItem);
        initButton(T_AUDIO_BACK, root, this, toucheventselector(MainScene::touchEvent));
        
        motionlist = (UIListView*)UIHelper::seekWidgetByTag(root, MOTION_LIST);
        motionlist->setItemModel(defaultItem);
        
        _layoutAudio = (Layout*)UIHelper::seekWidgetByTag(root, T_SELECT_AUDIO);
        _layoutAudio->setVisible(false);
        _btnAddAudio = initButton(T_ADD_AUDIO, root, this, toucheventselector(MainScene::touchEvent));
        
        xNotify->addObserver(this, callfuncO_selector(MainScene::updateProperty), UPDATE_PROPERTY, NULL);
        xNotify->addObserver(this, callfuncO_selector(MainScene::updateList), UPDATE_EFFECT_LIST, NULL);
        xNotify->addObserver(this, callfuncO_selector(MainScene::updateMotionList), UPDATE_MOTION_LIST, NULL);
        xNotify->addObserver(this, callfuncO_selector(MainScene::setFrameCount), UPDATE_ALL_INDEX, NULL);
        xNotify->addObserver(this, callfuncO_selector(MainScene::error), UPDATE_ERROR, NULL);
        
        setTouchEnabled(true);
        
        return true;
    }
    
    return true;
}
Пример #14
0
void GameAbout::menuEnter(){
    //菜单进入后,菜单项点击有效
    CCNode* mainmenu = this->getChildByTag(4);
    CCArray* temp = mainmenu->getChildren();
    ((CCMenuItemImage *)temp->objectAtIndex(0))->setEnabled(true);
}