当前位置: 首页>>代码示例>>C++>>正文


C++ SpriteFrameCache::addSpriteFramesWithFile方法代码示例

本文整理汇总了C++中SpriteFrameCache::addSpriteFramesWithFile方法的典型用法代码示例。如果您正苦于以下问题:C++ SpriteFrameCache::addSpriteFramesWithFile方法的具体用法?C++ SpriteFrameCache::addSpriteFramesWithFile怎么用?C++ SpriteFrameCache::addSpriteFramesWithFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SpriteFrameCache的用法示例。


在下文中一共展示了SpriteFrameCache::addSpriteFramesWithFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init

bool StartLayer::init()
{
	bool ret = false;
	do {
		CC_BREAK_IF(!Layer::init());

		Size s = Director::getInstance()->getWinSize();

		SpriteFrameCache *frameCache = SpriteFrameCache::getInstance();
		frameCache->addSpriteFramesWithFile("ui/shoot_background.plist", "ui/shoot_background.png");
		frameCache->addSpriteFramesWithFile("ui/shoot.plist");

		Sprite *backGround = Sprite::createWithSpriteFrameName("background.png");
		backGround->setPosition(Point(s.width * 0.5, s.height * 0.5));
		addChild(backGround, -1, 0);

		Sprite *title = Sprite::createWithSpriteFrameName("shoot_copyright.png");
		title->setPosition(Point(s.width * 0.5, s.height * 2 / 3));
		addChild(title, 0, 1);

		Sprite *gameLoad = Sprite::createWithSpriteFrameName(LOADIMAGE[0].c_str());
		gameLoad->setPosition(Point(s.width * 0.5, s.height * 0.5));
		addChild(gameLoad, 0, 2);

		Animation* animation = Animation::create();
		animation->setDelayPerUnit(0.4f);
		animation->addSpriteFrame(frameCache->getSpriteFrameByName(LOADIMAGE[0].c_str()));
		animation->addSpriteFrame(frameCache->getSpriteFrameByName(LOADIMAGE[1].c_str()));
		animation->addSpriteFrame(frameCache->getSpriteFrameByName(LOADIMAGE[2].c_str()));
		animation->addSpriteFrame(frameCache->getSpriteFrameByName(LOADIMAGE[3].c_str()));
		Animate* animate = Animate::create(animation);
		gameLoad->runAction(RepeatForever::create(animate));

		auto touchListener = EventListenerTouchOneByOne::create();
		touchListener->setSwallowTouches(true);
		touchListener->onTouchEnded = [](Touch *touch, Event *event) {
			Scene *st = Scene::create();
			BackgroundLayer *back = BackgroundLayer::create();
			st->addChild(back);
            GameLayer *gameLayer = GameLayer::create();
            st->addChild(gameLayer);

			Director::getInstance()->replaceScene(st);
			return;
		};
		touchListener->onTouchMoved = [](Touch* touch, Event* event){
			return;
		};

		touchListener->onTouchBegan = [](Touch *touch, Event *event) {
			return true;
		};
		_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
		ret = true;
	} while (0);
	return ret;
}
开发者ID:sydnash,项目名称:wexin_planefight,代码行数:57,代码来源:start_layer.cpp

示例2: init

bool WalkerLayer::init()
{
	if (!Layer::init())	{
		CCLOG("Error in init WalkerLayer!");
		return false;
	}

	float screenWidth = Director::getInstance()->getVisibleSize().width;

	SpriteFrameCache *cache = SpriteFrameCache::getInstance();
	cache->addSpriteFramesWithFile(WALKER_PLIST_PATH, WALKER_TEXTURE_PATH);

	char frameName[30];
	Sprite *walker = Sprite::create();
	walker->setAnchorPoint(Vec2(0.5f, 0.0f));
	walker->setPosition(Vec2(screenWidth * 0.5, _vPos));
	addChild(walker, 0, "walker");

	Animation *walkAnimation = Animation::create();
	for (int i = 1; i <= _frameCount; ++i) {
		sprintf_s(frameName, 20, "%s%d.png", _name.c_str(), i);
		walkAnimation->addSpriteFrame(cache->getSpriteFrameByName(frameName));
	}
	for (int i = _frameCount; i > 1; --i) {
		sprintf_s(frameName, 20, "%s%d.png", _name.c_str(), i);
		walkAnimation->addSpriteFrame(cache->getSpriteFrameByName(frameName));
	}
	walkAnimation->setLoops(-1);
	walkAnimation->setRestoreOriginalFrame(false);
	walkAnimation->setDelayPerUnit(0.2f);

	walker->runAction(RepeatForever::create(Animate::create(walkAnimation)));

	return true;
}
开发者ID:mdifferent,项目名称:Sanyu-with-cocos2dx-3.2,代码行数:35,代码来源:WalkerLayer.cpp

