动画 corona SDK 敌人

Animate corona SDK enemies

我正在尝试在 Corona SDK 上创建一个新游戏我是 lua 语言的新手,我的目标是在一种动作游戏中拥有一组敌人。

为此我认为最好的方法是用一个数组来存储我所有的敌人,在这种情况下我使用三个。

所以我的代码是:

local enemies = {}

enemy1 = display.newImageRect( "assets/images/sheep_mini.png", 60, 60 )
enemy1.anchorX = 0
enemy1.anchorY = 0
enemy1.name = 'enemy'
enemy1.id = 1
enemy1.x, enemy1.y = 28, display.contentHeight - 260
enemy1.angularVelocity = 0
enemies[1] =enemy1 



 enemy2 = display.newImageRect( "assets/images/sheep_mini.png", 60, 60 )
enemy2.anchorX = 0
enemy2.anchorY = 0
enemy1.id = 2
enemy2.name = "enemy"
enemy2.x, enemy2.y = screenW - 120, display.contentHeight - 420
enemy2.angularVelocity = 0
enemies[2] =enemy2

所以在那之后我有一段时间迭代这个敌人敌人,但是当我尝试从数组中获取敌人时我只得到这个:

3 月 31 日 02:23:36.576:table:0x600000a66640 3 月 31 日 02:23:36.577:table:0x600000a78e00

我正在使用这段代码做 while :

  local len = #enemies
local i= 1
while i <= len do
    enemy1 = enemies[i]
    print(enemy1)
end

你能帮忙吗?我现在在电晕上,也在 lua

提前致谢

您想要实现的目标可以通过

实现
table.print(enemy1)

有关更多信息,我建议您阅读此内容:Table Serialization 其中解释了如何:

functions to serialize/unserialize a table or object (usually, not always, represented as a table), which is to convert it to and from a string representation. This is typically used for display (e.g. debugging) or storing data in a file (e.g. persistence).