GameMaker Studio 2点击拖动平铺选择

时间:2017-07-27 07:03:24

标签: multipleselection gml game-maker-studio-2

我想实现一种简单的方法来选择一个tilemap的一部分,尽管我在你拖动时坚持更新所选区域的数学。

我花了大约12个小时重新研究并尝试不同的事情,看看我是否可以让它正常工作。我不认为这会像现在这样艰难。

我首选的实现选择的方法是使用四个变量: selection_x - 选择左上角的X位置 selection_y - 选择左上角的Y位置 selection_w - 选择的宽度 selection_h - 选择的高度

scrips tilex()和tiley()返回鼠标所在的平铺X / Y,计算缩放和视图偏移。

这是我的尝试:

if(mouse_check_button_pressed(mb_left)) {
  selecting = true;
  selection_start = [tilex(), tiley()];
  selection_stop = [tilex() + 1, tiley() + 1];

  selection_x = tilex();
  selection_y = tiley();
  selection_w = 0;
  selection_h = 0;
} else if(mouse_check_button(mb_left)) {
  var old = selection_x;
  selection_x = tilex() >= selection_x + selection_w ? tilex() : selection_x;
  selection_w = tilex() >= selection_x + selection_w ? tilex() - selection_x : (old - selection_x);

  var old = selection_y;
  selection_y = tiley() >= selection_y + selection_h ? tiley() : selection_y;
  selection_h = tiley() >= selection_y + selection_h ? tiley() - selection_y : (old - selection_y);
  /*
  if(selection_x >= tilex()) {
    var old = selection_x;
    selection_x = tilex();
    selection_w += old - selection_x ;

    selection_stop[0] = tilex() + 1;
    show_debug_message("x 0");
  } else if(selection_x + selection_w <= tilex()) {
    selection_w = tilex() - selection_x + 1;

    selection_start[0] = tilex();
    show_debug_message("x 1");
  }


  if(selection_y >= tiley()) {
    var old = selection_y;
    selection_y = tiley();
    selection_h += old - selection_y;;

    selection_stop[1] = tiley() + 1;
    show_debug_message("y 0");
  } else if(selection_y + selection_h <= tiley()) {
    selection_h = tiley() - selection_y + 1;

    selection_start[1] = tiley();
    show_debug_message("y 1");
  }
  */
  /*
  if(selection_x > tilex() && selection_y > tiley()) {

  } else if(selection_x < tilex() && selection_y < tiley()) {
    selection_x = tilex();
    selection_y = tiley();
    selection_w = selection_x - tilex();
    selection_h = selection_y - tiley();
  }
  */
  /*
  if(selection_start[0] > selection_stop[0] || selection_start[1] < selection_stop[1]) {
    //selection_start = [tilex(), tiley()];
  } else {
    selection_stop = [tilex() + 1, tiley() + 1];
  }
  */
}

感谢阅读!希望这可以很快得到解决。   - Searous&lt; 3

0 个答案:

没有答案