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


C++ SpriteManager::GetAllSprites方法代码示例

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


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

示例1: main

int main() {
	
    sf::RenderWindow App(sf::VideoMode(DemoConstants::SCREEN_WIDTH, DemoConstants::SCREEN_HEIGHT, 32), "SFML Graphics");

	sf::Shape lines[6];
	for(int i = 1; i < 4; ++i) {
		lines[i-1] = sf::Shape::Line(0,DemoConstants::CELLSIZE*i, DemoConstants::SCREEN_WIDTH, DemoConstants::CELLSIZE*i, 1, sf::Color::White);
		lines[i+2] = sf::Shape::Line(DemoConstants::CELLSIZE*i,0, DemoConstants::CELLSIZE*i, DemoConstants::SCREEN_HEIGHT, 1, sf::Color::White);
	}
	

	// How to load an image
	sf::Image image;
    

	// How to create a sprite from that image.
	CustomSprite::Init("chromatic_circle.png");

	// Make an instance of our sprite manager.
	SpriteManager spriteManager;

	//Create an instance of the map manager
	MapManager mapManager;
	//Create an instance of the collision manager
	CollisionManager * m_pCollisionManager = CollisionManager::instance();
	CustomSprite * theChosenOne;
	vector<CustomSprite *> & allSprites = spriteManager.GetAllSprites();
	list<CustomSprite *> nearbySprites;

	theChosenOne = allSprites.at(8);
	App.SetFramerateLimit(120);
	
    // Start game loop
    while (App.IsOpened())
    {
		
        // Process events
        sf::Event Event;
	
        while (App.PollEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

		
        // Clear the screen (fill it with black color)
        App.Clear();
		
		
		// How to draw a line.
		for(int i = 0; i < 6; ++i) {
			App.Draw(lines[i]);
		}

		//Mouse Input
		if (sf::Mouse::IsButtonPressed(sf::Mouse::Left)) {
			//Check Collision mouse
			for (int i = 0; i < allSprites.size(); ++i) {
				if (sf::Mouse::GetPosition(App).x % ((int)allSprites.at(i)->GetPosition().x+1) < (allSprites.at(i)->radius() * 2)
					&& sf::Mouse::GetPosition(App).y % ((int)allSprites.at(i)->GetPosition().y+1) < (allSprites.at(i)->radius() * 2)) {
						theChosenOne = allSprites.at(i);
				}
			}
		}



		//Add all the sprites to their buckets
		for (int i = 0; i < allSprites.size(); ++i){
			mapManager.RegisterSprite(allSprites.at(i));
		}
		theChosenOne->SetColor(sf::Color(255, 255, 255));
		
		//Get the list of sprites nearby
		nearbySprites = mapManager.GetNearbySprites(theChosenOne);
		list<CustomSprite *>::iterator iter = nearbySprites.begin();
		//Collision check with nearby sprites
		for (int i = 0; i < nearbySprites.size(); ++i, ++iter) {
			if (m_pCollisionManager->CheckCollision(theChosenOne, *iter) == true) {
				iter.operator*()->reverse();
				theChosenOne->reverse();
			}
			iter.operator*()->SetColor(sf::Color(150, 150, 150));
		}


		//Update the sprites, includes keeping them within 
		//the boundaries of the window
		spriteManager.updateSprites();
	
		// How to draw a container of sprites.
		for ( int i = 0; i < allSprites.size(); ++i ) {							
			App.Draw( * allSprites.at(i) );
			allSprites.at(i)->SetColor(sf::Color(50, 50, 50));
		}
		
		mapManager.ClearBucketLists();

//.........这里部分代码省略.........
开发者ID:RonanFarrell,项目名称:2D-Spatial-Hashing-for-Efficient-Collision-Detection,代码行数:101,代码来源:SpriteDemo.cpp


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