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;
	}
}
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;
}
Example #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;
}
Example #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;
}
bool CCActivityIndicator::init()
{
    auto spritecache = SpriteFrameCache::getInstance();
    
    spritecache->addSpriteFramesWithFile("ccactivityindicator.plist");
    CCSpriteBatchNode::initWithFile("ccactivityindicator.png", 1);
    
    Size winSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    indicator = CCSprite::createWithSpriteFrameName("ccactivityindicator_1.gif");
    indicator->setPosition(Vec2(winSize.width/2,winSize.height/2));
    addChild(indicator);
    
    animating = false;
    hidesWhenStopped = true;
    
//    beginCallback = NULL;
//    endCallback =


    //load all sprite frames into array
    for (int i=1; i<=kActivityIndicatorFramesCount; i++) {
        SpriteFrame * frame = spritecache->getSpriteFrameByName(CCString::createWithFormat("ccactivityindicator_%d.gif",i)->getCString());
        frame->retain();
        spriteFrames.pushBack(frame);
    }
    
    return true;
}
Example #6
0
    void prepareAnimation(cocos2d::Vector<cocos2d::SpriteFrame *> &frameArray, const std::string &animation, int numberOfFrame){
//        CCLOG("%s, %s, %d", __func__, animation.c_str(), numberOfFrame);
        
        for (int frameIndex = 0; frameIndex < numberOfFrame; ++frameIndex){
            std::string frameName = getMonsterAnimationFrameName(_name, animation, frameIndex);
//            CCLOG("Monster 动画名字:%s", frameName.c_str());
            frameArray.pushBack(getMonsterSpriteFrameByName(frameName));
        }
    }
Example #7
0
void ScrollDoubleLayer::creatMenuScrollItem(cocos2d::Vector<WJScrollItem*> &items, int count, const char *key)
{
	m_vectorMenuItem.clear();
	for (int i = 0; i < count; i++)
	{
		ScrollMenuItem *scrollItem = ScrollMenuItem::create(this, key, i, ScrollDragDir::StopDrag, true);
		scrollItem->setClickScrollItemEvent(CC_CALLBACK_3(ScrollDoubleLayer::_doEventMenuScrollItemClick, this));
		// 默认选中了第一个
		if (i == 0) scrollItem->setItemSelect(true);

		std::string itemKey = key;
		WJUtils::stringAddInt(itemKey, i + 1, 3);
		ScrollItemTemplate object = ScrollItemTemplateTem(itemKey);
		WJScrollItem* item = WJScrollItem::create(scrollItem, 0, scrollItem->getContentSize().height + object.itemsInterval);
		items.pushBack(item);

		// 当前1级菜单的数组
		m_vectorMenuItem.push_back(scrollItem);
	}
}
Example #8
0
void initMenuItems(cocos2d::Vector<cocos2d::MenuItem*>& menuItems, const std::string& name, const ccMenuCallback& callback) {
    MenuItemFont *menuItem = MenuItemFont::create(name, callback);
    menuItems.pushBack(menuItem);
}