示例3: init

bool HeroPlane::init(){

	Size visibleSize = Director::getInstance()->getVisibleSize();
	Point origin = Director::getInstance()->getVisibleOrigin();

	SpriteFrameCache *frameCache = SpriteFrameCache::getInstance();
	frameCache->addSpriteFramesWithFile("heroplane.plist", "heroplane.png");//加载全局资源

	plane = Sprite::createWithSpriteFrameName("plane1.png");//生成飞机
	
	plane->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 5));
	this->addChild(plane, 0, 1);

	Blink *blink = Blink::create(3,8);//闪烁动画
	Animation* animation = Animation::create();
	animation->setDelayPerUnit(0.1f);
	animation->addSpriteFrame(frameCache->getSpriteFrameByName("plane1.png"));
	animation->addSpriteFrame(frameCache->getSpriteFrameByName("plane2.png"));
	Animate* animate = Animate::create(animation);//帧动画

	plane->runAction(blink);//执行闪烁动画
	plane->runAction(RepeatForever::create(animate));// 执行帧动画

	//开启触摸事件,让飞机跟随手指移动
	auto listen = EventListenerTouchOneByOne::create();
	listen->onTouchBegan = CC_CALLBACK_2(HeroPlane::onTouchBegan, this);
	listen->onTouchMoved = CC_CALLBACK_2(HeroPlane::onTouchMoved, this);
	listen->onTouchEnded = CC_CALLBACK_2(HeroPlane::onTouchEened, this);
	listen->onTouchCancelled = CC_CALLBACK_2(HeroPlane::onTouchCancelled, this);
	listen->setSwallowTouches(false);
	Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listen, this);

	return true;
}
开发者ID:appleappleapple,项目名称:GameOfShooting,代码行数:34,代码来源:HeroPlane.cpp

示例4: runAnimation

void XHelper::runAnimation(string name, int count, float time, bool isRepeat, Sprite* _sprite)
{
	if (_sprite != nullptr)
	{
		_sprite->getActionManager()->removeAllActionsFromTarget(_sprite);
		//CCLOG(&name[0]);

		SpriteFrameCache* cache = SpriteFrameCache::getInstance();
		cache->addSpriteFramesWithFile(name + ".plist");

		//Chuyển thành sprite frame
		Animation* animation = Animation::create();
		animation->setDelayPerUnit(time);
		char frameName[100];
		for (int i = 1; i <= count; i++)
		{
			sprintf(frameName, "%s%d.png", &name[0], i);
			//CCLOG("framename : %s", frameName);
			auto frame = cache->getSpriteFrameByName(frameName);
			animation->addSpriteFrame(frame);
		}

		Action* action = nullptr;
		if (isRepeat)
			action = RepeatForever::create(Animate::create(animation));
		else action = Animate::create(animation);


		_sprite->runAction(action);
	}
	else{
		log("XHelper::runAnimation : _sprite iss null");
	}

}
开发者ID:HoangDang0306,项目名称:Skater,代码行数:35,代码来源:XHelper.cpp

示例5: InitAnimation

