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


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

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


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

示例1: checkForMouseTrigger

bool checkForMouseTrigger(sf::Sprite &sprite, sf::RenderWindow &window)
{
	int mouseX = sf::Mouse::getPosition().x;
	int mouseY = sf::Mouse::getPosition().y;

	sf::Vector2i windowPosition = window.getPosition();

	if (mouseX > sprite.getPosition().x + windowPosition.x && mouseX < (sprite.getPosition().x + sprite.getGlobalBounds().width + windowPosition.x)
		&& mouseY > sprite.getPosition().y + windowPosition.y + 30 && mouseY < (sprite.getPosition().y + sprite.getGlobalBounds().height + windowPosition.y + 30))
	{
		if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
		{
			return true;
		}
		return false;
	}
	return false;
}
开发者ID:strap8,项目名称:SFML-Menu,代码行数:18,代码来源:main.cpp

示例2: ClickTrigger

bool ClickTrigger(sf::Sprite &av_Sprite, sf::RenderWindow &av_Window)
{
    int mouseX = sf::Mouse::getPosition().x;
    int mouseY = sf::Mouse::getPosition().y;

    sf::Vector2i windowPosition = av_Window.getPosition();

    if(mouseX > av_Sprite.getPosition().x + windowPosition.x && mouseX < ( av_Sprite.getPosition().x + av_Sprite.getGlobalBounds().width + windowPosition.x)
        && mouseY > av_Sprite.getPosition().y + windowPosition.y + 30  && mouseY < ( av_Sprite.getPosition().y + av_Sprite.getGlobalBounds().height + windowPosition.y + 30) )
    {
        if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
        {
            return true;
        }
        return false;
    }
    return false;
}
开发者ID:erisrivera19,项目名称:Examen_Casa,代码行数:18,代码来源:main.cpp

示例3: screenToMapTransform

//Transforms mouseclicks to Map positions
sf::Vector2f screenToMapTransform(sf::Vector2i click, sf::RenderWindow& renderWindow, sf::Vector2f mapOffset)
{
	int spriteWidth = 100;
	int spriteHeight = 64;
	
	//adapt click to top of map
	sf::Vector2f screenClick;
	
	screenClick.x = click.x - renderWindow.getPosition().x - (SCREENWIDTH/2) + mapOffset.x;
	screenClick.y = click.y - renderWindow.getPosition().y - (SCREENHEIGHT/2) + mapOffset.y;
	
	//screenClick.x = renderWindow.convertCoords(click).x;
	//screenClick.y = renderWindow.convertCoords(click).y;
	
	//transform screen position to map position
	float XPos = ((screenClick.x/(spriteWidth/2)) + (screenClick.y/(spriteHeight/2)))/2;
	float YPos = ((screenClick.y/(spriteHeight/2)) - (screenClick.x/(spriteWidth/2)))/2;
	sf::Vector2f position(XPos, YPos);
	return position;
}
开发者ID:erullmann,项目名称:RTS-Project,代码行数:21,代码来源:main.cpp

示例4: update

void MapEditor::update(sf::RenderWindow &window){
	// Events
	sf::Event gEvent;
	while (window.pollEvent(gEvent)){

		if (gEvent.type == sf::Event::Closed)
			window.close();

		if (gEvent.type == sf::Event::MouseButtonPressed){
			sf::Vector2i pixel_pos = sf::Mouse::getPosition(window);
			sf::Vector2f coord_pos = window.mapPixelToCoords(pixel_pos);

			if (mMeny.menyClicked(sf::Vector2i(coord_pos))){
				MapEditor::updateInsertType();
			}
			else{
				
				int i;

				sf::Sprite clickedTile;
				switch (gEvent.mouseButton.button){

				case sf::Mouse::Left:
					if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift)){
						MapEditor::insertObject(sf::Vector2f(coord_pos.x, coord_pos.y));
					}
					else{
						sf::Vector2i pixel_pos = sf::Mouse::getPosition(window);
						sf::Vector2f coord_pos = window.mapPixelToCoords(pixel_pos);
						clickedTile = determineSelectedTileInGrid(coord_pos, &mGrid);
						// Offset applied in all tiles, counteroffset needed here to match grid.
						MapEditor::insertObject(sf::Vector2f(
							clickedTile.getPosition().x + clickedTile.getLocalBounds().width / 2
							, clickedTile.getPosition().y + clickedTile.getLocalBounds().height / 2));
					}
					break;


				case sf::Mouse::Right:
					for (i = mEntities.size() - 1; i > -1; i--){
						if (MapEditor::isSpriteClicked(mEntities[i]->getSprite(), &coord_pos)){
							MapEditor::eraseEntity(i);
							break;
						}
					}
					for (i = mTerrains.size() - 1; i > -1; i--){
						if (MapEditor::isSpriteClicked(mTerrains[i]->getSprite(), &coord_pos)){
							MapEditor::eraseTerrain(i);
							break;
						}
					}
					for (i = mDecorations.size() - 1; i > -1; i--) {
						if (MapEditor::isSpriteClicked(mDecorations[i]->getSprite(), &coord_pos)) {
							MapEditor::eraseDecoration(i);
							break;
						}
					}

					break;

				case sf::Mouse::Middle:
					MapEditor::changeInsertType();
					break;

				default:
					break;
				}
			}
		}
		if (gEvent.type == sf::Event::MouseWheelMoved){
			mCamera.zoomCameraEDITOR(gEvent);
			sf::Vector2i pixel_pos = window.getPosition();
			sf::Vector2f coord_pos = window.mapPixelToCoords(pixel_pos);
			mMeny.resetMenusPos(coord_pos);
		}

		if (gEvent.type == sf::Event::KeyPressed){
			switch (gEvent.key.code){
			case sf::Keyboard::S:
				MapEditor::saveMap();
				std::cout << "Saved..." << std::endl;
				break;
			case sf::Keyboard::Num0:
				MapEditor::changeInsertType();
				break;
			case sf::Keyboard::L:
				MapEditor::changeLayer();
				break;
			case sf::Keyboard::Delete:
				MapEditor::internalClear();
				break;
			case sf::Keyboard::R:
				MapEditor::changeRotDirection();
				break;
			case sf::Keyboard::E:
				MapEditor::changeEventType();
				break;
			case sf::Keyboard::P:
				mEventSize.y += 30;
				break;
//.........这里部分代码省略.........
开发者ID:Lallenthefikon,项目名称:Livia-Game-3.0,代码行数:101,代码来源:MapEditor.cpp

示例5:

//Common window get functions//
sf::Vector2i window_get_position(){
	return window.getPosition();
}
开发者ID:jameshea,项目名称:Imperia,代码行数:4,代码来源:game.cpp


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