gpt4 book ai didi

c++ - 鼠标相对于 sf::view 的位置

转载 作者:行者123 更新时间:2023-11-30 03:55:08 25 4
gpt4 key购买 nike

我制作了一个以玩家 Sprite 的头像为中心的 View ,经过 3 天的头脑 Storm ,我得到的(基本上)是这个:

    xVeiwMouse = xWindowMouse - Playerx;//(new mouse coord) = (mouse coord relitive to window) - (playersprite coord)
yVeiwMouse = yWindowMosue - Playery;//same, but with y

这是行不通的。

我需要鼠标相对于以玩家为中心的 View 的坐标。

最佳答案

是这样的吗?

sf::Vector2f mouse_pos = window.mapPixelToCoords(sf::Mouse::getPosition(window));
sf::Vector2f relative = player.getPosition() - mouse_pos;

查看官方文档和教程以获得对所用功能的进一步解释。

关于c++ - 鼠标相对于 sf::view 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29201727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com