示例#1
0
void HelloWorld::tick(float dt) {


    //=================================
    CCPoint backgroundScrollVert = ccp(-2000, 0);
    pBackgroundNode->setPosition(ccpAdd(pBackgroundNode->getPosition(), ccpMult(backgroundScrollVert, dt)));

    CCArray *BackGrounds = CCArray::createWithCapacity(2);
    BackGrounds->addObject(pSprite);
    BackGrounds->addObject(pNextSprite);
    for ( int ii = 0; ii < BackGrounds->count(); ii++ ) {
        CCSprite * BackGround = (CCSprite *)(BackGrounds->objectAtIndex(ii));
        float xPosition = pBackgroundNode->convertToWorldSpace(BackGround->getPosition()).x;
        float size = BackGround->getContentSize().width;
        if ( xPosition < -size/2 ) {
            pBackgroundNode->incrementOffset(ccp(BackGround->getContentSize().width*2,0),BackGround);
        }
    }


    //===================================

    pworld->Step(dt, 10, 10);
    for(b2Body *b = pworld->GetBodyList(); b; b=b->GetNext()) {
        if (b->GetUserData() != NULL) {

            if(b->GetType() == b2_dynamicBody)
            {
                CCSprite *ballData = (CCSprite *)b->GetUserData();
                ballData->setPosition(ccp(b->GetPosition().x * PTM_RATIO,
                                          b->GetPosition().y * PTM_RATIO));
                ballData->setRotation (-1 * CC_RADIANS_TO_DEGREES(b->GetAngle()));
            }

            /*else if(b->GetType() == b2_staticBody)
            {
            	CCSprite *ballData = (CCSprite *)b->GetUserData();
            	ballData->setPosition(ccp(b->GetPosition().x * PTM_RATIO,
            		b->GetPosition().y * PTM_RATIO));
            	ballData->setRotation (-1 * CC_RADIANS_TO_DEGREES(b->GetAngle()));
            }*/
        }
    }

}
void SGShowJingZhouRankCell::setData(SGShowJingZhouRankPlayerLayer *player)
{
    CCString *string = CCString::createWithFormat("countryIcon_%d.png", player->getHeadId());
    spriteIcon->setDisplayFrame(CCSprite::createWithSpriteFrameName(string->getCString())->displayFrame());
    spriteIcon->cocos2d::CCNode::setScale(0.9, 0.95);
    spriteIcon->setPosition(ccpAdd(spriteIconBg->getPosition(), ccp(spriteIcon->getContentSize().width*0.00, spriteIcon->getContentSize().height*0.05)) );
    //////////
    string = CCString::createWithFormat("country_%d.png", player->getHeadId());
    spriteIconBg->setDisplayFrame(CCSprite::createWithSpriteFrameName(string->getCString())->displayFrame());
    
    ////////////////////

     CCString *name= CCString::createWithFormat("%s", player->getName()->getCString());
     labelNickName->setString(name->getCString());
    
     CCString* paiming = CCString::createWithFormat(str_BMatchEndBox_str14, player->getRank());
     labelRank->setString(paiming->getCString());
    
     CCString* boshu = CCString::createWithFormat(str_ShowJingZhouRankCell_str2, player->getWave());
     labelboshu->setString(boshu->getCString());
    
     CCString* shanghai = CCString::createWithFormat(str_ShowJingZhouRankCell_str3, player->getDamage());
     labelshanghai->setString(shanghai->getCString());
	
	
	//更元宝显示, 是否能得到元宝
	//if (player->getGoldNum())
	{
		//可获得的奖励数量小于可获取奖励的人数时才显示
		goldCount->setString(CCString::createWithFormat("X %d", player->getGoldNum())->getCString());
	}
/*	else//没有元宝就什么都不显示
	{
		goldCount->setVisible(false);
		goldSpr->setVisible(false);
		goldBorderSpr->setVisible(false);
		goldBg->setVisible(false);
	}
	
	*/
	
	
	
 
}
示例#3
0
void CAScrollView::ccTouchEnded(CATouch *pTouch, CAEvent *pEvent)
{
    if (m_pTouches->containsObject(pTouch))
    {
        if (m_pTouches->count() == 1)
        {
            CCPoint p = CCPointZero;
            
            if (m_tPointOffset.size() > 0)
            {
                for (unsigned int i=0; i<m_tPointOffset.size(); i++)
                {
                    p = ccpAdd(p, m_tPointOffset.at(i));
                }
                p = p/m_tPointOffset.size();
            }
            m_tInertia = p * 1.5f;
			m_tPointOffset.clear();

            if (!m_tInertia.equals(CCPointZero))
            {
                m_bDecelerating = true;
                if (m_pScrollViewDelegate)
                {
                    m_pScrollViewDelegate->scrollViewDidScroll(this);
                }
            }

            this->startDeaccelerateScroll();
            
            if (m_pScrollViewDelegate)
            {
                m_pScrollViewDelegate->scrollViewDidEndDragging(this);
            }
            m_bTracking = false;
            
            this->detectionFromPullToRefreshView();
        }
        else if (m_pTouches->count() == 2)
        {
            m_bZooming = false;
        }
        m_pTouches->removeObject(pTouch);
    }
}
示例#4
0
JS_CLASS_METHOD(JsPointBinding, Add) {
	if(argc == 2) {
		JSObject *objA;
		JSObject *objB;
		JS_ConvertArguments(context, argc, JS_ARGV(cx, vp), "oo", &objA,
				&objB);
		CCPoint *p1 = static_cast<CCPoint*>(JS_GetPrivate(context,objA));
		CCPoint *p2 = static_cast<CCPoint*>(JS_GetPrivate(context,objB));
		CCPoint p = ccpAdd(*p1,*p2);
		CCPoint *pPoint = new CCPoint(p.x,p.y);
		if(pPoint) {
			JSObject *newObj = JS_NewObject(context, &clz, obj, NULL);
			JS_SetPrivate(context, newObj, pPoint);
			JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(newObj));
		}
	}
	return JS_TRUE;
}
示例#5
0
bool RoleJoyPad::init()
{

    if ( !CCLayer::init() )
    {
        return false;
    }
    CCPoint pos = this->getPosition();
    
    //ccp(winSize.width/2-32, winSize.height/2-164-115)
    CCSprite* mask =CCSprite::create("UI_Make_rock.png");
    mask->setPosition(ccpAdd(pos, ccp(288, 290)));

    this->initData(mask);
    this->initAction();
    
    return true;
}
示例#6
0
void SGSkillItem::showPlayerStar()
{
    for(int i=0;i<arrayStar->count();i++)
    {
        CCSprite *sprite = (CCSprite*)arrayStar->objectAtIndex(i);
        sprite->removeFromParentAndCleanup(true);
    }
    
    int starCount = _card->getCurrStar();
    for(int i=0; i < starCount;i++)
    {
        CCSprite *sprite = CCSprite::createWithSpriteFrameName("xx.png");
        sprite->setAnchorPoint(ccp(0.5, 1));
        sprite->setPosition(ccpAdd(spritePlayerHead->getPosition(), ccp(spritePlayerHead->getContentSize().width+sprite->getContentSize().width*i - 17,4)));
        arrayStar->addObject(sprite);
        this->addChild(sprite);
    }
}
void CCBezierBy::update(ccTime time)
{
	if (m_pTarget)
	{
		float xa = 0;
		float xb = m_sConfig.controlPoint_1.x;
		float xc = m_sConfig.controlPoint_2.x;
		float xd = m_sConfig.endPosition.x;

		float ya = 0;
		float yb = m_sConfig.controlPoint_1.y;
		float yc = m_sConfig.controlPoint_2.y;
		float yd = m_sConfig.endPosition.y;

		float x = bezierat(xa, xb, xc, xd, time);
		float y = bezierat(ya, yb, yc, yd, time);
		m_pTarget->setPosition(ccpAdd(m_startPosition, ccp(x, y)));
	}
}
示例#8
0
//-------------------------------------------------------------------------
//
//
void CTaskEventSubGui::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
	if( m_vTaskEvent.size() <= 4 )
	{
		m_pUpScorl->setIsVisible( false );
		m_pDownScorl->setIsVisible( false );
		return;
	}

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

    CCSetIterator it = pTouches->begin();
	CCTouch* touch = (CCTouch*)(*it);

	CCPoint touchLocation = touch->locationInView( touch->view() );	
	CCPoint prevLocation = touch->previousLocationInView( touch->view() );	
	
	touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );
	prevLocation = CCDirector::sharedDirector()->convertToGL( prevLocation );
	
	CCPoint diff = ccpSub(touchLocation, prevLocation);
	CCPoint currentPos = m_pGroupNode->getPosition();
	m_pGroupNode->setPosition( ccp( currentPos.x, ccpAdd(currentPos, diff).y ) );


	m_pUpScorl->setIsVisible( true );
	m_pDownScorl->setIsVisible( true );
	if( m_pGroupNode->getPosition().y <= 0 )
	{
		m_pGroupNode->setPosition( ccp( m_pGroupNode->getPosition().x, 0 ) );
		m_pUpScorl->setIsVisible( false );

	}

	if( m_pGroupNode->getPosition().y >= m_iEachSizeDis * ( m_vTaskEvent.size() - 4) )
	{
		m_pGroupNode->setPosition( ccp( m_pGroupNode->getPosition().x, m_iEachSizeDis * ( m_vTaskEvent.size() - 4) ) );
		m_pDownScorl->setIsVisible( false );

	}


}
void CCSimpleRookieGuide::pointToRegionCenter(int regionIndex, float distance, float degree, float arrowPresetRotation) {
    // basic check
    if(regionIndex < 0 || regionIndex >= m_regions.size() || !m_arrow)
        return;

    // get region
    Region& reg = m_regions.at(regionIndex);
    CCRect& r = reg.r;
    CCPoint center = ccpAdd(r.origin, ccp(r.size.width / 2, r.size.height / 2));

    // get center of arrow sprite
    float radian = CC_DEGREES_TO_RADIANS(degree);
    center.x += distance * cosf(radian);
    center.y += distance * sinf(radian);

    // set arrow
    m_arrow->setPosition(center);
    m_arrow->setRotation(-(degree - 180 - arrowPresetRotation));
}
示例#10
0
//
// Logics - BEGIN
//
void MovingComponent::update(float dt) {
    CCPoint agentPos = m_pAgent->getPosition();
    
    if (fabsf(agentPos.x - m_uTargetPosition.x) < 2 && fabsf(agentPos.y - m_uTargetPosition.y) < 2) {
        MessageDispatcher::instance()->dispatchMessage(0, m_pAgent->getID(), m_pAgent->getID(), kMessageReachPosition, (void *)&m_uTargetPosition);
        return ;
    }
    
    CCPoint direction = ccpSub(m_uTargetPosition, agentPos);
    CCPoint n = ccpNormalize(direction);
    
    double kSpeedTweaker = 0.2;
    double k = m_eSpeedLevel * kSpeedTweaker;
    n.x *= k;
    n.y *= k;
    
    CCPoint goTo = ccpAdd(m_pAgent->getPosition(), n);
    m_pAgent->setPosition(goTo);
}
示例#11
0
void Hero::move(HeroDirection direction) 
{
	if (isHeroMoving)
		return;

	//移动的距离
	Point moveByPosition;
	//根据方向计算移动的距离
	switch (direction)
	{
	case kDown:
		moveByPosition = Vec2(0, -32);
		break;
	case kLeft:
		moveByPosition = Vec2(-32, 0);
		break;
	case kRight:
		moveByPosition = Vec2(32, 0);
		break;
	case kUp:
		moveByPosition = Vec2(0, 32);
		break;
	}
	//计算目标坐标,用当前勇士坐标加上移动距离
	targetPosition = ccpAdd(this->getPosition(), moveByPosition);
	//调用checkCollision检测碰撞类型,如果是墙壁、怪物、门,则只需要设置勇士的朝向
	CollisionType collisionType = checkCollision(targetPosition);
	if (collisionType == kWall || collisionType == kEnemy || collisionType == kDoor || collisionType == kNPC)
	{
		setFaceDirection((HeroDirection)direction);
		return;
	}
	//heroSprite仅播放行走动画
	heroSprite->runAction(sAnimationMgr->createAnimate(direction));
	//主体进行位移,结束时调用onMoveDone方法
	Action *action = Sequence::create(
		MoveBy::create(0.20f, moveByPosition),
		//把方向信息传递给onMoveDone方法
		CCCallFuncND::create(this, callfuncND_selector(Hero::onMoveDone), (void*)direction),
		NULL);
	this->runAction(action);
	isHeroMoving = true;
}
示例#12
0
bool GameMainLayer::init()
{
    if (!CCLayer::init())
        return false;
    
    CCSize size = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint originPoint = CCDirector::sharedDirector()->getVisibleOrigin();
    
    map = new GameObjMap();
    map->setAnchorPoint(ccp(0, 1));
    map->setPosition(ccpSub(ccp(0, size.height), originPoint));
    this->addChild(map, 0);
    
    hero = new GameObjHero();
    hero->setScale(0.5f);
    hero->setPosition(ccpAdd(ccp(100, 160), originPoint));
    this->addChild(hero, 1);
    
    gameMark = new GameMark();
    this->addChild(gameMark, 4);
    
    //游戏结束
    gameOver = CCSprite::create("gameover.png");
    gameOver->setScale(0.5f);
    gameOver->setPosition(ccp(size.width/2, size.height/2 + 70));
    gameOver->setVisible(false);
    this->addChild(gameOver, 5);
    
    //菜单项
    CCMenuItemImage *pCloseItem = CCMenuItemImage::create("back.png", "back.png", this, menu_selector(GameMainLayer::menuBackCallback));
    pCloseItem->setPosition(ccp(size.width/2, size.height/2 - 50));
    pCloseItem->setScale(0.5f);
    
    CCMenu *pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setPosition(CCPointZero);
    this->addChild(pMenu, 5, 25);
    pMenu->setVisible(false);
    pMenu->setEnabled(false);
    
    this->isOver = false;
    this->scheduleUpdate();
    return true;
}
示例#13
0
//初始化界面
void SGFriend::initView()
{
    CCPoint bottomCenter = SGLayout::getPoint(kBottomCenter);
    CCPoint upCenter = SGLayout::getPoint(kUpCenter);
    float h = SGMainManager::shareMain()->getTotleHdHgt();
    float b = SGMainManager::shareMain()->getBottomHeight();
	 

    
    //我的好友
//    CCSprite *spriteTitle = CCSprite::createWithSpriteFrameName("friend_myFriend.png");
    SGCCLabelTTF *spriteTitle = SGCCLabelTTF::create(str_FriendCountFull_str11, FONT_XINGKAI, 36 , COLOR_UNKNOW_TAN);
    //modify by:zyc. merge into create.
	//spriteTitle->setColor(ccc3(0xff, 0x95, 0x0c));
    spriteTitle->setPosition(ccpAdd(upCenter, ccp(0, -h+65/2)));
    this->addChild(spriteTitle);
    
    CCSprite *title_bg = CCSprite::createWithSpriteFrameName("title_bg.png");
    title_bg->setAnchorPoint(ccp(0.5, 1));
    title_bg->setPosition(ccpAdd(SGLayout::getPoint(kUpCenter), ccp(0, -h + title_bg->getContentSize().height-2)));
    this->addChild(title_bg,-1);
    
    
    float headhgt = SGMainManager::shareMain()->getTotleHdHgt();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    CCSprite *titlecenter = CCSprite::createWithSpriteFrameName("title_bg_2.png");
    titlecenter->setAnchorPoint(ccp(0.5, 0));
    titlecenter->setPosition(ccpAdd(SGLayout::getPoint(kUpCenter), ccp(0,  -headhgt- 10)));
    this->addChild(titlecenter,10);
    titlecenter->setScaleX(4);
    
    CCSprite *title_bg_l = CCSprite::createWithSpriteFrameName("title_bg_LR.png");
    title_bg_l->setAnchorPoint(ccp(0, 0));
    title_bg_l->setPosition(ccpAdd(SGLayout::getPoint(kUpCenter), ccp(-s.width/2,  -headhgt- 10)));
    this->addChild(title_bg_l,10);
    
    CCSprite *title_bg_r = CCSprite::createWithSpriteFrameName("title_bg_LR.png");
    title_bg_r->setFlipX(true);
    title_bg_r->setAnchorPoint(ccp(1, 0));
    title_bg_r->setPosition(ccpAdd(SGLayout::getPoint(kUpCenter), ccp(s.width/2,  -headhgt- 10)));
    this->addChild(title_bg_r,10);
   
    //tableview
    tableView->setFrame(CCRectMake(0, 56+101, SGLayout::getSkewing(320) , SGLayout::getSkewingY(480)-b-h));
    tableView->setZOrder(0);
    tableView->setPosition(ccpAdd(bottomCenter, ccp(-skewing(160), b)));
    this->tableViewHeight = 110;
    tableView->setDown(-18);
    //tableView -> setPageNEnable(true);
}
示例#14
0
Point IRole::getNextPointByDir()
{
	Point dest;
	int dirValue = 212;
	int dValue = 176;
	switch (direction)
	{
		case GameDirs::BACK_DIR:
		{
			dest = ccp(0, dirValue);
		}break;
		case GameDirs::LEFT_DIR:
		{
			dest = ccp(-dirValue, 0);
		}break;
		case GameDirs::RIGHT_DIR:
		{
			dest = ccp(dirValue, 0);
		}break;
		case GameDirs::FRONT_DIR:
		{
			dest = ccp(0, -dirValue);
		}break;
		case GameDirs::BACK_LEFT_DIR:
		{
			dest = ccp(-dValue, dValue);
		}break;
		case GameDirs::FRONT_RIGHT_DIR:
		{
			dest = ccp(dValue, -dValue);
		}break;
		case GameDirs::FRONT_LEFT_DIR:
		{
			dest = ccp(-dValue, -dValue);
		}break;
		case GameDirs::BACK_RIGHT_DIR:
		{
			dest = ccp(dValue, dValue);
		}break;
	}
	return ccpAdd(dest,this->getPosition()); 
}
示例#15
0
CCPoint EXZoomController::getHistoricSpeed() {
    CCPoint lastPt;
    CCPoint tPt = ccp(0,0);
    CCPoint speed = ccp(0,0);
    float   lastTime;
    int     count = 0;
    
    //Walk thru our history
    for (int i = 0; i < kEXZoomControllerHistoryCount && i < _timePointStampCounter; i++) {
        CCPanZoomTimePointStamp *record = &_history[(_timePointStampCounter-i-1) % kEXZoomControllerHistoryCount];
        
        CCPoint pt = record->pt;
        float time = record->time;
        
        //Only calculate after first
        if (i != 0) {
            //Sentinels: stop if we have large time chunks
            if ((lastTime-time) > .25)
                break;
            //or sporadic vectors past an amount of history
            if (i > 3 && vectorsDeviation(lastPt, pt) > .1)
                break;
            
            //Get a vector between two touches, but weight it with the time difference,
            //this will eliminate small quick movements and favor sweeping touches
            tPt = ccpAdd(tPt, ccpMult(ccpSub(lastPt, pt), (lastTime-time)));
            count++;
        }
        
        lastPt = pt;
        lastTime = time;
    }
    
    //Calculate speed
    if (count)
        speed = ccpMult(tPt, 1.0f/count);
    
    CCLog("tPt %f,%f",tPt.x, tPt.y);
    CCLog("count %d",count);
    CCLog("speed %f,%f",speed.x, speed.y);
    return speed;
}
示例#16
0
void GameGlobals::GeneratePolygonFormation(EEnemyFormation type, vector<CCPoint> &vertices, int num_vertices, CCRect boundary, CCPoint anchor_point)
{
	int num_polygons = 1;
	float polygon_radius = SCREEN_SIZE.width/6;
	switch(type)
	{
	case E_FORMATION_POLYGON_EASY:
		num_polygons = 1;
		polygon_radius = SCREEN_SIZE.width/6;
		break;
	case E_FORMATION_POLYGON_MEDIUM:
		num_polygons = 2;
		polygon_radius = SCREEN_SIZE.width/7;
		break;
	case E_FORMATION_POLYGON_HARD:
		num_polygons = 3;
		polygon_radius = SCREEN_SIZE.width/8;
		break;
	}

	int num_vertices_per_polygon = (int)(num_vertices/num_polygons);
	vector<CCPoint> vertices_per_polygon;
	vertices_per_polygon.clear();

	for(int i = 0; i < num_polygons; ++i)
	{
		// get the vertices of a single polygon
		GetRegularPolygonVertices(vertices_per_polygon, num_vertices_per_polygon, (i * ENEMY_RADIUS * 2.5f + polygon_radius));

		// copy the vertices into the final array
		for(int j = 0; j < num_vertices_per_polygon; ++j)
		{
			CCPoint vertex = ccpAdd(vertices_per_polygon[j], anchor_point);
			if(RECT_CONTAINS_CIRCLE(boundary, vertex, ENEMY_RADIUS*2))
			{
				vertices.push_back(vertex);
			}
		}

		vertices_per_polygon.clear();
	}
}
示例#17
0
bool RPGMapSceneLayer::doMoving(cocos2d::CCPoint targetPoint)
{
    //这里的逻辑跟RPGMapNPCRoleSprite::autoMove类似
    
    CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap);
    RPGMapRoleSprite *player = (RPGMapRoleSprite*)bgMap->getChildByTag(kRPGMapSceneLayerTagPlayer);
    CCTMXObjectGroup *obstaclesObjects = bgMap->objectGroupNamed("obstacles");
    
    targetPoint = ccpAdd(player->getPosition(), targetPoint);
    
    //地图上的障碍物
    for (int i = 0; i < obstaclesObjects->getObjects()->count(); i++)
    {
        CCDictionary *obstaclesObject = (CCDictionary*)obstaclesObjects->getObjects()->objectAtIndex(i);
        const CCString *x = obstaclesObject->valueForKey("x");
        const CCString *y = obstaclesObject->valueForKey("y");
        const CCString *width = obstaclesObject->valueForKey("width");
        const CCString *height = obstaclesObject->valueForKey("height");
        
        CCRect obstaclesRect = CCRectMake(stringToNumber<float>(x->getCString()), stringToNumber<float>(y->getCString()), stringToNumber<float>(width->getCString()), stringToNumber<float>(height->getCString()));
        
        if(obstaclesRect.containsPoint(targetPoint))
            return false;
    }
    
    //NPC或Player
    for (int i = 0; i < bgMap->getChildren()->count(); i++)
    {
        CCObject *item = bgMap->getChildren()->objectAtIndex(i);
        if(dynamic_cast<RPGMapRoleSprite*>(item) != NULL)
        {
            //如果为非player的对象才会执行里面的判断
            if(item != player)
            {
                if(((RPGMapRoleSprite*)item)->boundingBox().containsPoint(targetPoint))
                    return false;
            }
        }
    }
    
    return true;
}
示例#18
0
void CCBlade::push(CCPoint v)
{
	if (isReset) 
	{
		return;
	}
    if (CC_CONTENT_SCALE_FACTOR() != 1.0f) {
        v = ccpMult(v, CC_CONTENT_SCALE_FACTOR());
    }

	#if USE_LAGRANGE

    if (path.size() == 0) 
	{
		path.insert(path.begin(),v);        
        return;
    }
    
    CCPoint first = path[0];
    if (ccpDistance(v, first) < DISTANCE_TO_INTERPOLATE) {
        path.insert(path.begin(),v);
        if (path.size() > pointLimit) {
            path.pop_back();
        }
    }else{
        int num = ccpDistance(v, first) / DISTANCE_TO_INTERPOLATE;
        CCPoint iv = ccpMult(ccpSub(v, first), (float)1./(num + 1));
		for (int i = 1; i <= num + 1; i++) {
            path.insert(path.begin(),ccpAdd(first, ccpMult(iv, i)));
		}
		while (path.size() > pointLimit) {
			path.pop_back();
		}
    }
#else // !USE_LAGRANGE
	path.push_front(v);
	if (path.size() > pointLimit) {
		path.pop_back();
	}
#endif // !USE_LAGRANGE
	this->populateVertices();
}
示例#19
0
void CAView::setFrameOrigin(const DPoint& point)
{
    float x = m_obAnchorPointInPoints.x * m_fScaleX;
    float y = m_obAnchorPointInPoints.y * m_fScaleY;
    
    DPoint p = DPoint(x, y);
    p = ccpAdd(p, point);
    
    if (CAViewAnimation::areAnimationsEnabled()
        && CAViewAnimation::areBeginAnimations())
    {
        CAViewAnimation::getInstance()->setPoint(p, this);
        m_bFrame = true;
    }
    else
    {
        this->setPoint(p);
        m_bFrame = true;
    }
}
示例#20
0
void CCScrewOut::update(ccTime time)
{
    if(m_pTarget){
        int iStep = 180 * time;
        
        CCPoint pt = m_pTarget->getPositionInPixels();
        
        for(; m_iStep < iStep; m_iStep++){
            m_angle += 0.06;
            m_vecFactor += (0.1 + m_vecFactor2);
            m_vecFactor2 += 0.0005;
            
            m_vec.x = m_vecFactor * cos(m_angle);
            m_vec.y = m_vecFactor * sin(m_angle);

            pt = ccpAdd(pt, m_vec);
        }
        
        m_pTarget->setPositionInPixels(pt);
    }
}
//星空上加入随机闪烁的星星
void SGSpecialBattleLayer::flashStarOnSpace()
{
    
    ResourceManager::sharedInstance()->bindTexture("animationFile/flashStar.plist", RES_TYPE_LAYER_UI, sg_specialBattleLayer);
    
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    for (int i = 0; i < 3; i++)
    {
        //生成随机位置
        int posX = CCRANDOM_0_1() * (winSize.width - 30) + 15;
        int posY = CCRANDOM_0_1() * (winSize.width - 200) + 160;
        
        
        CCSpriterX *star = CCSpriterX::create("animationFile/lanxing.scml", true, true);
        this->addChild(star, 11);
        star->setanimaID(0);
        star->setisloop(true);
        star->setPosition(ccpAdd(ccp(posX, posY), ccp(0, 0)));
        star->play();
    }
}
示例#22
0
bool EnemyJoyPad::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }
//    this->setScale(0.28f);
    //ccpSub(m_ptCenter, ccp(98, 120))
    CCPoint pos = this->getPosition();
    
    CCSprite* mask =CCSprite::create("UI_Make_erock.png");
    mask->setPosition(ccpAdd(pos, ccp(82, 82)));
