0

嗨,我正在开发电晕 SDK 上的游戏。我只是不知道如何在其上添加 vungle 或 chartboost 激励广告并在回调后添加虚拟奖励。

我搜索了 Corona 教程,但没有找到。我可以切换到其他 SDK,但我不想这样做,因为 Corona SDK 是我最喜欢的 SDK,并且永远不会想到使用任何其他 SDK。谢谢

4

2 回答 2

2

vungle 广告的用户名是可选的,您可以在此处查看:https ://docs.coronalabs.com/plugin/vungle/show.html#parameter-reference

您可以将您的奖励代码放在“ adEnd ”事件类型上。

下面是示例代码:

--import vungle ads

local ads = require "ads"

--GET YOUR APP ID FROM VUNGLE
--TEST_Android for Android devices
local appID = "TEST_iOS"

--VUngle ADS Listener
local function vungleAdListener( event )
  if ( event.type == "adStart" and event.isError ) then
    -- Ad has not finished caching and will not play
  end
  if ( event.type == "adStart" and not event.isError ) then
    -- Ad will play
  end
  if ( event.type == "cachedAdAvailable" ) then
    -- Ad has finished caching and is ready to play
  end
  if ( event.type == "adView" ) then
    -- An ad has completed
  end
  if ( event.type == "adEnd" ) then
    -- The ad experience has been closed- this
    -- is a good place to resume your app
    -- Place your reward code here like extra lives, coins etc    

  end
end

--initialize vungle ads
--THIS MUST BE CALLED EARLY SO THAT VUNGLE WILL CACHE THE ADS TO PLAY
--USUALLY TAKES 30 SECS OR LESS ACCORDING TO THE DOCS
ads.init("vungle", appID)

--to show the ads somewhere on your game 
ads.show( "interstitial", { isAnimated=false, isBackButtonEnabled=true } )

编辑

要在按钮上显示广告,您可以添加一个小部件。要自定义小部件,您可以在此处查看更多信息:https ://docs.coronalabs.com/api/library/widget/newButton.html

--INIT WIDGET
local widget = require("widget")

--BUTTON EVENT LISTENER
local function handleButtonEvent( event )

    if ( "ended" == event.phase ) then
    --SHOW ADS        
    ads.show( "interstitial", { isAnimated=false, isBackButtonEnabled=true } )
    end
end


--ADD YOUR BUTTON
local button1 = widget.newButton
{
    left = display.contentWidth/2,
    top = display.contentHeight/2,
    id = "adsButton",
    label = "CLICK ME FOR ADS",
    onEvent = handleButtonEvent
}
于 2015-09-08T02:25:31.410 回答
0

您应该查看Chartboost 示例项目Vungle 示例项目,它们是您可以在代码中调整的示例应用程序。

关于回调,您是指服务器到服务器的回调吗?您必须查看 Vungle/Chartboost 网站以获取有关如何在其仪表板中配置回调的更多信息。

于 2015-09-07T19:12:14.203 回答