Lua:如何将外部功能所需的显示对象添加到显示组? [英] Lua: how do I add display objects required from external functions to display groups?

查看:108
本文介绍了Lua:如何将外部功能所需的显示对象添加到显示组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在情节提要场景中,我需要一堆来自外部函数的显示对象.当我尝试将它们添加到场景的显示组中时,出现错误期望表".

In a storyboard scene, I require a bunch of display objects from external functions. When I attempt to add these to the scene's display group, I get the error "table expected."

function scene:createScene(event)
    local group=self.view
    local shieldDisplay = shieldDisplay.new()
    group:insert(shieldDisplay)
end

外部函数如下:

function shieldDisplay.new()
    shieldDisp = display.newText("Shield: "..tostring(Cshield), 1165, 20, native.systemFont, 30)
    shieldDisp:setTextColor(9,205,235)
end
return shieldDisplay

我在做什么错了?

推荐答案

返回对象必须位于要调用的函数中.

The return object must be inside on the function that you're calling.

function shieldDisplay.new()
    local shieldDisp = display.newText("Shield: "..tostring(Cshield), 1165, 20, native.systemFont, 30)
    shieldDisp:setTextColor(9,205,235)
    return shieldDisp 
end

这篇关于Lua:如何将外部功能所需的显示对象添加到显示组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