/*渲染*/ void GameStage::render() { //人物移动和设置手臂和身体的角度 this->hand->setRotation(this->pukaManCore->roleVo->handRotation); this->role->setRotation(this->pukaManCore->roleVo->bodyRotation); this->role->setPosition(ccp(this->pukaManCore->roleVo->x, this->pukaManCore->roleVo->y)); //运动背景移动 CCDrawNode* drawNode; float dis; int length = this->drawBgList->count(); for (int i = 0; i < length; i+=1) { drawNode = static_cast<CCDrawNode *>(this->drawBgList->objectAtIndex(i)); if (drawNode->getPositionX() < -drawNode->getContentSize().width) { //计算移到出边界后的误差,并取绝对值。 重新设置背景的位置并减轻误差。 dis = (float) abs(drawNode->getPositionX()) - drawNode->getContentSize().width; drawNode->setPositionX(drawNode->getContentSize().width - dis); } drawNode->setPositionX(drawNode->getPositionX() - this->pukaManCore->vx *.5); } //前景 length = this->frontBgList->count(); CCDrawNode* lastDrawNode; CCDrawNode* prevDrawNode; for (int i = length - 1; i >= 0; i-=1) { drawNode = static_cast<CCDrawNode *>(this->frontBgList->objectAtIndex(i)); if (drawNode->getPositionX() <-drawNode->getContentSize().width - this->stageWidth) { //计算移到出边界后的误差,并取绝对值。 重新设置背景的位置并减轻误差。 dis = (float) abs(drawNode->getPositionX()) - (drawNode->getContentSize().width + this->stageWidth); lastDrawNode = static_cast<CCDrawNode *>(this->frontBgList->objectAtIndex(length - 1)); drawNode->setPositionX(lastDrawNode->getPositionX() + this->stageWidth - dis); this->frontBgList->removeObjectAtIndex(i); this->frontBgList->addObject(drawNode); } if(i > 0) { prevDrawNode = static_cast<CCDrawNode *>(this->frontBgList->objectAtIndex(i - 1)); drawNode->setPositionX(prevDrawNode->getPositionX() + this->stageWidth); } float scale = this->pukaManCore->bgWidth / this->stageWidth; drawNode->setContentSize(CCSizeMake(this->pukaManCore->bgWidth, drawNode->getContentSize().height)); drawNode->setScaleX(scale); drawNode->setPositionX(drawNode->getPositionX() - this->pukaManCore->vx); } }
/*判断跳跃范围,只有在有背景的范围下才能跳跃*/ bool GameStage::inWallBoundaries() { CCDrawNode* drawNode; int length = this->frontBgList->count(); float left; float right; for (int i = length - 1; i >= 0; i-=1) { drawNode = static_cast<CCDrawNode *>(this->frontBgList->objectAtIndex(i)); left = drawNode->getPositionX() - this->pukaManCore->roleVo->width * .5; right = left + drawNode->getContentSize().width + this->pukaManCore->roleVo->width * .5; if(this->pukaManCore->roleVo->x >= left && this->pukaManCore->roleVo->x <= right) return true; } return false; }