2016-11-09 64 views
-3

我如何使用鼠标拖动精灵,可以显示代码吗? 我正在编写战舰游戏的代码,我需要用鼠标拖动的代码。SFML中的可拖动精灵

+1

你到目前为止尝试过什么?你知道如何画一个精灵吗?你知道如何捕捉鼠标输入吗?你有哪些麻烦? – Alex

+0

是的,我知道如何绘制,但我拖动的问题 – Tessium

回答

2

想先在拖动会发生什么,

  • 点击精灵
  • 移动鼠标,同时仍持有他们离开按钮精灵

现在我们已经列出,我们现在可以考虑第二步,将其翻译成伪代码。

if (check here if the user is moving) 
{ 
    if (check here if the user is holding left button) 
    { 
     if (check here if mouse is inside the sprite) 
     { 
       set the position to the mouse pointer. 
     } 
    } 
} 

你明白了吗? :)

+0

你可以帮助sfml代码,但不是与伪代码?因为我也有伪代码 – Tessium

+0

我们不能给你任何代码没有你的代码在问题/你试过 – Treycos

+0

@AzizKobilov我建议你阅读关于sfml网站的教程或获得一本书并阅读关于AABB碰撞(轴对齐边界框) –