//INITS
void GameScreen::InitAnimation()
{
	SpriteBatchNode* spritebatch = SpriteBatchNode::create("Assets/Animation/Idle.png");

	SpriteFrameCache* cache = SpriteFrameCache::getInstance();
	cache->addSpriteFramesWithFile("Assets/Animation/Idle.plist");

	_santaPaused = Sprite::createWithSpriteFrameName("Assets/Santa/idle_0001.png");
	spritebatch->addChild(_santaPaused);
	addChild(spritebatch);
	_santaPaused->setPosition(Vec2(-_winSizeW*0.5f, _winSizeH*0.7f));

	Vector<SpriteFrame*> animFrames;

	char str[100] = { 0 };
	for (int i = 1; i <= 12; i++)
	{
		sprintf(str, "Assets/Santa/idle_%04d.png", i);
		SpriteFrame* frame = cache->getSpriteFrameByName(str);
		animFrames.pushBack(frame);
	}

	Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.1f);
	_santaPaused->runAction(RepeatForever::create(Animate::create(animation)));
}
开发者ID:G012188e,项目名称:Technical-Duo-Game,代码行数:26,代码来源:GameScreen.cpp

示例6: init

bool HelloWorld::init()
{
	if ( !Layer::init() )
	{
		return false;
	}

	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();

	auto background = Sprite::create("background.png");//加载背景精灵
	background->setAnchorPoint(Vec2::ZERO);
    this->addChild(background,0);
	
	SpriteFrameCache *frameCache = SpriteFrameCache::getInstance();//单例对象
	frameCache->addSpriteFramesWithFile("SpriteSheet.plist");//加载精灵图集

    auto mountain1 = Sprite::createWithSpriteFrameName("mountain1.png");//通过精灵帧名创建精灵
	mountain1->setAnchorPoint(Vec2::ZERO);//设置锚点
    mountain1->setPosition(Vec2(-200,80));
    this->addChild(mountain1,0);

	SpriteFrame *heroSpriteFrame = frameCache->getSpriteFrameByName("hero1.png");//通过精灵帧名字获取精灵帧
	Sprite *hero1 = Sprite::createWithSpriteFrame(heroSpriteFrame);//通过精灵帧创建精灵
	//上面的两条语句相当于前面一条语句的效果auto mountain1 = Sprite::createWithSpriteFrameName("mountain1.png");
    hero1->setPosition(Vec2(800,200));
    this->addChild(hero1,0);

	return true;
}
开发者ID:zhouzhihao07,项目名称:cocos2d-x,代码行数:30,代码来源:HelloWorldScene.cpp

示例7: addCharacter

KDvoid SampleLayer::addCharacter ( KDvoid )
{
	// plist 에서 달리기 애니매이션 로딩
	SpriteFrameCache*	pFrameCache = SpriteFrameCache::getInstance ( );
	pFrameCache->addSpriteFramesWithFile ( "ch01.plist" );

	Dictionary*		pDictionary = Dictionary::createWithContentsOfFile ( "ch01_1_aniinfo.plist" );
	Array*			pAnimationList = (Array*) pDictionary->objectForKey ( "animationlist" );
	Array*			pFrameList = (Array*) pDictionary->objectForKey ( "framelist" );
	String*			pName = (String*) pDictionary->objectForKey ( "name" );
	String*			pTexture = (String*) pDictionary->objectForKey ( "texture" );
	String*			pType = (String*) pDictionary->objectForKey ( "type" );

	Dictionary*		pAnimationItem = (Dictionary*) pAnimationList->getObjectAtIndex ( 12 );

	Array*			pTemp = (Array*) pAnimationItem->objectForKey ( "FrameList" );
	KDfloat			fTemp = ( (String*) pAnimationItem->objectForKey ( "FPS" ) )->floatValue ( );

	Array*			pArraySpriteFrame = Array::createWithCapacity ( pTemp->count ( ) );

	Animation*		pAnimation = Animation::create ( );

	for ( KDint32 i = 0; i < pTemp->count ( ); i++ )
	{
		KDint		ii = ( (String*) pTemp->getObjectAtIndex ( i ) )->intValue ( );
		String*		pString = (String*) pFrameList->getObjectAtIndex ( ii );
		pAnimation->addSpriteFrame ( pFrameCache->getSpriteFrameByName ( pString->getCString ( ) ) );
	}
	pAnimation->setDelayPerUnit ( fTemp );

	Sprite*			pSprite = Sprite::createWithSpriteFrameName ( ( (String*) pFrameList->getObjectAtIndex ( 21 ) )->getCString ( ) );
	Point			tPoint = Point ( Point ( 100, 200 ) );
	Point tOffset = pSprite->getDisplayFrame ( )->getOffset ( );
	pSprite->setPosition ( tPoint - tOffset );
	
	pSprite->runAction ( RepeatForever::create ( Animate::create ( pAnimation ) ) );
	pSprite->setTag ( 10 );
	this->addChild ( pSprite );

	// Box2D body setting
	b2BodyDef		tBodyDef;
	tBodyDef.type = b2_dynamicBody;
	tBodyDef.position.Set ( tPoint.x / PTM_RATIO, tPoint.y / PTM_RATIO );
	tBodyDef.userData = pSprite;

	b2PolygonShape	tDynamicBox;
	Size tSize = pSprite->getDisplayFrame ( )->getRect ( ).size;
	tDynamicBox.SetAsBox ( tSize.width / 2 / PTM_RATIO, tSize.height / 2 / PTM_RATIO );

	m_pBody = m_pWorld->CreateBody ( &tBodyDef );

	b2FixtureDef	tFixtureDef;
	tFixtureDef.shape = &tDynamicBox;
	tFixtureDef.density = 1.0f;
	tFixtureDef.friction = 0.0f;

	m_pBody->CreateFixture ( &tFixtureDef );
}
开发者ID:mcodegeeks,项目名称:OpenKODE-Framework,代码行数:58,代码来源:SampleLayer.cpp

