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


C++ SpriteSheet::addAnimation方法代码示例

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


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

示例1: load

// TODO: find a cleaner way that this massive mess ?
SpriteSheet* SpriteSheetManager::load(const std::string& textureName)
{
	sf::Texture* t = new sf::Texture();
	if (!t->loadFromFile(textureName))
	{
		// BAD!
	}

	SpriteSheet* s = new SpriteSheet(*t);
	if (textureName == "Castle2.png")
	{

	}
	else if (textureName == "wood_tileset_3.png")
	{
		sf::Sprite* sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(0,0,32,32)); // only grass
		tiles[TileGame::Grass][TileGame::Grass][TileGame::Grass][TileGame::Grass] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(64,0,32,32));// grass top left
		tiles[TileGame::Grass][TileGame::Grass][TileGame::Earth][TileGame::Grass] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(64,32,32,32)); // horizontal separation (grass left)
		tiles[TileGame::Grass][TileGame::Grass][TileGame::Earth][TileGame::Earth] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(64,64,32,32)); // grass bottom left
		tiles[TileGame::Grass][TileGame::Grass][TileGame::Grass][TileGame::Earth] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(96,0,32,32)); // vertical separation (grass top)
		tiles[TileGame::Grass][TileGame::Earth][TileGame::Earth][TileGame::Grass] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(96,32,32,32));// only earth
		tiles[TileGame::Earth][TileGame::Earth][TileGame::Earth][TileGame::Earth] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(96,64,32,32));// vertical separation (grass bottom)
		tiles[TileGame::Earth][TileGame::Grass][TileGame::Grass][TileGame::Earth] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(128,0,32,32));// grass right top
		tiles[TileGame::Grass][TileGame::Earth][TileGame::Grass][TileGame::Grass] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(128,32,32,32));// horizontal separation (grass right)
		tiles[TileGame::Earth][TileGame::Earth][TileGame::Grass][TileGame::Grass] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(128,64,32,32)); // grass bottom right
		tiles[TileGame::Earth][TileGame::Grass][TileGame::Grass][TileGame::Grass] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(256,192,32,32)); // grass bottom left, top right
		tiles[TileGame::Earth][TileGame::Grass][TileGame::Earth][TileGame::Grass] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(160,224,32,32)); // grass top left, bottom right
		tiles[TileGame::Grass][TileGame::Earth][TileGame::Grass][TileGame::Earth] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(192,224,32,32)); // minimum grass bottom right
		tiles[TileGame::Earth][TileGame::Earth][TileGame::Grass][TileGame::Earth] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(224,224,32,32)); // minimum grass bottom left
		tiles[TileGame::Earth][TileGame::Grass][TileGame::Earth][TileGame::Earth] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(192,256,32,32)); // minimum grass top right
		tiles[TileGame::Earth][TileGame::Earth][TileGame::Earth][TileGame::Grass] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(224,256,32,32)); // minimum grass top left
		tiles[TileGame::Grass][TileGame::Earth][TileGame::Earth][TileGame::Earth] = sprite;
	}
	else if (textureName == "BODY_male.png")
	{
		Animation* anim = new Animation();
		anim->setSpriteSheet(*t);
		anim->addFrame(sf::IntRect(0,0,64,64));
		s->addAnimation("idleUp",anim);
		anim = new Animation();
		anim->setSpriteSheet(*t);
		anim->addFrame(sf::IntRect(0,64,64,64));
		s->addAnimation("idleLeft",anim);
		anim = new Animation();
		anim->setSpriteSheet(*t);
		anim->addFrame(sf::IntRect(0,128,64,64));
		s->addAnimation("idleDown",anim);
		anim = new Animation();
		anim->setSpriteSheet(*t);
		anim->addFrame(sf::IntRect(0,192,64,64));
		s->addAnimation("idleRight",anim);

		anim = new Animation();
		anim->setSpriteSheet(*t);
		for (int i = 1; i < 8; ++i)
			anim->addFrame(sf::IntRect(i * 64,0,64,64));
		s->addAnimation("walkUp",anim);
		anim = new Animation();
		anim->setSpriteSheet(*t);
		for (int i = 1; i < 8; ++i)
			anim->addFrame(sf::IntRect(i * 64,64,64,64));
		s->addAnimation("walkLeft",anim);
				anim = new Animation();
		anim->setSpriteSheet(*t);
		for (int i = 1; i < 8; ++i)
			anim->addFrame(sf::IntRect(i * 64,128,64,64));
		s->addAnimation("walkDown",anim);
//.........这里部分代码省略.........
开发者ID:Vrixyz,项目名称:Arena,代码行数:101,代码来源:SpriteSheetManager.cpp


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