Corona插页式点击计数

我有一个关于Corona(LUA)的问题,目前我在点击按钮时显示插页式广告。我有这个并且它工作正常(有时需要5-10-15秒才能加载广告,我不知道为什么:

local ads = require"ads"local interstitialAppID = "ca-app-pub-xxxxxxxxxx/xxxxxxxx21"
local testMode = true

local adProvider = "admob"
local function adListener( event )

if(event.isError)then
    print"Error en el anuncio!",msg)

elseif(event.phase == "loaded"then
    print"Anuncio cargado!",msg)

elseif(event.phase == "shown"then
    print"Cargando nuevo anuncio!",msg)
    ads.load"interstitial",{ appId = interstitialAppID,testMode = isTestMode })
end
end

ads.init("admob",interstitialAppID,adListener)
ads.load"interstitial",{ appId = interstitialAppID,testMode = isTestMode })

-- 插页式广告
local function Adinterstatialselfeventads.show("interstitial",{ appId = interstitialAppIDtestMode = isTestMode
})
end

local test = display.newImageRect("Lore/0.png",50,50)
test.x = 150
test.y = 150
test.tap = Adinterstatial
test:addEventListener("tap")

例如我想要实现每20次点击(所有应用程序)显示一个插页式广告,这是可能的吗?我该如何实现?

谢谢。

点赞
用户1381216
用户1381216

你可以添加一个 Runtime 的触摸事件。这将捕获屏幕上的所有触摸,无论在哪里或是点击了什么对象。例如:

local numTaps = 0
local function countTaps()
    numTaps = numTaps + 1
    if numTaps % 20 == 0 then
        -- 在此处显示添加信息。
    end
end

Runtime:addEventListener("tap", countTaps)

% 运算符获取了 numTaps 除以 20 的余数。这意味着当触摸数每增加20个时余数为 0。

2016-09-26 21:19:35