【问题标题】:Draggable sprite in the SFMLSFML 中的可拖动精灵
【发布时间】:2016-11-09 19:23:35
【问题描述】:

如何使用代码使精灵用鼠标拖动?我正在写战舰游戏的代码,我需要鼠标拖动的代码。

【问题讨论】:

  • 到目前为止你尝试过什么?你知道怎么画精灵吗?你知道如何捕捉鼠标输入吗?您在哪个部分遇到了问题?
  • 是的,我知道怎么画,但我在拖动时遇到了问题

标签: sfml


【解决方案1】:

首先考虑拖动时应该发生什么,

  • 点击精灵
  • 在精灵上按住左键的同时移动鼠标

既然我们已经列出了,我们现在可以考虑第二步,将其转换为伪代码。

 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. 
         }
     }
 }

你明白了吗? :)

【讨论】:

  • 你能帮忙用 sfml 代码,但不能用伪代码吗?因为我也有伪代码
  • 如果问题中没有您的代码/您尝试过的内容,我们无法为您提供任何代码
  • @AzizKobilov 我建议你阅读 sfml 网站上的教程或阅读有关 AABB 碰撞(Axis Align Bounding Box)的书
猜你喜欢
  • 1970-01-01
  • 2017-05-19
  • 2019-03-10
  • 1970-01-01
  • 2017-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-09
相关资源
最近更新 更多