How to incorporate appodeal ads into my app?

Hi,

I am currently working on a game and I plan to insert an interstitial ad from Appodeal in a pause scene.

However, the ad only shows up the first time I click the pause button, so I wonder how exactly should I do to make it appear every time I click the pause button?

Here’s my integration code:

local appodeal = require( “plugin.appodeal” )

local function adListener( event )

 

    if ( event.phase == “init” ) then  

        – Successful initialization

        appodeal.show(“interstitial”)

 

    elseif ( event.phase == “failed” ) then  – The ad failed to load

        print( event.type )

        print( event.isError )

        print( event.response )

    end

end

 

 

appodeal.init( adListener, { appKey=“281d532d2b1cea19d51dd7531179e683c5c2a6b614c29424”, testMode = true } )

 

I inserted these codes before the scene:create function.

 

(When the pause button is clicked, a scene overlay is displayed. These codes are within the scene that overlays the current game scene.)

Hi @vyou17,

Since you’re using Composer with an overlay, you shouldn’t call “appodeal.show()” immediately after getting a successful initialization of the Appodeal plugin. Instead, you should show the ad from within the “did” phase of the “scene:show()” function of the overlay scene… and similarly, you should hide the ad (“appodeal.hide()”) when you close the overlay.

Hope this helps,

Brent

Hi Brent,

Thank you for your reply but it still is not working out for me. The ad still only shows up the first time.

Here’s my code:

 [lua]

function scene:show( event )

local sceneGroup = self.view

local phase = event.phase

if phase == “will” then

– Called when the scene is still off screen and is about to move on screen

elseif phase == “did” then

– Called when the scene is now on screen

– Initialize the Appodeal plugin

     local function adListener( event )

    if ( event.phase == “init” ) then  

        – Successful initialization

        appodeal.show(“interstitial”)

    elseif ( event.phase == “failed” ) then  – The ad failed to load

        print( event.type )

        print( event.isError )

        print( event.response )

    end

end

appodeal.init( adListener, { appKey=“281d532d2b1cea19d51dd7531179e683c5c2a6b614c29424”, testMode = true } )

– 

– INSERT code here to make the scene come alive

– e.g. start timers, begin animation, play audio, etc.

end

end [/lua]

And yes I did hide the ad when the overlay is closed; I tried both scene:destroy and scene:hide

You should only call appodeal.init() once, preferably in your main.lua (or ad network module if you have one).

(Remember to remove appodeal.show() from your listener)

In your scene’s “did” phase you can call appodeal.show(“interstitial”).

(appodeal.hide() is only used for banners. It has no effect on any other ad types and will be ignored)

Worked! Thank you so much for your help!

Hi @vyou17,

Since you’re using Composer with an overlay, you shouldn’t call “appodeal.show()” immediately after getting a successful initialization of the Appodeal plugin. Instead, you should show the ad from within the “did” phase of the “scene:show()” function of the overlay scene… and similarly, you should hide the ad (“appodeal.hide()”) when you close the overlay.

Hope this helps,

Brent

Hi Brent,

Thank you for your reply but it still is not working out for me. The ad still only shows up the first time.

Here’s my code:

 [lua]

function scene:show( event )

local sceneGroup = self.view

local phase = event.phase

if phase == “will” then

– Called when the scene is still off screen and is about to move on screen

elseif phase == “did” then

– Called when the scene is now on screen

– Initialize the Appodeal plugin

     local function adListener( event )

    if ( event.phase == “init” ) then  

        – Successful initialization

        appodeal.show(“interstitial”)

    elseif ( event.phase == “failed” ) then  – The ad failed to load

        print( event.type )

        print( event.isError )

        print( event.response )

    end

end

appodeal.init( adListener, { appKey=“281d532d2b1cea19d51dd7531179e683c5c2a6b614c29424”, testMode = true } )

– 

– INSERT code here to make the scene come alive

– e.g. start timers, begin animation, play audio, etc.

end

end [/lua]

And yes I did hide the ad when the overlay is closed; I tried both scene:destroy and scene:hide

You should only call appodeal.init() once, preferably in your main.lua (or ad network module if you have one).

(Remember to remove appodeal.show() from your listener)

In your scene’s “did” phase you can call appodeal.show(“interstitial”).

(appodeal.hide() is only used for banners. It has no effect on any other ad types and will be ignored)

Worked! Thank you so much for your help!