void Clayer_normalMapped::ccTouchesEnded(CCSet* touches, CCEvent* event)
{
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    
    CCSetIterator it;
    CCTouch* touch;
    
    for( it = touches->begin(); it != touches->end(); it++)
    {
        touch = (CCTouch*)(*it);
        
        if(!touch)
            break;
        
        CCPoint loc_winSpace = touch->getLocationInView();
        CCPoint loc_GLSpace = CCDirector::sharedDirector()->convertToGL(loc_winSpace);
        
        m_lightSprite->setPosition(loc_GLSpace);
        
    }
}
Beispiel #2
0
void GameWorld::ccTouchesMoved(CCSet* set, CCEvent* event)
{
	// don't accept touch when clown is in these states
	if(clown_->GetState() == E_CLOWN_ROCKET ||
		clown_->GetState() == E_CLOWN_BALLOON ||
		clown_->GetState() == E_CLOWN_UP)
		return;

	CCTouch* touch = (CCTouch*)(*set->begin());
	CCPoint touch_point = touch->getLocationInView();
	touch_end_ = CCDirector::sharedDirector()->convertToGL(touch_point);

	// manipulate anchor point so the platform is correctly oriented
	platform_->setAnchorPoint( touch_end_.x >= touch_start_.x ? ccp(0, 0.5f) : ccp(1, 0.5f) );
	float length = ccpDistance(touch_end_, touch_start_);
	// scale the platform according to user input
	platform_->setScaleX(length / platform_->getContentSize().width);
	// manipulate rotation so that platform doesn't appear upside down
	float angle = CC_RADIANS_TO_DEGREES(-1 * ccpToAngle(ccpSub(touch_end_, touch_start_)));
	platform_->setRotation( touch_end_.x >= touch_start_.x ? angle : angle + 180 );
}
void HelloWorld::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
	CCTouch *touch = (CCTouch *)pTouches->anyObject();
	CCPoint pointTouched = touch->getLocationInView();
	pointTouched = CCDirector::sharedDirector()->convertToGL(pointTouched);

	if (pointTouched.x <= moveSize)
	{
		smallcircle->setVisible(true);
		bigcircle->setVisible(true);
		smallcircle->setPosition(pointTouched);
		m_IsTouchMoved = true;
		IsHolding = false;
	}
	else 
	{
		smallcircle->setVisible(false);
		bigcircle->setVisible(false);
		m_IsTouchMoved = false;
	}
}
void HelloWorld::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) {
    
    // touch
    CCTouch *touch = (CCTouch *)pTouches->anyObject();
    CCPoint location = touch->getLocationInView();
    location = CCDirector::sharedDirector()->convertToGL(location);
    CCLog("---location (%f, %f)", location.x, location.y);
    
    /*
    // Test Messaging
    MessageDispatcher::instance()->dispatchMessage(0, 0, 0, kTesting, (void *)"Hello World");
     */
    
    /*
    // Test Collision
    Fighter *newFighter = Fighter::create(kPeasant);
    m_pBatch->addChild(newFighter->getSprite());
    
    newFighter->setPosition(location);
     */
}
void CtestLayer::ccTouchesBegan(CCSet* touches, CCEvent* event)
{
    
    CCSetIterator it;
    CCTouch* touch;
	for( it = touches->begin(); it != touches->end(); it++)
    {
        touch = (CCTouch*)(*it);
        if(!touch)
            break;
        
        CCPoint pointInWinSpace = touch->getLocationInView();
        //note: for 3d mode, CCDirector::convertToGL() not works as we expected
        //  CCPoint pointInWinSpace = CCDirector::sharedDirector()->convertToGL(pointInWinSpace);
        
        //----update mos
        m_mosPosf=m_mosPos;
        m_mosPos=pointInWinSpace;
        
    }
}
Beispiel #6
0
void Clayer_break:: onTouchesBegan(const std::vector<Touch*>& touches, Event *unused_event)
{
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    
     
    CCTouch* touch;
	for(auto  it = touches.begin(); it != touches.end(); it++)
    {
        touch = (CCTouch*)(*it);
        if(!touch)
            break;
        
        CCPoint loc_winSpace = touch->getLocationInView();
        CCPoint loc_GLSpace = CCDirector::sharedDirector()->convertToGL(loc_winSpace);
        //CCLOG("loc_GLSpace:%f,%f",loc_GLSpace.x,loc_GLSpace.y);
        
        
        switch (m_breakSprite->getState()) {
            case ens::breakEffect::eState_well:
                m_breakSprite->doCrack(loc_GLSpace);
                break;
            case ens::breakEffect::eState_crack:
            {
                m_breakSprite->generateDelayTimes(15);
                breakEffect::CfallOffAction*breakAction=breakEffect::CfallOffAction::create(30);
                m_breakSprite->runAction(breakAction);
            }
                break;
            case ens::breakEffect::eState_fallOff:
                m_breakSprite->reSet();
                break;
            default:
                break;
        }
        
        break;
        
        
    }
}
void GameLayer::ccTouchesBegan(CCSet* touches, CCEvent* event)
{
    if(_gameStrategy->getGameStatus() == GAME_OVER) {
        CCScene* mainScene = Main::scene();
        CCDirector::sharedDirector()->replaceScene(mainScene);
        return;
    }
    
    CCTouch *touch = (CCTouch*) touches->anyObject();
    CCPoint location = touch->getLocationInView();
    location = CCDirector::sharedDirector()->convertToGL(location);
    
    if(_pauseButton->getPosition().x >= location.x &&
       _pauseButton->getPosition().x - _pauseButton->getContentSize().width <= location.x &&
       _pauseButton->getPosition().y >= location.y &&
       _pauseButton->getPosition().y - _pauseButton->getContentSize().height <= location.y) {
        if(_gameStrategy->getGameStatus() == PAUSE) {
            _gameStrategy->resumeGame();
            _pauseButton->setNormalMode();
        } else if(_gameStrategy->getGameStatus() == IN_PROCESS) {
            _gameStrategy->pauseGame();
            _pauseButton->setClickedMode();
        }
        return;
    }
    
    if(_gameStrategy->isPaused()) return;
    if(_abilityButton->getPosition().x + _abilityButton->_panelSprite->getContentSize().width / 2 >= location.x &&
       _abilityButton->getPosition().x - _abilityButton->_panelSprite->getContentSize().width / 2 <= location.x &&
       _abilityButton->getPosition().y + _abilityButton->_panelSprite->getContentSize().height / 2 >= location.y &&
       _abilityButton->getPosition().y - _abilityButton->_panelSprite->getContentSize().height / 2 <= location.y) {
        if(_abilityButton->isReady()) {
            _gameStrategy->useAbility();
            return;
        }
    }
        
    _gameStrategy->touchesBegan(touches, event);
}
Beispiel #8
0
// タッチダウン
void HelloWorld::ccTouchesBegan(CCSet* touches, CCEvent* event)
{
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    //Add a new body/atlas sprite at the touched location
    CCSetIterator it;
    CCTouch* touch;

    for( it = touches->begin(); it != touches->end(); it++)
    {
        touch = (CCTouch*)(*it);
        
        if(!touch)
            break;
        
        CCPoint location = touch->getLocationInView();
        location = CCDirector::sharedDirector()->convertToGL(location);
        
        // マウスジョイント取得
        mouseJoint = this->getMouseJoint(location);
    }
}
Beispiel #9
0
void HelloWorld::ccTouchesEnded(CCSet *pTouches,CCEvent *pEvent)
{
	//获取鼠标位置
	CCTouch *touch = (CCTouch*)pTouches->anyObject();
	CCPoint locInView= touch->getLocationInView();
	//坐标系的转化
	CCPoint loc =CCDirector::sharedDirector()->convertToGL(locInView);

	//精灵的动作
	//CCCallFuncN* disapear= CCCallFuncN::create(this,callfuncN_selector(HelloWorld::myDefine));
	for(vector<keyedit*>::iterator it=this->m_pSpriteList.begin();it!=m_pSpriteList.end();it++){
		if(isTouchGetNode(*it,touch)){
			(*it)->endTime = getCurrentTime();
			(*it)->Change();
			(*it)->isClick = true;
			currentScore+=5;
			CCLOG("currentScore:%d",currentScore);
			break;
		}
	}
	//mykey->runAction(disapear);
}
Beispiel #10
0
void GameScene::ccTouchesBegan(CCSet* touches, CCEvent* event)
{
	// Choose one of the touches to work with
	CCTouch* touch = (CCTouch*)( touches->anyObject() );
	CCPoint location = touch->getLocationInView();
	location = CCDirector::sharedDirector()->convertToGL(location);

	if ( _ledsSelected->count() > 0 and _palette->boundingBox().containsPoint(location) )
	{
		int locX = location.x;
		int locY = location.y;
		CCLOG("X:%d Y:%d", locX, locY);
		int red = (locX / 72) * 36;
		int green = 255 - ( (locY / 18) * 36 );
		int blue = ( (locX % 64) / 16) * 85;

		CCObject *it = NULL;
		CCARRAY_FOREACH(_ledsSelected, it)
		{
			CCMenuItem *led = dynamic_cast<CCMenuItem*>(it);
			led->setColor( ccc3(red, green, blue) );
		}
Beispiel #11
0
void Clayer_tail::onTouchesMoved(const std::vector<Touch*>& touches, Event *unused_event)
{
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    
     
    CCTouch* touch;
    for(auto  it = touches.begin(); it != touches.end(); it++)
    {
        touch = (CCTouch*)(*it);
        
        if(!touch)
            break;
        
        CCPoint loc_winSpace = touch->getLocationInView();
        CCPoint loc_GLSpace = CCDirector::sharedDirector()->convertToGL(loc_winSpace);
        

         if(m_tailSpriteList.empty()==false)m_tailSpriteList[(int)m_tailSpriteList.size()-1]->setPosition(loc_GLSpace);
		
    }
    
}
void Clayer_tail::ccTouchesMoved(cocos2d::CCSet* touches , cocos2d::CCEvent* event)
{
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    
    CCSetIterator it;
    CCTouch* touch;
    for( it = touches->begin(); it != touches->end(); it++)
    {
        touch = (CCTouch*)(*it);
        
        if(!touch)
            break;
        
        CCPoint loc_winSpace = touch->getLocationInView();
        CCPoint loc_GLSpace = CCDirector::sharedDirector()->convertToGL(loc_winSpace);
        

         if(m_tailSpriteList.empty()==false)m_tailSpriteList[(int)m_tailSpriteList.size()-1]->setPosition(loc_GLSpace);
		
    }
    
}
void HelloWorld::ccTouchesBegan(CCSet* touches, CCEvent* even)
{
    if (m_mouseJoint != NULL)
    {
        return;
    }
    
    CCTouch *touch = (CCTouch *)touches->anyObject();
    CCPoint location = touch->getLocationInView();
    location = CCDirector::sharedDirector()->convertToGL(location);
    b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);
    if (locationWorld.x < m_armBody->GetWorldCenter().x + 150.0/PTM_RATIO)
    {
        b2MouseJointDef md;
        md.bodyA = groundBody;
        md.bodyB = m_armBody;
        md.target = locationWorld;//设置鼠标的单机点
        md.maxForce = 2000;
        
        m_mouseJoint = (b2MouseJoint *)world->CreateJoint(&md);
    }
    
}
void HelloWorld::ccTouchesBegan(CCSet* touches, CCEvent *event)
{
	start = true;
	if(mouseJoint != nullptr)
		return;

	CCTouch* touch = (CCTouch*)(touches->anyObject());
	touches->count();
	CCPoint location = touch->getLocationInView();
	location = CCDirector::sharedDirector()->convertToGL(location);
	b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);
	if(locationWorld.x < armBody->GetWorldCenter().x + 50.0/PTM_RATIO)
	{
		b2MouseJointDef md;
		md.bodyA = groundBody;
		md.bodyB = armBody;
		md.target = locationWorld;
		md.maxForce = 2000;

		mouseJoint = (b2MouseJoint *)world->CreateJoint(&md);
		printf("asdf");
	}
}
Beispiel #15
0
void Game::ccTouchesCancelled(cocos2d::CCSet *touches, cocos2d::CCEvent *event)
{
    int touchCount = 0;
    
    for(CCSetIterator i = touches->begin(); i != touches->end(); i ++)
    {
        CCTouch* t = (CCTouch*)(*i);
        CCPoint location = t->getLocationInView();
        location = CCDirector::sharedDirector()->convertToGL(location);
        
        location += touchOffset;
        
        touch[t->m_uID].position = location * scaleFactor;
        touch[t->m_uID].held = false;
        touch[t->m_uID].newPress = false;
        touch[t->m_uID].released = true;
        touch[t->m_uID].enabled = false;
        
        touchCount++;
    }
    
    updateTouches();
}
Beispiel #16
0
void SceneNode::ccTouchesMoved(cocos2d::CCSet* touches , cocos2d::CCEvent* event)
{
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    
    CCSetIterator it;
    CCTouch* touch;
    for( it = touches->begin(); it != touches->end(); it++)
    {
        touch = (CCTouch*)(*it);
        
        if(!touch)
            break;
        
        CCPoint loc_winSpace = touch->getLocationInView();

		if(loc_winSpace.x>0&&loc_winSpace.x<winSize.width&&loc_winSpace.y>0&&loc_winSpace.y<winSize.height){
			touchPos_winSpace=loc_winSpace;
			touchValid=true;
		}
		
    }
   
}
Beispiel #17
0
void HelloWorld::ccTouchesEnded(cocos2d::CCSet *touches,cocos2d::CCEvent *event)
{
	CCTouch *touch =(CCTouch*)touches->anyObject();
	CCPoint location = touch->getLocationInView();
	location = this->convertTouchToNodeSpace(touch);

	CCSize winSize = CCDirector::sharedDirector()->getWinSize();

	CCSprite *projectile = CCSprite::create("YuGuZD.png");
	projectile->setScale(0.5);
	projectile->setPosition(ccp(30,winSize.height/2));

	float offX = location.x - projectile->getPositionX();
	float offY = location.y - projectile->getPositionY();

	if(offX <= 0)
	{
		return;
	}
	projectile->setTag(2);
	this->addChild(projectile);
	arrayProjectile->addObject(projectile);

	float angle = offY / offX;
	float realX = winSize.width + projectile->getContentSize().width/2 + 20;
	float realY = realX * angle +projectile->getPositionY();

	CCPoint finalPosition = ccp(realX, realY);

	float length = sqrtf(realX * realX + realY * realY);
	float velocity = 480;
	float realMoveDuration = length / velocity;

	projectile->runAction(CCSequence::create(CCMoveTo::create(realMoveDuration,finalPosition),
		CCCallFuncN::create(this, callfuncN_selector(HelloWorld::spriteMoveFinished)),NULL));

}
void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event)
{
	if(m_pPlayerBubble == NULL || m_pPlayerBubble->getActive())
		return;

	// Get the touch position and shoot the ball in that direction

	CCTouch* touch = (CCTouch*)(touches->anyObject());
	CCPoint location = touch->getLocationInView();
	location = CCDirector::sharedDirector()->convertToGL(location);

	m_pCannon->setEnabled(false);

	CCSize winSize = CCDirector::sharedDirector()->getWinSize();

	CCPoint direction = ccpNormalize(ccpSub(location, m_pPlayerBubble->getPosition()));

	if(direction.y <= 0) // don't shoot downwards
		return;

	m_pPlayerBubble->setVelocityX(direction.x * BUBBLE_SPEED);
	m_pPlayerBubble->setVelocityY(direction.y * BUBBLE_SPEED);
	m_pPlayerBubble->setActive(true);
}
Beispiel #19
0
void MCoinsGameScene::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
    
    if(box->isLocked())
        return;
	CCSetIterator it = pTouches->begin();
    CCTouch* touch = (CCTouch*)(*it);
    CCPoint location = touch->getLocationInView();
    location = CCDirector::sharedDirector()->convertToGL( location );
    
    int x = (location.x -kStartX) / kTileSize;
	int y = (location.y -kStartY) / kTileSize;
	
    GameTile *tile = box->objectAtXandY(x, y);
    if (tile->x == -1 && tile->y == -1) {
        return;
    }
    
	if (selectedTile != NULL && selectedTile->x ==x && selectedTile->y == y)
		return;
    
    if(selectedTile && selectedTile->nearTile(tile))
    {
        box->setLock(true);
        this->changeWithTileABandSel(selectedTile, tile, callfuncND_selector(MCoinsGameScene::checkSenderandData));
        selectedTile = NULL;
    }
    else
    {
       
        selectedTile = tile;
        this->afterOneShineTrun(tile->sprite);
    }
    CCString* string = CCString::createWithFormat(SOUND_EFF_ICON_CLICK);
    VSCSound::playEffect(string->getCString());
}
Beispiel #20
0
void GameLayer::ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
    if (pTouches->count() == 1) {
        CCTouch *pTouch = (CCTouch*)pTouches->anyObject();
        
        /*for (CCSetIterator iterTouch = pTouches->begin(); iterTouch != pTouches->end(); iterTouch++) {
         CCTouch *pcurTouch = (CCTouch*)(*iterTouch);
         }*/
        
        CCPoint touchLocation = pTouch->getLocationInView();
        touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation);
        CCPoint local = convertToNodeSpace(touchLocation);
        
        // back button
        CCRect rect1 = _backSprite->boundingBox();
        bool flag = rect1.containsPoint(local);
        if (flag) {
            _backSprite->setColor(ccc3(222, 43, 54));
            SimpleAudioEngine::sharedEngine()->playEffect("click.caf");
            CCScene *pScene = FirstLevelView::scene();
            CCDirector::sharedDirector()->replaceScene(CCTransitionSplitRows::create(1, pScene));
        }
    }
}
void HelloWorld::ccTouchesBegan(CCSet* touches, CCEvent* event)
{
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    
    CCSetIterator it;
    CCTouch* touch;
	for( it = touches->begin(); it != touches->end(); it++)
    {
        touch = (CCTouch*)(*it);
        if(!touch)
            break;
        
        CCPoint loc_winSpace = touch->getLocationInView();
        CCPoint loc_GLSpace = CCDirector::sharedDirector()->convertToGL(loc_winSpace);
        //CCLOG("loc_GLSpace:%f,%f",loc_GLSpace.x,loc_GLSpace.y);
        
        m_touchPointFoe=m_touchPoint;
        m_touchPoint=loc_GLSpace;
        break;
        
    }
    m_isTouchingFoe=m_isTouching;
    m_isTouching=true;
}
Beispiel #22
0
int CCLuaEngine::executeNodeTouchesEvent(CCNode* pNode, int eventType, CCSet *pTouches, int phase)
{
    CCScriptEventListenersForEvent &listeners = pNode->getScriptEventListenersByEvent(phase == NODE_TOUCH_CAPTURING_PHASE ? NODE_TOUCH_CAPTURE_EVENT : NODE_TOUCH_EVENT);
    if (listeners.size() == 0) return 1;

    m_stack->clean();
    CCLuaValueDict event;
    switch (eventType)
    {
        case CCTOUCHBEGAN:
            event["name"] = CCLuaValue::stringValue("began");
            break;

        case CCTOUCHMOVED:
            event["name"] = CCLuaValue::stringValue("moved");
            break;

        case CCTOUCHENDED:
            event["name"] = CCLuaValue::stringValue("ended");
            break;

        case CCTOUCHCANCELLED:
            event["name"] = CCLuaValue::stringValue("cancelled");
            break;

        default:
            return 0;
    }

    event["mode"] = CCLuaValue::intValue(kCCTouchesAllAtOnce);
    switch (phase)
    {
        case NODE_TOUCH_CAPTURING_PHASE:
            event["phase"] = CCLuaValue::stringValue("capturing");
            break;

        case NODE_TOUCH_TARGETING_PHASE:
            event["phase"] = CCLuaValue::stringValue("targeting");
            break;

        default:
            event["phase"] = CCLuaValue::stringValue("unknown");
    }

    CCLuaValueDict points;
    CCDirector* pDirector = CCDirector::sharedDirector();
    char touchId[16];
    for (CCSetIterator touchIt = pTouches->begin(); touchIt != pTouches->end(); ++touchIt)
    {
        CCLuaValueDict point;
        CCTouch* pTouch = (CCTouch*)*touchIt;
        sprintf(touchId, "%d", pTouch->getID());
        point["id"] = CCLuaValue::stringValue(touchId);

        const CCPoint pt = pDirector->convertToGL(pTouch->getLocationInView());
        point["x"] = CCLuaValue::floatValue(pt.x);
        point["y"] = CCLuaValue::floatValue(pt.y);
        const CCPoint prev = pDirector->convertToGL(pTouch->getPreviousLocationInView());
        point["prevX"] = CCLuaValue::floatValue(prev.x);
        point["prevY"] = CCLuaValue::floatValue(prev.y);

        points[touchId] = CCLuaValue::dictValue(point);
    }
    event["points"] = CCLuaValue::dictValue(points);
    m_stack->pushCCLuaValueDict(event);

    CCScriptEventListenersForEventIterator it = listeners.begin();
    for (; it != listeners.end(); ++it)
    {
        m_stack->copyValue(1);
        m_stack->executeFunctionByHandler((*it).listener, 1);
        m_stack->settop(1);
    }

    m_stack->clean();
    
    return 1;
}
Beispiel #23
0
void ScrollViewDemo::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
    if (!m_bScrolling) return;
	CCTouch *touch = (CCTouch*)pTouches->anyObject();
    CCNode *clipper = this->getChildByTag(kTagClipperNode);
    CCPoint point = clipper->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(touch->getLocationInView()));
	CCPoint diff = ccpSub(point, m_lastPoint);
    CCNode *content = clipper->getChildByTag(kTagContentNode);
    content->setPosition( ccpAdd(content->getPosition(), diff) );
    m_lastPoint = point;
}
Beispiel #24
0
void ScrollViewDemo::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
	CCTouch *touch = (CCTouch*)pTouches->anyObject();
    CCNode *clipper = this->getChildByTag(kTagClipperNode);
	CCPoint point = clipper->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(touch->getLocationInView()));
    CCRect rect = CCRectMake(0, 0, clipper->getContentSize().width, clipper->getContentSize().height);
    m_bScrolling = rect.containsPoint(point);
    m_lastPoint = point;
}
Beispiel #25
0
void HoleDemo::ccTouchesBegan(CCSet* touches, CCEvent* event)
{
	CCTouch *touch = (CCTouch *)touches->anyObject();
	CCPoint point = m_pOuterClipper->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(touch->getLocationInView()));
    CCRect rect = CCRectMake(0, 0, m_pOuterClipper->getContentSize().width, m_pOuterClipper->getContentSize().height);
    if (!rect.containsPoint(point)) return;
    this->pokeHoleAtPoint(point);
}
void MonsterLayer::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
{
    
    CCLog("タッチが離れました");
    
    CCLog("離れるタッチ位置を設定");
    CCTouch* touch = (CCTouch*)pTouches->anyObject();
    CCPoint location = touch->getLocationInView();
    location = CCDirector::sharedDirector()->convertToGL(location);
 
    CCSprite* AA = (CCSprite*)this->getChildByTag(103);
    CCSprite* KK = (CCSprite*)this->getChildByTag(113);
    CCSprite* SS = (CCSprite*)this->getChildByTag(123);
    CCSprite* TT = (CCSprite*)this->getChildByTag(133);
    CCSprite* NN = (CCSprite*)this->getChildByTag(143);
    CCSprite* HH = (CCSprite*)this->getChildByTag(153);
    CCSprite* MM = (CCSprite*)this->getChildByTag(163);
    CCSprite* YY = (CCSprite*)this->getChildByTag(173);
    CCSprite* RR = (CCSprite*)this->getChildByTag(183);
    CCSprite* WW = (CCSprite*)this->getChildByTag(203);

    if (!(AA==NULL)) {
        TASP(aF,iF,uF,eF,oF,101,102,103,104,105);
        TASP2(aF, iF, uF, eF, oF, "あ", "い", "う", "え", "お")
        this->removeChildByTag(102,true);
        this->removeChildByTag(103,true);
        this->removeChildByTag(104,true);
        this->removeChildByTag(105,true);

        
    }
    if (!(KK==NULL)){
        TASP(kaF, kiF, kuF, keF, koF, 111, 112, 113, 114, 115);
        TASP2(kaF, kiF, kuF, keF, koF, "か", "き", "く", "け", "こ")
        this->removeChildByTag(112,true);
        this->removeChildByTag(113,true);
        this->removeChildByTag(114,true);
        this->removeChildByTag(115,true);
        
    }
    if (!(SS==NULL)){
      TASP(saF, siF, suF, seF, soF, 121, 122, 123, 124, 125);
         TASP2(saF, siF, suF, seF, soF, "さ", "し", "す", "せ", "そ")
        this->removeChildByTag(122,true);
        this->removeChildByTag(123,true);
        this->removeChildByTag(124,true);
        this->removeChildByTag(125,true);
    }
    if (!(TT==NULL)){
        TASP(taF, tiF, tuF, teF, toF, 131, 132, 133, 134, 135);
        TASP2(taF, tiF, tuF, teF, toF, "た", "ち", "つ", "て", "と")
        this->removeChildByTag(132,true);
        this->removeChildByTag(133,true);
        this->removeChildByTag(134,true);
        this->removeChildByTag(135,true);

        
    }
    if (!(NN==NULL)){
        TASP(naF, niF, nuF, neF, noF, 141, 142, 143, 144, 145);
        TASP2(naF, niF, nuF, neF, noF, "な", "に", "ぬ", "ね", "の")
        this->removeChildByTag(142,true);
        this->removeChildByTag(143,true);
        this->removeChildByTag(144,true);
        this->removeChildByTag(145,true);
        
    }
    if (!(HH==NULL)){
        TASP(haF, hiF, huF, heF, hoF, 151, 152, 153, 154, 155);
        TASP2(haF, hiF, huF, heF, hoF, "は", "ひ", "ふ", "へ", "ほ")
        this->removeChildByTag(152,true);
        this->removeChildByTag(153,true);
        this->removeChildByTag(154,true);
        this->removeChildByTag(155,true);
        
    }
    if (!(MM==NULL)){
        
        TASP(maF, miF, muF, meF, moF, 161, 162, 163, 164, 165);
        TASP2(maF, miF, muF, meF, moF, "ま", "み", "む", "め", "も")
        this->removeChildByTag(162,true);
        this->removeChildByTag(163,true);
        this->removeChildByTag(164,true);
        this->removeChildByTag(165,true);
        
    }
    if (!(YY==NULL)){
        //TASP(yaF, yiF, yuF, yeF, yoF, 171, 172, 173, 174, 175);
        
        
        CCSprite* yaF = (CCSprite*)this->getChildByTag(171);\
        CCSprite* yuF = (CCSprite*)this->getChildByTag(173);\
        CCSprite* yoF = (CCSprite*)this->getChildByTag(175);\

        CCRect rectyaF=CCR(yaF);\
        CCRect rectyuF=CCR(yuF);\
        CCRect rectyoF=CCR(yoF);\
        yaF->retain();\
        yuF->retain();\
        yoF->retain();\
        yaF->autorelease();\
        yuF->autorelease();\
        yoF->autorelease();\
        //TASP2(yaF, yiF, yuF, yeF, yoF, "や", "い", "ゆ", "え", "よ")
        if(rectyaF.containsPoint(location)){
            flickLabel->setString("や");
            CCLog("や");\
        }else if(rectyuF.containsPoint(location)){\
            flickLabel->setString("ゆ");\
            CCLog("ゆ");\
        }else if(rectyoF.containsPoint(location)){\
            flickLabel->setString("よ");\
            CCLog("よ");\
        }
      
        this->removeChildByTag(172,true);
        this->removeChildByTag(173,true);
        this->removeChildByTag(174,true);
        this->removeChildByTag(175,true);
        
    }
    if (!(RR==NULL)){
        TASP(raF, riF, ruF, reF, roF, 181, 182, 183, 184, 185);
        TASP2(raF, riF, ruF, reF, roF, "ら", "り", "る", "れ", "ろ")
        this->removeChildByTag(182,true);
        this->removeChildByTag(183,true);
        this->removeChildByTag(184,true);
        this->removeChildByTag(185,true);
        
    }
    if (!(WW==NULL)){
       
        CCSprite* waF = (CCSprite*)this->getChildByTag(201);
        CCSprite* woF = (CCSprite*)this->getChildByTag(202);
        CCSprite* nnF = (CCSprite*)this->getChildByTag(203);
        CCSprite* barF = (CCSprite*)this->getChildByTag(204);
        
        CCRect rectwaF=CCR(waF);
        CCRect rectwoF=CCR(woF);
        CCRect rectnnF=CCR(nnF);
        CCRect rectbarF=CCR(barF);

        waF->retain();
        woF->retain();
        nnF->retain();
        barF->retain();
        waF->autorelease();
        woF->autorelease();
        nnF->autorelease();
        barF->autorelease();
        //TASP2(yaF, yiF, yuF, yeF, yoF, "や", "い", "ゆ", "え", "よ")
        if(rectwaF.containsPoint(location)){
            flickLabel->setString("わ");
            CCLog("わ");
        }else if(rectwoF.containsPoint(location)){
            flickLabel->setString("を");
            CCLog("を");
        }else if(rectnnF.containsPoint(location)){
            flickLabel->setString("ん");
            CCLog("ん");
        }else if(rectbarF.containsPoint(location)){
            flickLabel->setString("ー");
            CCLog("ー");
        
        this->removeChildByTag(202,true);
        this->removeChildByTag(203,true);
        this->removeChildByTag(204,true);
        this->removeChildByTag(205,true);
        
    }
    
    }



   
    CCLog("ここまでや?");

    
    this->removeChildByTag(102,true);
    this->removeChildByTag(103,true);
    this->removeChildByTag(104,true);
    this->removeChildByTag(105,true);
    this->removeChildByTag(112,true);
    this->removeChildByTag(113,true);
    this->removeChildByTag(114,true);
    this->removeChildByTag(115,true);

    this->removeChildByTag(122,true);
    this->removeChildByTag(123,true);
    this->removeChildByTag(124,true);
    this->removeChildByTag(125,true);

    this->removeChildByTag(132,true);
    this->removeChildByTag(133,true);
    this->removeChildByTag(134,true);
    this->removeChildByTag(135,true);

    this->removeChildByTag(142,true);
    this->removeChildByTag(143,true);
    this->removeChildByTag(144,true);
    this->removeChildByTag(145,true);

    this->removeChildByTag(152,true);
    this->removeChildByTag(153,true);
    this->removeChildByTag(154,true);
    this->removeChildByTag(155,true);

    this->removeChildByTag(162,true);
    this->removeChildByTag(163,true);
    this->removeChildByTag(164,true);
    this->removeChildByTag(165,true);

    this->removeChildByTag(172,true);
    this->removeChildByTag(173,true);
    this->removeChildByTag(174,true);
    this->removeChildByTag(175,true);

    this->removeChildByTag(182,true);
    this->removeChildByTag(183,true);
    this->removeChildByTag(184,true);
    this->removeChildByTag(185,true);

    this->removeChildByTag(202,true);
    this->removeChildByTag(203,true);
    this->removeChildByTag(204,true);
    this->removeChildByTag(205,true);

 
 
    CCCallFuncN* flickDone =
    CCCallFuncN::create(this,callfuncN_selector(MonsterLayer::flickFinished));
    
    runAction(flickDone);
     
    CCLog("指がはなれた");
    
}
////////////フリック入力画面の実装/////////////////////////////////////////////////
void MonsterLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
    CCLog("タッチ開始");
    
    
    CCSprite* aF = (CCSprite*)this->getChildByTag(101);
    CCSprite* kaF = (CCSprite*)this->getChildByTag(111);
    CCSprite* saF = (CCSprite*)this->getChildByTag(121);
    CCSprite* taF = (CCSprite*)this->getChildByTag(131);
    CCSprite* naF = (CCSprite*)this->getChildByTag(141);
    CCSprite* haF = (CCSprite*)this->getChildByTag(151);
    CCSprite* maF = (CCSprite*)this->getChildByTag(161);
    CCSprite* yaF = (CCSprite*)this->getChildByTag(171);
    CCSprite* raF = (CCSprite*)this->getChildByTag(181);
    CCSprite* waF = (CCSprite*)this->getChildByTag(201);
    CCRect rectA =aF->boundingBox();
    CCRect rectKa =kaF->boundingBox();
    CCRect rectSa =saF->boundingBox();
    CCRect rectTa =taF->boundingBox();
    CCRect rectNa =naF->boundingBox();
    CCRect rectHa =haF->boundingBox();
    CCRect rectMa =maF->boundingBox();
    CCRect rectYa =yaF->boundingBox();
    CCRect rectRa =raF->boundingBox();
    CCRect rectWa =waF->boundingBox();

    //CCRect rectK =kaF->boundingBox();
    CCTouch* touch = (CCTouch*)pTouches->anyObject();
    CCPoint location = touch->getLocationInView();
    location = CCDirector::sharedDirector()->convertToGL(location);
    
    
    if (rectA.containsPoint(location)) {
        STADC(aF, iF, uF, eF, oF, "iF.png", "uF.png", "eF.png", "oF.png", 102, 103, 104, 105);
       
    }else if(rectKa.containsPoint(location)){
        STADC(kaF, kiF, kuF, keF, koF, "kiF.png", "kuF.png", "keF.png", "koF.png", 112, 113, 114, 115);

    }else if(rectSa.containsPoint(location)){
        STADC(saF, siF, suF, seF, soF, "siF.png", "suF.png", "seF.png", "soF.png", 122, 123, 124, 125);
        
    }else if(rectTa.containsPoint(location)){
        STADC(taF, tiF, tuF, teF, toF, "tiF.png", "tuF.png", "teF.png", "toF.png", 132, 133, 134, 135);
        
    }else if(rectNa.containsPoint(location)){
        STADC(naF, niF, nuF, neF, noF, "niF.png", "nuF.png", "neF.png", "noF.png", 142, 143, 144, 145);
        
    }else if(rectHa.containsPoint(location)){
        STADC(haF, hiF, huF, heF, hoF, "hiF.png", "huF.png", "heF.png", "hoF.png", 152, 153, 154, 155);
        
    }else if(rectMa.containsPoint(location)){
        STADC(maF, miF, muF, meF, moF, "miF.png", "muF.png", "meF.png", "moF.png", 162, 163, 164, 165);
        
    }else if(rectYa.containsPoint(location)){
        CCSprite* yuF = CCSprite::create("yuF.png");
        yuF->setPosition(ccp(yaF->getPosition().x,yaF->getPositionY()+yaF->getContentSize().height));
        this->addChild(yuF,0,173);
        CCSprite* yoF = CCSprite::create("yoF.png");
        yoF->setPosition(ccp(yaF->getPosition().x,yaF->getPositionY()-yaF->getContentSize().height));
        this->addChild(yoF,0,175);
        yuF->retain();
        yoF->retain();
        yuF->autorelease();
        yoF->autorelease();

       

        
    }else if(rectRa.containsPoint(location)){
        STADC(raF, riF, ruF, reF, roF, "riF.png", "ruF.png", "reF.png", "roF.png", 182, 183, 184, 185);
        
    }else if(rectWa.containsPoint(location)){
        CCSprite* woF = CCSprite::create("woF.png");
        woF->setPosition(ccp(waF->getPositionX()-waF->getContentSize().width,waF->getPositionY()));
        this->addChild(woF,0,202);
        CCSprite* nnF = CCSprite::create("nnF.png");
        nnF->setPosition(ccp(waF->getPosition().x,waF->getPositionY()+waF->getContentSize().height));
        this->addChild(nnF,0,203);
        CCSprite* barF = CCSprite::create("barF.png");
        barF->setPosition(ccp(waF->getPositionX()+waF->getContentSize().width,waF->getPositionY()));
        this->addChild(barF,0,204);
        
        woF->retain();\
        nnF->retain();\
        barF->retain();\
        woF->autorelease();\
        nnF->autorelease();\
        barF->autorelease();\
        
        
    }
}
Beispiel #28
0
int CCLuaEngine::executeNodeTouchesEvent(CCNode* pNode, int eventType, CCSet *pTouches, int phase)
{
    m_stack->clean();
    CCLuaValueDict event;
    switch (eventType)
    {
        case CCTOUCHBEGAN:
            event["name"] = CCLuaValue::stringValue("began");
            break;

        case CCTOUCHMOVED:
            event["name"] = CCLuaValue::stringValue("moved");
            break;

        case CCTOUCHENDED:
            event["name"] = CCLuaValue::stringValue("ended");
            break;

        case CCTOUCHCANCELLED:
            event["name"] = CCLuaValue::stringValue("cancelled");
            break;

        case CCTOUCHADDED:
            event["name"] = CCLuaValue::stringValue("added");
            break;

        case CCTOUCHREMOVED:
            event["name"] = CCLuaValue::stringValue("removed");
            break;

        default:
            return 0;
    }

    event["mode"] = CCLuaValue::intValue(kCCTouchesAllAtOnce);
    switch (phase)
    {
        case NODE_TOUCH_CAPTURING_PHASE:
            event["phase"] = CCLuaValue::stringValue("capturing");
            break;

        case NODE_TOUCH_TARGETING_PHASE:
            event["phase"] = CCLuaValue::stringValue("targeting");
            break;

        default:
            event["phase"] = CCLuaValue::stringValue("unknown");
    }

    CCLuaValueDict points;
    CCDirector* pDirector = CCDirector::sharedDirector();
    char touchId[16];
    for (CCSetIterator touchIt = pTouches->begin(); touchIt != pTouches->end(); ++touchIt)
    {
        CCLuaValueDict point;
        CCTouch* pTouch = (CCTouch*)*touchIt;
        sprintf(touchId, "%d", pTouch->getID());
        point["id"] = CCLuaValue::stringValue(touchId);

        const CCPoint pt = pDirector->convertToGL(pTouch->getLocationInView());
        point["x"] = CCLuaValue::floatValue(pt.x);
        point["y"] = CCLuaValue::floatValue(pt.y);
        const CCPoint prev = pDirector->convertToGL(pTouch->getPreviousLocationInView());
        point["prevX"] = CCLuaValue::floatValue(prev.x);
        point["prevY"] = CCLuaValue::floatValue(prev.y);

        points[touchId] = CCLuaValue::dictValue(point);
    }
    event["points"] = CCLuaValue::dictValue(points);
    m_stack->pushCCLuaValueDict(event);

    int eventInt = (phase == NODE_TOUCH_CAPTURING_PHASE) ? NODE_TOUCH_CAPTURE_EVENT : NODE_TOUCH_EVENT;
    CCArray *listeners = pNode->getAllScriptEventListeners();
    CCScriptHandlePair *p;
    for (int i = listeners->count() - 1; i >= 0; --i)
    {
        p = dynamic_cast<CCScriptHandlePair*>(listeners->objectAtIndex(i));
        if (p->event != eventInt || p->removed) continue;
        m_stack->copyValue(1);
        m_stack->executeFunctionByHandler(p->listener, 1);
        m_stack->settop(1);
    }

    m_stack->clean();
    
    return 1;
}
void CtestLayer::ccTouchesBegan(CCSet* touches, CCEvent* event)
{

    CCSetIterator it;
    CCTouch* touch;
    for( it = touches->begin(); it != touches->end(); it++)
    {
        touch = (CCTouch*)(*it);
        if(!touch)
            break;

        CCPoint pointInWinSpace = touch->getLocationInView();
        //note: for 3d mode, CCDirector::convertToGL() not works as we expected
        //  CCPoint pointInWinSpace = CCDirector::sharedDirector()->convertToGL(pointInWinSpace);

        //----update mos
        m_mosPosf=m_mosPos;
        m_mosPos=pointInWinSpace;


        //-------
        CCRect viewportRect=cocos2d::CCEGLView::sharedOpenGLView()->getViewPortRect();
        float viewport[4]= {viewportRect.getMinX(),viewportRect.getMinY(),viewportRect.size.width,viewportRect.size.height};

        Cc3dCamera*camera=m_root3d->getCamera3D();
        Cc3dVector4 eyePos=camera->getEyePos();
        Cc3dVector4 winPos=Cc3dVector4(m_mosPos.x,viewport[3]-m_mosPos.y,0,1);
        Cc3dMatrix4 projMat=camera->calculateProjectionMat();
        Cc3dMatrix4 viewMat=camera->calculateViewMat();
        Cc3dMatrix4 projViewInverse=inverse(projMat*viewMat);
        Cc3dVector4 worldPos= convertFromViewportSpaceToWorldSpace(winPos, projMat, viewMat, viewport);


        int i_firstIntersectActor=-1;
        int j_firstIntersectActor=-1;
        int k_firstIntersectActor=-1;
        float minDisIntersectPointToEyePos=INFINITY;

        for(int i=0; i<m_nRow; i++) {
            for(int j=0; j<m_nCol; j++) {
                for(int k=0; k<m_nDeep; k++) {
                    Cc3dActor*actor=m_actor3dMat3d[i][j][k];
                    int meshCount=actor->getModel()->getMeshCount();
                    for(int u=0; u<meshCount; u++) {
                        Cc3dMesh*mesh=actor->getModel()->getMeshByIndex(u);
                        int subMeshCount=mesh->getSubMeshCount();
                        for(int v=0; v<subMeshCount; v++) {
                            Cc3dSubMesh*subMesh=mesh->getSubMeshByIndex(v);
                            Cc3dSubMeshData*subMeshData=subMesh->getSubMeshData();
                            const vector<Cc3dVector4>&positionList=subMeshData->m_positionList;
                            const vector<Cc3dIDTriangle>&IDtriList=subMeshData->m_IDtriList;
                            int nIDtri=(int)IDtriList.size();
                            for(int w=0; w<nIDtri; w++) {
                                const Cc3dIDTriangle&IDtri=IDtriList[w];
                                int ID0=IDtri.vID(0);
                                int ID1=IDtri.vID(1);
                                int ID2=IDtri.vID(2);
                                Cc3dVector4 p0=subMesh->convertToWorldSpace3D(positionList[ID0]);
                                Cc3dVector4 p1=subMesh->convertToWorldSpace3D(positionList[ID1]);
                                Cc3dVector4 p2=subMesh->convertToWorldSpace3D(positionList[ID2]);
                                if(isLine3dIntersectWithTriangle3d(eyePos, worldPos-eyePos, p0, p1, p2)) { //intersect
                                    Cc3dVector4 intersectPos=getIntersectPointOfLine3dIntersectWithPlane3d(eyePos, worldPos-eyePos, p0, cross(p1-p0, p2-p1));
                                    float disIntersectPointToEyePos=getLength(intersectPos-eyePos);
                                    if(disIntersectPointToEyePos<minDisIntersectPointToEyePos) {
                                        minDisIntersectPointToEyePos=disIntersectPointToEyePos;
                                        i_firstIntersectActor=i;
                                        j_firstIntersectActor=j;
                                        k_firstIntersectActor=k;
                                    }

                                }
                            }
                        }
                    }
                }
            }
        }//got i_firstIntersectActor, j_firstIntersectActor, k_firstIntersectActor, minDisIntersectPointToEyePos
        if(i_firstIntersectActor!=-1) { //have intersect
            Cc3dActor*firstIntersectActor=m_actor3dMat3d[i_firstIntersectActor][j_firstIntersectActor][k_firstIntersectActor];
            int meshCount=firstIntersectActor->getModel()->getMeshCount();
            for(int i=0; i<meshCount; i++) {
                Cc3dMesh*mesh=firstIntersectActor->getModel()->getMeshByIndex(i);
                int subMeshCount=mesh->getSubMeshCount();
                for(int j=0; j<subMeshCount; j++) {
                    Cc3dSubMesh*subMesh=mesh->getSubMeshByIndex(j);
                    Cc3dSubMeshData*subMeshData=subMesh->getSubMeshData();
                    vector<Cc3dVector4>&colorList=subMeshData->m_colorList;
                    for(int k=0; k<(int)colorList.size(); k++) {
                        colorList[k]=Cc3dVector4(0,0,1,1);
                    }
                    subMesh->submitColor(GL_STREAM_DRAW);

                }
            }

        }


        break;//only consider the first touch

    }
}
Beispiel #30
0
void GameLayerScene::ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event){
    CCLOG("Touches..");
    CCTouch *myTouch = (CCTouch *)touches->anyObject();
    CCPoint location = myTouch->getLocationInView();
    location = CCDirector::sharedDirector()->convertToGL(location);
}