示例8: init

bool PlayLayer::init()
{
    if(!BaseLayer::init())
    {
        return false;
    }

    Size visibleSize = Director::getInstance()->getVisibleSize();

    MenuItemFont *back = MenuItemFont::create("back", CC_CALLBACK_1(PlayLayer::back, this));
    Menu *menu = Menu::create(back, NULL);
    menu->setPosition(visibleSize.width*9/10, visibleSize.height*9/10);

    this->addChild(menu);

    SpriteFrameCache* cache = SpriteFrameCache::getInstance();
    cache->addSpriteFramesWithFile("UI.plist", "UI.png");

    mJoystick = NULL;
    mJoystick = new SneakyJoystick();
    mJoystick->initWithRect(Rect::ZERO);
    mJoystick->setAutoCenter(true);
    mJoystick->setHasDeadzone(true);
    mJoystick->setDeadRadius(10);
    SneakyJoystickSkinnedBase* jstickSkin = new SneakyJoystickSkinnedBase();
    jstickSkin->autorelease();
    jstickSkin->init();
    jstickSkin->setBackgroundSprite(CCSprite::createWithSpriteFrameName("JoyStick-base.png"));
    jstickSkin->setThumbSprite(CCSprite::createWithSpriteFrameName("JoyStick-thumb.png"));
    //jstickSkin->getThumbSprite()->setScale(0.5f);
    jstickSkin->setPosition(visibleSize.width*1/10, visibleSize.width*1/10);
    jstickSkin->setJoystick(mJoystick);
    this->addChild(jstickSkin);

    mButtonA = NULL;
    mButtonA = new SneakyButton();
    mButtonA->initWithRect(Rect::ZERO);
    mButtonA->setIsToggleable(false);
    mButtonA->setIsHoldable(true);
    SneakyButtonSkinnedBase* btnASkin = new SneakyButtonSkinnedBase();
    btnASkin->autorelease();
    btnASkin->init();
    btnASkin->setPosition(visibleSize.width*9/10, visibleSize.width*1/10);
    btnASkin->setDefaultSprite(CCSprite::createWithSpriteFrameName("button-default.png"));
    btnASkin->setPressSprite(CCSprite::createWithSpriteFrameName("button-pressed.png"));
    btnASkin->setActivatedSprite(CCSprite::createWithSpriteFrameName("button-activated.png"));
    //btnASkin->setDisabledSprite(CCSprite::createWithSpriteFrameName("button-disabled.png"));
    btnASkin->setButton(mButtonA);
    this->addChild(btnASkin);

    this->schedule(schedule_selector(PlayLayer::inputUpdate));

    startPlay();

    return true;
}
开发者ID:hkb1990,项目名称:PracticeHand,代码行数:56,代码来源:PlayLayer.cpp

