点击等距图块

问题描述 投票:0回答:1

问题是这个。我必须调用单击的图块的特殊方法

if (event.type == sf::Event::MouseButtonPressed)
                if(event.mouseButton.button == sf::Mouse::Left){
                    sf::Vector2f mouse = renderWindow.mapPixelToCoords(sf::Mouse::getPosition(renderWindow));
                    for (int i=0; i<tilesOnMap; i++){
                        sf::FloatRect bounds = tileMap.at(i).sprite.getGlobalBounds();
                        if (bounds.contains(mouse)){
                            std::cout << "clicked at x: "<< tileMap.at(i).axis << " and y : " << tileMap.at(i).ord<< std::endl;   //to test the position since i still have to think about the method to create an interaction menù with the tile

                        }

                    }
                }

但是由于我使用等距图块(部分透明的子画面以提供等距线),所以rects重叠,因此我总是从2个图块中得到答案。有解决方案吗?

click sprite sfml tile isometric
1个回答
0
投票

从两个图块开始,还是仅从第二个图块开始?

© www.soinside.com 2019 - 2024. All rights reserved.