小编san*_*dra的帖子

Corona SDK - 我们如何将外部函数连接到main.lua?

现在我们将所有代码都收集在main.lua中.我们不想使用面向对象的代码,但仍然找到一种将不同对象拆分为单独文件的简单方法.

在我们的main.lua文件中,我们有像水,船,男孩,岛屿和云这样的对象 - 所有这些都创造了一大堆代码.我们希望在它自己的lua文件中有"BEGIN WATER 3",并且能够使用简单的函数在main.lua中执行该代码.我们怎么做?

这是一个来自main.lua文件的例子,显示"water3":

--------------- BEGIN WATER 3 ---------------------------------------------------------

local watere = display.newImage( "water3.png", true )
game:insert( watere )
watere.y = 619
watere.x = 500
watere.xScale = 2

--water sound
local wavesound5 = media.newEventSound("waves.wav")

local function playWave5 (event)
  media.playEventSound(wavesound5)
end

local w,h = display.contentWidth, display.contentHeight

local function callbackFunc()
  print( "Transition 1 completed" )
end

local function mainwater(watere)
end

function loopar()
  local myTween = transition.to(watere, {time=2300, x=(400), y=(h-140), transition=easing.inOutQuad, onComplete=loopar2})
end

function loopar2()
  local myTween = transition.to(watere, {time=2200, …
Run Code Online (Sandbox Code Playgroud)

mobile lua function coronasdk

2
推荐指数
1
解决办法
5427
查看次数

标签 统计

coronasdk ×1

function ×1

lua ×1

mobile ×1