示例9: createTankWithTankType

Tank* Tank::createTankWithTankType(const char* tankTypeName, TileMapInfo* tileMapInfo)
{
    SpriteFrameCache* pCache = SpriteFrameCache::getInstance();
    pCache->addSpriteFramesWithFile("tank.plist");

    Tank* tank = new Tank();
    tank->initTankWithTankType(tankTypeName, tileMapInfo);
    tank->autorelease();

    return tank;
}
开发者ID:jypeitao,项目名称:Cocosdx-tk,代码行数:11,代码来源:Tank.cpp

示例10: initItem

KDvoid SampleLayer::initItem ( KDvoid )
{
	SpriteFrameCache*	pFrameCache = SpriteFrameCache::getInstance ( );
	pFrameCache->addSpriteFramesWithFile ( "playing_jelly.plist" );

	m_pJellyDictionary = (Dictionary*) Dictionary::createWithContentsOfFile ( "playing_jelly.plist" )->objectForKey ( "frames" );
	m_pJellyDictionary->retain ( );

	m_pItemArray = Array::create ( );
	m_pItemArray->retain ( );

	m_pTempArray = Array::create ( );
	m_pTempArray->retain ( );

	m_nItemCount = 0;
}
开发者ID:mcodegeeks,项目名称:OpenKODE-Framework,代码行数:16,代码来源:SampleLayer.cpp

示例11: addBackground

KDvoid SampleLayer::addBackground ( KDvoid )
{
	SpriteFrameCache*	pFrameCache = SpriteFrameCache::getInstance ( );
	pFrameCache->addSpriteFramesWithFile ( "tm01_bg.plist" );

	Sprite*				pSprite1 = Sprite::createWithSpriteFrameName ( "tm01_bg1.png" );
	Sprite*				pSprite2 = Sprite::createWithSpriteFrameName ( "tm01_bg2.png" );
	Sprite*				pSprite3 = Sprite::createWithSpriteFrameName ( "tm01_black.png" );
	Sprite*				pSprite4 = Sprite::create ( "floor.png" );

	pSprite1->setAnchorPoint ( Point ( 0.0f, 0.0f ) );
	pSprite2->setAnchorPoint ( Point ( 0.0f, 0.0f ) );
	pSprite3->setAnchorPoint ( Point ( 0.0f, 0.0f ) );
	pSprite4->setAnchorPoint ( Point ( 0.0f, 0.0f ) );

	pSprite1->getTexture ( )->setAliasTexParameters ( );
	pSprite2->getTexture ( )->setAliasTexParameters ( );
	pSprite3->getTexture ( )->setAliasTexParameters ( );
	pSprite4->getTexture ( )->setAliasTexParameters ( );


	Sprite*				pSprite1_1 = Sprite::createWithSpriteFrameName ( "tm01_bg1.png" );
	Sprite*				pSprite2_1 = Sprite::createWithSpriteFrameName ( "tm01_bg2.png" );
	Sprite*				pSprite3_1 = Sprite::createWithSpriteFrameName ( "tm01_black.png" );
	Sprite*				pSprite4_1 = Sprite::create ( "floor.png" );

	pSprite1_1->setAnchorPoint ( Point ( 0.0f, 0.0f ) );
	pSprite2_1->setAnchorPoint ( Point ( 0.0f, 0.0f ) );
	pSprite3_1->setAnchorPoint ( Point ( 0.0f, 0.0f ) );
	pSprite4_1->setAnchorPoint ( Point ( 0.0f, 0.0f ) );

	pSprite1_1->getTexture ( )->setAliasTexParameters ( );
	pSprite2_1->getTexture ( )->setAliasTexParameters ( );
	pSprite3_1->getTexture ( )->setAliasTexParameters ( );
	pSprite4_1->getTexture ( )->setAliasTexParameters ( );

	ParallaxScrollNode*		pParallaxNode = ParallaxScrollNode::create ( );
	
	pParallaxNode->addInfiniteScrollXWithZ ( 0, Point ( 0.5f, 0.0f ), Point ( 0, 0 ), pSprite1, pSprite1_1, KD_NULL );
	pParallaxNode->addInfiniteScrollXWithZ ( 1, Point ( 0.7f, 0.0f ), Point ( 0, 0 ), pSprite2, pSprite2_1, KD_NULL );
	pParallaxNode->addInfiniteScrollXWithZ ( 2, Point ( 1.0f, 0.0f ), Point ( 0, 0 ), pSprite4, pSprite4_1, KD_NULL );
	//pParallaxNode->addInfiniteScrollXWithZ ( 2, Point ( 1.0f, 0.0f ), Point ( 0, 0 ), pSprite3, pSprite3_1, KD_NULL );

	this->addChild ( pParallaxNode , 0, 100 );

	this->schedule ( schedule_selector ( SampleLayer::moveBackground ) );
}
开发者ID:mcodegeeks,项目名称:OpenKODE-Framework,代码行数:47,代码来源:SampleLayer.cpp

