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


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

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


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

示例1: main


//.........这里部分代码省略.........

		for (auto && entity : loadedLevel->currentEntities) {
			// draw all active entities in the level
			window.draw(entity.Sprite);
		}

		// Show text of talking NPCs
		if (playerQuests->triggerShowText) {

			if (playerQuests->clock.getElapsedTime().asSeconds() < 10)
				window.draw(playerQuests->talkText);

			if (playerQuests->clock.getElapsedTime().asSeconds() > 10)
				playerQuests->triggerShowText = false;
		}

		window.draw(PlayerImage);
		window.draw(playerQuests->currentQuestText);

		for (auto && item : playerInventory->currentItems) {
			// draw all items in the player invneotry
			window.draw(item.itemIconSprite);
		}

		// initiate the final draw call
		window.display();

		// Switch level, if 5 tasks have been accomplished in every map
		if (playerQuests->currentQuestId > 5 && loadedLevelIndex <= 3) {
			delete loadedLevel;
			delete playerQuests;

			loadedLevelIndex++;
			loadedLevel = levels[loadedLevelIndex];
			playerQuests = new Quests(loadedLevel);
			PlayerImage.setPosition(0.0f, 100.0f);
		}

		// Execute the Game Loop in each individual level constantly
		loadedLevel->Update(playerQuests->currentQuestId);

		//Check for left mouse clicks
		if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
		{
			sf::Vector2i localPosition = sf::Mouse::getPosition(window);
			sf::Vector2f worldPos = window.mapPixelToCoords(localPosition);
			// Move player, if cursor is in game world
			if (localPosition.y < 380 && !dragging) {
					Target1.x = worldPos.x - 100;
					Target1.y = worldPos.y - 100;
			}
			// Use item and init dragging, if cursor is in menu (bottom screen part)
			if (localPosition.y > 380 && !dragging) {

				for (auto && item : playerInventory->currentItems) {
					if (localPosition.y < item.itemIconSprite.getPosition().y + item.itemIconSprite.getGlobalBounds().height && localPosition.y   > item.itemIconSprite.getPosition().y && localPosition.x  < item.itemIconSprite.getPosition().x + item.itemIconSprite.getGlobalBounds().width && localPosition.x  > item.itemIconSprite.getPosition().x) {
						item.itemIconSprite.setPosition(localPosition.x - 32, localPosition.y - 32);
						dragging = true;
						draggeditem = &item;

					}

				}

			}


			if (draggeditem) {
				if (dragging) {
					//Set the item position to the mouse cursor position if the user is dragging it
					draggeditem->itemIconSprite.setPosition(localPosition.x - 32, localPosition.y - 32);
				}



			}
			// MOVE TO POINT via CURSOR
			float k = 1;
			// Speed Constant
			float px = PlayerImage.getPosition().x;
			float py = PlayerImage.getPosition().y;
			float ex = Target1.x;
			float ey = Target1.y;

			// "clicked" is used to not allow the player to just drag his charachter across the screen,
			// but instead the player has to confirm each charachter movement by mouse click.

			if (!clicked) {
				PlayerImage.setPosition(Target1.x, Target1.y);
			}

			clicked = true;

		}

	}


	return 0;
}
开发者ID:gotwig,项目名称:DonkeyIsland,代码行数:101,代码来源:main.cpp


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