当移动物体达到Lua中的x,y坐标时采取行动。

我的脚本有两个动作:

  1. 找到球的 x1,y1 坐标。
  2. 当球到达 x,y 坐标时将其击出。

我已经进行了多次测试,但实际上物体到达脚本中设定的 x,y 坐标时没有反应。请问有人能指出问题所在吗?谢谢。

function main()
    x1, y1 = findImageFuzzy("/mnt/sdcard/b1.bmp", 90);                          ---- 找到移动物体
        if getColor(368, 653) == 0xBB0011 and x1 == 368 and y1 == 653 then      ---- 如果移动物体到达这个 x,y 坐标
            touchDown(0, 368, 653)                                              ---- 射击
            touchUp(0)
        elseif getColor(352, 756) == 0xBB0011 and x1 == 352 and y1 == 756 then
            touchDown(0, 352, 756)
            touchUp(0)
        elseif getColor(382, 468) == 0xBB0011 and x1 == 382 and y1 == 468 then
            touchDown(0, 382, 468)
            touchUp(0)
        elseif getColor(361, 551) == 0xBB0011 and x1 == 361 and y1 == 551 then
            touchDown(0, 361, 551)
            touchUp(0)
        elseif getColor(366, 467) == 0xBB0011 and x1 == 366 and y1 == 467 then
            touchDown(0, 366, 467)
            touchUp(0)
        elseif getColor(352, 620) == 0xBB0011 and x1 == 352 and y1 == 620 then
            touchDown(0, 352, 620)
            touchUp(0)
        end
end

我知道这可能是一个愚蠢的问题,但对于一个非电脑专业的人来说,你的帮助将给我带来巨大的进步。

点赞
用户3574628
用户3574628

如果球每帧移动超过一个像素,它可能无法与任何给定帧的精确坐标匹配。请改用 <=>= 而非 ==

2014-05-25 15:12:31