示例12: createBars

void ProgressBars::createBars(cocos2d::Layer *layerToSpawn)
{
	SpriteFrameCache* cache = SpriteFrameCache::getInstance();
	spriteBatch = SpriteBatchNode::create("Atlases/ui.png");
	cache->addSpriteFramesWithFile("Atlases/ui.plist");

	visibleSize = Director::getInstance()->getVisibleSize();

	originalBarHeight = 172;
	sideOffset = 26;
	topOffset = 10;

    //Bottom food (static)
	Sprite *foodProgressBottom = Sprite::createWithSpriteFrameName("foodBottomProgress.png");
	foodProgressBottom->setPosition(Vec2(sideOffset, (visibleSize.height/2) - originalBarHeight));
	spriteBatch->addChild(foodProgressBottom, 11);

	//Bottom timer (static)
	Sprite *timerProgressBottom = Sprite::createWithSpriteFrameName("timerBottomProgress.png");
	timerProgressBottom->setPosition(Vec2((visibleSize.width) - sideOffset, (visibleSize.height/2) - originalBarHeight));
	spriteBatch->addChild(timerProgressBottom, 11);

	//Middle of progress food left (move down as progress)
	foodProgressMiddle = Sprite::createWithSpriteFrameName("foodMiddleProgress.png");
	foodProgressMiddle->setPosition(Vec2(sideOffset, (visibleSize.height/2)));
	spriteBatch->addChild(foodProgressMiddle, 10);

	//Middle of progress timer (move down as progress)
	timerProgressMiddle = Sprite::createWithSpriteFrameName("timerMiddleProgress.png");
	timerProgressMiddle->setPosition(Vec2((visibleSize.width) - sideOffset, (visibleSize.height/2)));
	spriteBatch->addChild(timerProgressMiddle, 10);

	//Top of progress food left (move down as progress)
	foodProgressTop = Sprite::createWithSpriteFrameName("foodTopProgress.png");
	foodProgressTop->setPosition(Vec2(sideOffset, (visibleSize.height/2) + (originalBarHeight+topOffset)));
	spriteBatch->addChild(foodProgressTop, 12);

	//Top of progress timer (move down as progress)
	timerProgressTop = Sprite::createWithSpriteFrameName("timerTopProgress.png");
	timerProgressTop->setPosition(Vec2((visibleSize.width) - sideOffset, (visibleSize.height/2) + (originalBarHeight+topOffset)));
	spriteBatch->addChild(timerProgressTop, 12);

    layerToSpawn->addChild(spriteBatch);

    resetFood();
}
开发者ID:MartyGreenAce,项目名称:DonutMuncher,代码行数:46,代码来源:ProgressBars.cpp

示例13:

