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


C++ AnimatedSprite::updateSprite方法代码示例

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


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

示例1: update

/*
	update - This method should be called once per frame. It
	goes through all of the sprites, including the player, and calls their
	update method such that they may update themselves.
*/
void SpriteManager::update(Game *game)
{
	// UPDATE THE PLAYER SPRITE
		
		player.updateSprite();
		player.getPhysicalProperties()->setX(player.body->GetPosition().x / 0.01f);
		player.getPhysicalProperties()->setY(player.body->GetPosition().y / 0.01f);

		if (game->getGSM()->gravN)
		{
			//Remake the proper fixture
			b2PolygonShape box = player.getBox();
			b2FixtureDef fixtureDef = player.getFixDef();
			box.SetAsBox(player.getBoundingVolume()->getWidth() / 2 * 0.01f, player.getBoundingVolume()->getHeight() / 2 * 0.01f);
			fixtureDef.shape = &box;
			fixtureDef.density = 15.0f;
			fixtureDef.friction = 1.0f;
			player.body->CreateFixture(&fixtureDef);
			game->getGSM()->gravN = false;
		}

		if (game->getGSM()->gravR)
		{
			//Remake the proper fixture
			b2PolygonShape box = player.getBox();
			b2FixtureDef fixtureDef = player.getFixDef();
			box.SetAsBox(player.getBoundingVolume()->getHeight() / 2 * 0.01f, player.getBoundingVolume()->getWidth() / 2 * 0.01f);
			fixtureDef.shape = &box;
			fixtureDef.density = 15.0f;
			fixtureDef.friction = 1.0f;
			player.body->CreateFixture(&fixtureDef);
			game->getGSM()->gravR = false;
		}

		if (game->getGSM()->gravU)
		{
			//Remake the proper fixture
			b2PolygonShape box = player.getBox();
			b2FixtureDef fixtureDef = player.getFixDef();
			box.SetAsBox(player.getBoundingVolume()->getWidth() / 2 * 0.01f, player.getBoundingVolume()->getHeight() / 2 * 0.01f);
			fixtureDef.shape = &box;
			fixtureDef.density = 15.0f;
			fixtureDef.friction = 1.0f;
			player.body->CreateFixture(&fixtureDef);
			game->getGSM()->gravU = false;
		}

		if (game->getGSM()->gravL)
		{
			//Remake the proper fixture
			b2PolygonShape box = player.getBox();
			b2FixtureDef fixtureDef = player.getFixDef();
			box.SetAsBox(player.getBoundingVolume()->getHeight() / 2 * 0.01f, player.getBoundingVolume()->getWidth() / 2 * 0.01f);
			fixtureDef.shape = &box;
			fixtureDef.density = 15.0f;
			fixtureDef.friction = 1.0f;
			player.body->CreateFixture(&fixtureDef);
			game->getGSM()->gravL = false;
		}

		// NOW ADD THE REST OF THE SPRITES
		list<AnimatedSprite*>::iterator blockIterator;
		blockIterator = blocks.begin();
		while (blockIterator != blocks.end())
		{
			AnimatedSprite *block = (*blockIterator);
			block->getPhysicalProperties()->setX(block->body->GetPosition().x / 0.01f + 16.0f);
			block->getPhysicalProperties()->setY(block->body->GetPosition().y / 0.01f + 16.0f);
			blockIterator++;
		}

		// NOW UPDATE THE REST OF THE SPRITES
		list<AnimatedSprite*>::iterator botIterator;
		botIterator = enemies.begin();
		while (botIterator != enemies.end())
		{
			AnimatedSprite *bot = (*botIterator);
			bot->updateSprite();
			bot->getPhysicalProperties()->setX(bot->body->GetPosition().x / 0.01f);
			bot->getPhysicalProperties()->setY(bot->body->GetPosition().y / 0.01f);
			
			bot->body->SetGravityScale(0);

			if (bot->body->GetUserData() == L"walker" || bot->body->GetUserData() == L"uwalker")
			{
				bot->body->SetTransform(b2Vec2(bot->body->GetPosition().x + bot->deltaMove, bot->body->GetPosition().y), 0.0f);
				
				if ((bot->body->GetPosition().x + bot->deltaMove) / 0.01f > bot->originalx + 50.0f && bot->deltaMove > 0)
					bot->deltaMove *= -1;

				else if ((bot->body->GetPosition().x + bot->deltaMove) / 0.01f < bot->originalx - 50.0f && bot->deltaMove < 0)
					bot->deltaMove *= -1;

			}

//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


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