void CCParallaxScrollNode::addInfiniteScrollWithObjects(const cocos2d::Vector<Sprite *>& objects, int z, Point ratio, Point pos, Point dir, Point relVel, Point padding)
{
	// 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.size(); i ++)
  {
    Sprite *object = (Sprite*) objects.at(i);
		totalWidth += object->getContentSize().width * object->getScaleX() + dir.x * padding.x;
		totalHeight += object->getContentSize().height * object->getScaleY() + dir.y * padding.y;
	}
  
	// Position objects, add to parallax
	Point currPos = pos;
  for (int i = 0; i < objects.size(); i ++)
  {
    Sprite *object = (Sprite*) objects.at(i);
		this->addChild(object, z, ratio, currPos, Point(totalWidth, totalHeight), relVel);
		Point nextPosOffset = Point(dir.x * (object->getContentSize().width * object->getScaleX() + padding.x),
                                dir.y * (object->getContentSize().height * object->getScaleY() + padding.y));
		currPos = currPos + nextPosOffset;
	}
}
예제 #2
0
ssize_t FloatingSprite::getStepIndex(const cocos2d::Vector<PathStep*> &stepVec, PathStep* step)
{
    for(ssize_t i = 0; i < stepVec.size(); i++){
        if(stepVec.at(i)->isEqual(step)){
            return i;
        }
    }
    return -1;
}
예제 #3
0
ssize_t AStar::getCellIndex(cocos2d::Vector<Cell*> &cells, Cell *cell)
{	
	for (ssize_t i = 0; i < cells.size(); ++i){
		if (cells.at(i)->isEqual(cell)){
			return i;
		}
	}
	return -1;
}
예제 #4
0
int AStarPathHelper::getIndexInVec(AStarPathUnit * unit, const cocos2d::Vector<AStarPathUnit*>& vec)
{
	int index = -1;
	for (int i = 0; i < vec.size(); ++i)
	{
		if (unit->isEqual(vec.at(i)))
		{
			index = i;
			break;
		}
	}
	// 找到返回索引值, 没找到返回-1
	return index;
}