【问题标题】:Trying to pinpoint 4 coordinates out of a region试图从一个区域中找出 4 个坐标
【发布时间】:2016-03-16 12:23:16
【问题描述】:

我为 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

这个检查正确且速度快得多,但点击了错误的位置。

【问题讨论】:

  • 很难说出你在问什么,findColorTap 是如何工作的?
  • findColorTap(颜色,出现,区域)。它将检查我在该区域内的代码中指定的可变颜色。如果返回的颜色与代码中的颜色匹配,那么我的手机将在找到颜色的屏幕上模拟触摸。因此,当这些黑条从我的屏幕的顶部下降到底部时,手机正在检查 x 平面上的一条线,当其中一个条穿过 y(500) 时,它将被点击。
  • 而不是检查从 100 到 600 的每个“x”。我只想检查可变颜色“0”的 4 个精确像素。但我希望它更有效率,而这可能是麻烦的地方。
  • @Matthew 为什么不让这个区域的宽度和高度只有一个像素?
  • @warspyking 我需要声明 4 个区域,因为音符可能位于四个位置。但这会成倍地增加我的 cpu 的负载。我想找到一种方法来声明 4 个坐标并在点击返回值对时不断检查这些坐标。

标签: iphone lua autotouch


【解决方案1】:

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

您调用的“其他检查”比您代码中的任何内容都非常复杂。

您无需担心您有多少行代码,您需要担心计算量昂贵的代码会被大量执行。

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

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

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

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

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

【讨论】:

  • 我喜欢在表格中设置点。这会有所帮助。对于每个 [0]、[258] 等,我应该从表中设置具体点。对于每种颜色,我需要四个 tapPoints。另外,直到最后一个街区,我都明白了一切。我是否错过了您声明 checkPoint 的地方,并且因为我真的无法理解它,所以 local note = getColors() 和 tapPoints[note] 有什么关系?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-20
  • 1970-01-01
  • 2020-04-25
  • 1970-01-01
  • 2012-11-08
相关资源
最近更新 更多