试图从一个区域中精确定​​位4个坐标

时间:2015-12-10 18:27:17

标签: iphone lua autotouch

我为Piano Tiles 2创建了一个简单的宏,看看我是否可以无限期地自动化它。 我的代码在这里:

search = true
region = {100, 500, 500, 1}
while search do
    findColorTap(0, 1, region);
    findColorTap(258, 1, region);
    findColorTap(16758018, 1, region);
    usleep(5000)
end

适用于所有三个瓷砖。

--0 being jet black notes
--258 being hold notes which have a smaller "hitbox"
--16758018 being extra notes which have an even small "hitbox"

目前,脚本将从开始到结束(100-> 500)以1像素水平线检查屏幕上的每种颜色,当它返回时我需要的颜色,它将点击该像素一次。

我很好奇如何从该地区获得4分并检查那些相同的内容。 我也很好奇如果以上是可能的,Lua能够比检查区域更快或更慢地编译脚本。

我的想法是,一旦findColorTap返回我需要的值。其他检查基本上浪费了宝贵的时间。但是,我也知道代码越复杂,我的手机就越难以处理这些命令。

我试过了:

示例1

check = true

while check do
    note1 = getColor(80,500)
    note2 = getColor(240,500)
    note3 = getColor(400,500)
    note4 = getColor(560,500)
end

while check do
if note1 == 0 then
    tap(80,500)
elseif note1 == 258 then
    tap(80,500)
elseif note1 == 16758018 then
    tap(80,500)
    else
    end
end

这最终要么根本没有阅读任何音符,要么就会发现它与游戏失去同步。

示例2

function fct(startX, maxX, y, increment)
    for x=startX,maxX,160 do
        check=getColor(x,y)
        if check == 0 then
        return(x)
        end
    tap(x,y)
    end
end

v = true
repeat
fct(80,560,500) until
v == false

这个检查正确且速度更快,但却在错误的位置进行检查。

1 个答案:

答案 0 :(得分:0)

  

其他检查实质上是在浪费宝贵的时间。但是,我也知道代码越复杂,我的手机就越难以处理这些命令。

"其他检查"您的电话 比您的代码中的任何内容都要复杂得多。

您不必担心自己拥有多少行代码,因此需要担心计算中昂贵的代码会被执行很多。

  

Lua能否比检查区域更快或更慢地编译脚本。

你的意思是运行更快。编译在启动时完成一次,并不会影响运行速度。

是的,检查4个像素而不是数百个像素会更快。

  

我试过了

说出你尝试过的事情对我们没有好处,除非你告诉我们为什么它没有工作

while check do
    note1 = getColor(80,500)
    note2 = getColor(240,500)
    note3 = getColor(400,500)
    note4 = getColor(560,500)
end

while check do
    if note1 == 0 then
        tap(80,500)
    elseif note1 == 258 then
        tap(80,500)
    elseif note1 == 16758018 then
        tap(80,500)
        else
        end
    end
end

看起来它永远不会离开第一个循环(除非您在check内设置getColor)。

此外,第二个循环中的每个分支都会产生完全相同的分支。

很难说出你在问什么,但如果目标是检查指定位置的颜色,然后根据你找到的颜色点击另一个指定的位置,你可以做类似的事情这样:

-- which points to check
points = {
    { x= 80, y=500 },
    { x=240, y=500 },
    { x=400, y=500 },
    { x=560, y=500 },
}

-- map a found color to a resulting tap point
tapPoints = {
  [0]        = { x=80, y=500 }, -- these
  [258]      = { x=80, y=500 }, --   should
  [16758018] = { x=80, y=500 }, --      be different!
}

while check do
    for checkPoint in ipairs(points) do
        local note = getColor(checkPoint.x, checkPoint.y)
        local tapPoint = tapPoints[note]
        tap(tapPoint.x, tapPoint.y)
    end
end