本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
//.........这里部分代码省略.........
示例5:
//Common window get functions//
sf::Vector2i window_get_position(){
return window.getPosition();
}