【问题标题】:selecting an inventory item选择库存项目
【发布时间】:2016-06-02 22:52:07
【问题描述】:
/// Drag Icon
visible = oInventoryBox.visible;

if(position_meeting(mouse_x,mouse_y,oInventoryIconParent)){
    if(mouse_check_button_pressed(mb_left)){ // grab the item //
        global.heldIcon = id;
    }
}

if(global.heldIcon == id){
box = instance_nearest(mouse_x,mouse_y,oInventoryBox);
if(mouse_check_button(mb_left)){ // drag the item //
    x = mouse_x;
    y = mouse_y;
}
if(mouse_check_button_released(mb_left)){ // release the item //
    if(instance_exists(box)){
        global.boxes[boxNumber].item = box.item; // give the old box the new boxes item
        global.boxes[boxNumber].item.boxNumber = boxNumber;// give the new boxes item it's new box number
        box.item = id;                           // put the item in the new box
        boxNumber = box.boxID;                             // give this item it's new box number
    }
    box = -1; // reset box and the item being dragged.
    global.heldIcon = -1;
}
}

http://webmshare.com/WNdZd 好吧,所以我的库存被破坏了。正如您在视频中看到的那样,它似乎只抓住了这一颗种子,而忽略了其他一切。如果有人看到什么问题,那将是美丽。

还有当我在视频中出现抓取不同种子时,实际上只是我双击切换原始种子的位置。

我认为问题出在“id”上,我不确定它是否实际引用了该对象,或者它只是一些随机数。文档并没有很好地解释它,用 'self' 尝试过,但返回 -1 导致它拖动每个项目。

【问题讨论】:

    标签: inventory game-maker gml


    【解决方案1】:

    您可以使用instance_position(x,y,oInventoryBox); 来确定拾取的物品。
    我还没有测试过,但它应该返回点击项目的id,当与mouse_check_button_pressed(mb_left);结合时:

    if(mouse_check_button_pressed(mb_left))
    {
        if(position_meeting(mouse_x,mouse_y,obj))
        {
            global.clicked = instance_position(mouse_x,mouse_y,obj);
        }
    }
    
    if(mouse_check_button_released(mb_left))
    {
        global.clicked = 0;
    }
    
    if(global.clicked = id) // You can replace this with your inventory grid handler.
    {
        x = (mouse_x div 32) * 32;
        y = (mouse_y div 32) * 32;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-26
      相关资源
      最近更新 更多