Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua 如何基于数字调用函数_Lua_Coronasdk - Fatal编程技术网

Lua 如何基于数字调用函数

Lua 如何基于数字调用函数,lua,coronasdk,Lua,Coronasdk,首先,我在数组(即表格)中存储了10张1-10之间的图像作为键值,我使用0-9之间的math.random函数创建了一个随机数,我需要访问由random函数创建的值存储在数组中的图像,并需要分配触摸和移动(拖放)仅用于特定图像文件的功能。其他图像也需要触摸(即仅拖动) Ex:如果随机fn创建no为“5”,我需要拖放数组索引中存储为5的图像5.png,除5.png之外的其他图像不应能够拖放。,(即,它们可以在屏幕中移动,但不能在屏幕中拖放)您正在询问游戏的全部功能。我会向你解释基本情况。理解它,然

首先,我在数组(即表格)中存储了10张1-10之间的图像作为键值,我使用0-9之间的
math.random
函数创建了一个随机数,我需要访问由random函数创建的值存储在数组中的图像,并需要分配触摸和移动(拖放)仅用于特定图像文件的功能。其他图像也需要触摸(即仅拖动)


Ex:如果随机fn创建no为“5”,我需要拖放数组索引中存储为5的图像
5.png
,除
5.png
之外的其他图像不应能够拖放。,(即,它们可以在屏幕中移动,但不能在屏幕中拖放)

您正在询问游戏的全部功能。我会向你解释基本情况。理解它,然后做剩下的事情:

创建元素

  -- Here I'm creating them as array elements for easy access --
  local image = {}
  for i=1,10 do
    image[i] = display.newImageRect("myImage.png",20,20)
    image[i].x = 55*i
    image[i].y = 100
    image[i].tag = i
  end
因此,您可以将属性指定给每个图像,如下所示:

local function imageClicked(event)
   --[[ You can check the image tag here as event.target.tag
        and do the rest based on that. --]]
   print("Touch "..event.phase.." in image["..event.target.tag.."]")
end
for i=1,10 do
    image[i]:addEventListener("touch", imageClicked)
end
继续编码…………:)