//    mask->setScale(1.72);
//    this->addChild(mask);
    
    this->initData(mask);
    
    m_spriteNode->setScale(0.28f);
    
    return true;
}
示例#23
0
void OzgCCSlider::sliderTouchMoved(cocos2d::CCTouch *pTouch, cocos2d::CCObject *pSelectorTarget, SEL_CallFuncN selector)
{
    if(this->m_isDrag)
    {
        //在可拖动的状态下,拖动条在可拖动区域内移动,并计算百分比后修改value值
        
        CCPoint beginPoint = pTouch->getLocation();
        CCPoint endPoint = pTouch->getPreviousLocation();
        CCPoint offSet = ccpSub(beginPoint, endPoint);
        
        CCPoint toPoint = ccpAdd(this->m_slider->getPosition(), offSet);
        if(this->m_sliderRect.containsPoint(toPoint))
        {
            this->m_slider->setPosition(ccp(toPoint.x, this->m_slider->getPosition().y));
            this->m_value = this->computingPercentage(this->m_slider, this->m_sliderRect);
        }
        
        //修改value值后执行的回调
        (pSelectorTarget->*selector)(this);
    }
}
示例#24
0
void SGTaskLayer::showMenuItemMultiMove(CCMenu *menu)
{
    EFFECT_PLAY(MUSIC_ITEM);
    
    if (menu == NULL) {
        return;
    }
//    bool isSingleRow = true;
//    CCAction *action = NULL;
    SGButton *item = NULL;
//    SGButton *ling=NULL;
    int rowCount = menu -> getChildrenCount();
    
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    CCPoint pos = CCPointZero;
    CCPoint pos2 = CCPointZero;
    
    for (int ii = 0; ii < rowCount; ii++) {
        item = (SGButton *)menu->getChildByTag(ii);
       // ling = (SGButton *)menu->getChildByTag(ii+100);
        if (item != NULL)
        {
            pos = item->getPosition();
           
            item->stopAllActions();
            
            
//新效果
             item->setPosition(ccpAdd(pos, ccp(size.width, 0)));
            
            CCMoveBy*moveby1=CCMoveBy::create(0.15f, ccp(-size.width*1.05, 0));
            CCMoveBy*moveby2=CCMoveBy::create(0.15f, ccp(size.width*0.1, 0));
            CCMoveBy*moveby3=CCMoveBy::create(0.15f, ccp(-size.width*0.05, 0));
            
            CCAction *action = CCSequence::create(CCCallFuncN::create(this, callfuncN_selector(SGTaskLayer::hide)),CCDelayTime::create(0.15f*(ii/10.0f+1)),moveby1,moveby2,moveby3,CCCallFuncN::create(this, callfuncN_selector(SGTaskLayer::show)),NULL);
            item->runAction(action);
          
        }
    }
}
示例#25
0
void Hero::move(HeroDirection direction)
{
	if(isHeroMoving)
	{
		return;
	}

	CCPoint moveByPosition;
	//根据方向计算移动的距离
	switch (direction)
	{
	case kDown:
		moveByPosition = ccp(0, -32);
		break;
	case kLeft:
		moveByPosition = ccp(-32, 0);
		break;
	case kRight:
		moveByPosition = ccp(32, 0);
		break;
	case kUp:
		moveByPosition = ccp(0, 32);
		break;
	}

	CCPoint targetPosition = ccpAdd(this->getPosition(), moveByPosition);
/*	if(checkCollision(targetPosition) == kWall)
	{
		setFaceDirection((HeroDirection)direction);
		return;
	}*/

	heroSprite->runAction(sAnimationManager->createAnimate(direction));
	CCAction *action = CCSequence::actions(CCMoveBy::actionWithDuration(0.20f, moveByPosition),
		CCCallFuncND::actionWithTarget(this,
		callfuncND_selector(Hero::onMoveDone), (void *)direction),
		NULL);
	this->runAction(action);
	isHeroMoving = true;
}
示例#26
0
void MenuLayer2::alignMenusV()
{
	for(int i=0;i<2;i++) 
	{
		CCMenu *menu = (CCMenu*)getChildByTag(100+i);
		menu->setPosition( m_centeredMenu );
		if(i==0) 
		{
			// TIP: if no padding, padding = 5
			menu->alignItemsVertically();			
			CGPoint p = menu->getPosition();
			menu->setPosition( ccpAdd(p, CGPointMake(100,0)) );			
		} 
		else 
		{
			// TIP: but padding is configurable
			menu->alignItemsVerticallyWithPadding(40);	
			CGPoint p = menu->getPosition();
			menu->setPosition( ccpSub(p, CGPointMake(100,0)) );
		}		
	}
}
 void CCParallaxScrollNode::addInfiniteScrollWithObjects(CCArray *objects, int z, const CCPoint ratio, const CCPoint &pos, const CCPoint &dir)
 {
     // NOTE: corrects for 1 pixel at end of each sprite to avoid thin lines appearing
     
     // Calculate total width and height
     float totalWidth = 0;
     float totalHeight = 0;
     for (int i = 0; i < objects->count(); i++) {
         CCSprite *object = (CCSprite *)(objects->objectAtIndex(i));
         totalWidth += object->getContentSize().width - 2;//1;
         totalHeight += object->getContentSize().height - 2;//1;
     }
     
     // Position objects, add to parallax
     CCPoint currPos = pos;
     for (int i = 0; i < objects->count(); i++) {
         CCSprite *object = (CCSprite *)(objects->objectAtIndex(i));
         addChild(object, z, ratio, currPos, ccp(totalWidth, totalHeight));
         CCPoint nextPosOffset = ccp(dir.x * (object->getContentSize().width - 2/*1*/), dir.y * (object->getContentSize().height - 2/*1*/));
         currPos = ccpAdd(currPos, nextPosOffset);
     }
 }
