2014-02-26 25 views
3

下面是我写的一个简单游戏的代码的一部分,我试图发送一个包含用户在菜单屏幕上花费的时间的电子邮件。我不确定在哪里调用选项功能。如何在corona中调用此代码发送电子邮件的功能?

--Send a email to my own address 
local options = 
{ 
to = "[email protected]", 
subject = "Time spent at the menu screen", 
body = "This is the time I spent to look at the menu"..(os.time() - startTime), 
} 
native.showPopup("mail", options) 

--Function that initializes all game logic 
function Main() 
splash:removeSelf() 
splash = nil 

playGame = display.newImage("Play Button.png") 
tutorial = display.newImage("Tutorial Button.png") 
credits = display.newImage("Credits Button.png") 

playGame.x = display.contentWidth/2 
playGame.y = display.contentWidth - 187 
tutorial.x = display.contentWidth/2 
tutorial.y = display.contentWidth - 130 
credits.x = display.contentWidth/2 
credits.y = display.contentWidth - 73 

startButtonListeners('add') 
end 

--Adds listeners to the button in menu screen 
function startButtonListeners(action) 
    if (action == 'add') then 
      playGame:addEventListener ('tap', showGameView) 
      credits: addEventListener ('tap', showCredits) 
      tutorial: addEventListener ("tap", showTutorial) 
    else 
     playGame:removeEventListener ('tap', showGameView) 
     print("Time spent at menu screen: ", (os.time() - startTime)) 
     credits: removeEventListener ('tap', showCredits) 
     tutorial: removeEventListener ('tap', showTutorial) 
      end 
end 

回答

2

我无法完全理解您的需求。我想,当你离开屏幕或游戏结束时,你必须发送电子邮件到特定的地址。所以,当你的游戏结束时,或者当你通过触发一个按钮离开屏幕时,你可以在里面调用一个带有options的函数。就像下面:

local function sendMail() 
    local options = 
    { 
    to = "[email protected]", 
    subject = "Time spent at the menu screen", 
    body = "This is the time I spent to look at the menu"..(os.time() - startTime), 
    } 
    native.showPopup("mail", options) 
end 

... 
... 
... 
sendMail() -- Call this when the game is over/before you leave the scene 

欲了解更多信息,请参考以下链接太:How to mail a screen captured image using corona SDK

保持编码............. :)

+0

谢谢,这是重量我在找。顺便说一句,有没有一种方法来测试,而不是代码在电脑上工作?我跑了代码,但似乎没有发生任何事,我找不到电子邮件。 – user3305142

+1

电晕本机邮件弹出窗口在电晕模拟器上不起作用。您必须构建Xcode模拟器或设备来测试它... –

相关问题