// on "init" you need to initialize your instance
bool InteractiveLayerV1::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    
    SpriteFrameCache* sfCache = SpriteFrameCache::getInstance();
    sfCache->addSpriteFramesWithFile("btn_lp.plist");
    sfCache->addSpriteFramesWithFile("btn_rp.plist");
    
    //使用第一帧精灵初始化对象,精灵对象的名字与plist中的名字一致
    this->_uiLPBeginFlag = Sprite::createWithSpriteFrameName("btn_lp_00.png");
    this->_uiLPBeginFlag->setPosition(Vec2(origin.x + this->LPBeginFlagPosition, origin.y + 140));
    this->addChild(this->_uiLPBeginFlag, 0);
    
    // add right began flag
    this->_uiRPBeginFlag =  Sprite::createWithSpriteFrameName("btn_rp_00.png");
    this->_uiRPBeginFlag->setPosition(Vec2(origin.y + this->RPBeginFlagPosition, origin.y + 140));
    this->addChild(this->_uiRPBeginFlag, 0);
    
    
    /*
    auto testFlag = Sprite::create("CloseNormal.png");
    testFlag->setName("testFlag");
    // position the sprite on the center of the screen
    testFlag->setPosition(Vec2(0,100));
    this->addChild(testFlag, 0);
     */
    
    //register touch event(touch all)
    auto dispatcher = cocos2d::Director::getInstance()->getEventDispatcher();
    auto listenerTA = EventListenerTouchAllAtOnce::create();
    listenerTA->onTouchesBegan = CC_CALLBACK_2(InteractiveLayerV1::onTouchsBegan, this);
    listenerTA->onTouchesEnded = CC_CALLBACK_2(InteractiveLayerV1::onTouchsEnded, this);
    listenerTA->onTouchesCancelled = CC_CALLBACK_2(InteractiveLayerV1::onTouchsCancelled, this);
    dispatcher->addEventListenerWithSceneGraphPriority(listenerTA, this);
    
    return true;
}
开发者ID:Stringbao,项目名称:bahe,代码行数:47,代码来源:InteractiveLayerV1.cpp

示例14: init

bool SpriteAnimation::init(const std::string& plist, float delay)
{
	if (!Sprite::init())
	{
		return false;
	}
	
	_animation = AnimationCache::getInstance()->getAnimation(plist);
	
	if (!_animation)
	{
		SpriteFrameCache* cache = SpriteFrameCache::getInstance();
		cache->addSpriteFramesWithFile(plist);
		
		FrameParser parser;
        Vector<SpriteFrame*> animFrames = parser.getFrames(plist);
		
		_animation = Animation::createWithSpriteFrames(animFrames, delay);
		
		AnimationCache::getInstance()->addAnimation(_animation, plist);
	}
	
    if (_animation->getFrames().empty())
    {
        return false;
    }
    
	_action = Animate::create(_animation);
	_action->retain();
	
	_repeatAction = RepeatForever::create(_action);
	_repeatAction->retain();
	
	//set the current frame to first frame of animation
	setSpriteFrame(_animation->getFrames().at(0)->getSpriteFrame());
    
	return true;
}
开发者ID:elnormous,项目名称:cocos2d-x-ext,代码行数:38,代码来源:SpriteAnimation.cpp

示例15: explode

void Item::explode(){
    //play the explode animation
    explodeIndicator = 1;
    if(haveExplode == 0){
    haveExplode=1;
    SpriteFrameCache* cache = SpriteFrameCache::getInstance();
    cache->addSpriteFramesWithFile("explode/explode.plist");
    Vector<SpriteFrame*> animFrames(14);
    char str[100]={0};
    for(int i=1; i<=14; i++){
        sprintf(str, "exp%d.png",i);
        SpriteFrame* frame = cache->getSpriteFrameByName(str);
        animFrames.insert(i-1, frame);
    }

    Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.1f);
    Animate* act = Animate::create(animation);
        
    Sequence* endAct=Sequence::create(act,CallFunc::create( std::bind(&Item::explodeEnd,this) ),NULL);
    item->runAction(endAct);

    }
}
开发者ID:LynnLinZhang,项目名称:SchoolKeeper,代码行数:23,代码来源:Item.cpp


注:本文中的SpriteFrameCache::addSpriteFramesWithFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。