示例#28
0
void CATableView::loadTableCell()
{
    CCRect rect = this->getBounds();
    rect.origin.y -= rect.size.height * 0.1f;
    rect.size.height *= 1.2f;
    
    for (int i=0; i<m_rTableCellRectss.size(); i++)
    {
        for (int j=0; j<m_rTableCellRectss.at(i).size(); j++)
        {
            CAIndexPath2E indexPath = CAIndexPath2E(i, j);
            CC_CONTINUE_IF(m_pUsedTableCells.count(indexPath) && m_pUsedTableCells[indexPath]);
            CCRect cellRect = m_rTableCellRectss[i][j];
            cellRect.origin = ccpAdd(cellRect.origin, m_pContainer->getFrameOrigin());
            CC_CONTINUE_IF(!rect.intersectsRect(cellRect));
            CATableViewCell* cell = m_pTableViewDataSource->tableCellAtIndex(this, m_rTableCellRectss[i][j].size, i, j);
            
            cell->m_nSection = i;
            cell->m_nRow = j;
            m_pContainer->addSubview(cell);
            cell->setFrame(m_rTableCellRectss[i][j]);
            m_pUsedTableCells[indexPath] = cell;
            if (m_pSelectedTableCells.count(indexPath))
            {
                cell->setControlStateSelected();
            }
            
            CAView* view = this->dequeueReusableLine();
            CCRect lineRect = m_rLineRectss[i][j];
            if (view == NULL)
            {
                view = CAView::createWithFrame(lineRect, m_separatorColor);
            }
            m_pUsedLines[indexPath] = view;
            this->insertSubview(view, 1);
            view->setFrame(lineRect);
        }
    }
}
示例#29
0
void CAScrollView::closeToPoint(float delay)
{
    CCSize size = this->getContentSize();
    CCPoint point = m_pContainer->getFrameOrigin();
    CCPoint resilience = ccpSub(m_tCloseToPoint, point);
    
    if (resilience.getLength() <= 0.5f)
    {
        m_pContainer->setFrameOrigin(m_tCloseToPoint);
        CAScheduler::unschedule(schedule_selector(CAScrollView::closeToPoint), this);
        m_tCloseToPoint = CCPoint(-1, -1);
        this->hideIndicator();
    }
    else
    {
        resilience.x /= size.width;
        resilience.y /= size.height;
        resilience = ccpMult(resilience, maxBouncesSpeed(delay));
        resilience = ccpAdd(resilience, point);
        m_pContainer->setFrameOrigin(resilience);
    }
}
示例#30
0
//移动事件
void HRocker::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent)
{
	if (!isCanMove)
	{
		return;
	}
	CCPoint point = pTouch->getLocation();
	CCSprite *rocker = (CCSprite *)this->getChildByTag(tag_rocker);
	//得到摇杆与触屏点所形成的角度
	float angle = getRad(rockerBGPosition,point);
	//判断两个圆的圆心距是否大于摇杆背景的半径
	if (sqrt(pow((rockerBGPosition.x - point.x),2) + pow((rockerBGPosition.y - point.y),2)) >= rockerBGR)
	{
	
		//保证内部小圆运动的长度限制
		rocker->setPosition(ccpAdd(getAngelePosition(rockerBGR,angle),ccp(rockerBGPosition.x,rockerBGPosition.y)));
	}
	else
		rocker->setPosition(point);
	//判断方向
	if(angle>=-PI/4&&angle<PI/4)
	{
		rocketDirection=rocker_right;
		rocketRun=false;
	}
	else if(angle>=PI/4&&angle<3*PI/4)
	{
		rocketDirection=rocker_up;
	}
	else if((angle>=3*PI/4&&angle<=PI)||(angle>=-PI&&angle<-3*PI/4))
	{
		rocketDirection=rocker_left;
		rocketRun=true;
	}
	else if(angle>=-3*PI/4&&angle<-PI/4)
	{
		rocketDirection=rocker_down;
	}
}