- Joined
- Jul 3, 2017
- Messages
- 239
A small update - sorry I couldn't do more for now since I'm @ a hospital with my father who will do a complicated exam tomorrow.
The code below will attempt 'non stop' to load an ad if it fails to load. I plan to change this later if possible for a function to manually try again instead of this. It also has other functions to retrieve the type of reward (the default returns a string 'coins') and the amount (the default returns an int, 10) - those values will reset once you show a new ad.
It alsos pause and resume your game when an ad is shown
rewardedads.cxs:
--- split to fit into messages ---
The code below will attempt 'non stop' to load an ad if it fails to load. I plan to change this later if possible for a function to manually try again instead of this. It also has other functions to retrieve the type of reward (the default returns a string 'coins') and the amount (the default returns an int, 10) - those values will reset once you show a new ad.
It alsos pause and resume your game when an ad is shown
rewardedads.cxs:
Code:
#Rem
Admob Rewarded ads module for Cerberus-X
based on Interstial ads module on brl.admob
version 1.1 - 18 November 2022
• Added suspend/resume support
• If an ad fails to load, keep trying to load it again.
• support for type and amount of rewards received
version 1.0 - 16 November 2022
• First version
----------------------------------------------------------------
Created by José Lucio "SLotman"
----------------------------------------------------------------
SETUP NEEDED:
(1) Open [project build]\android\gradletemplate\app\src\main\AndroidManifest.xml and add
just before ${ANDROID_MANIFEST_APPLICATION}:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="real_app_id_generated_by_admob_here"/>
(2) Open [project build]/android/gradletemplate/build.gradle
replace every
maven {
url "https://maven.google.com"
}
with
mavenCentral()
#End
Import mojo.app
Import mojo.graphics
Import mojo.input
#If TARGET="android"
#If ANDROID_LIBGOOGLEPLAY_AVAILABLE
Import brl.admob
#End
Import "native/rewardedads.java"
#End If
Extern
Class AdmobRewarded Extends Null = "BBAdmobRewarded"
Function GetAdmobRewarded:AdmobRewarded(adUnitId:String)
Method ShowAdViewRewarded:Void()
Method isLoaded:Bool() ' was the ad loaded?
Method earnedReward:Bool() ' did the user earned the reward?
Method isClosed:Bool() ' was the ad closed?
Method failed:Bool() ' failed to load the ad?
Method rewardAmount:Int() ' ammount of reward received
Method rewardType:String() ' type of reward received
End Class
Public
#If TARGET="android"
#ANDROID_APP_LABEL="Rewarded ads"
#ANDROID_APP_PACKAGE="com.icongames.rewardedAdsTest"
#ANDROID_SCREEN_ORIENTATION="sensorPortrait" '"user", "portrait", "landscape"
#ANDROID_VERSION_CODE="001"
#ANDROID_VERSION_NAME="0.01"
' test ads
#ADMOB_PUBLISHER_ID = "ca-app-pub-3940256099942544/5224354917"
#End
Class Game Extends App
Global IDLE:Int = 0
Global AD_VISIBLE:Int = 1
Global AD_CLOSED:Int = 2
Global UPDATE_RATE:Int = 30
Field state:Int
Field admobRewarded:AdmobRewarded
Method OnCreate()
#If TARGET="android"
' test ads
admobRewarded = AdmobRewarded.GetAdmobRewarded("ca-app-pub-3940256099942544/5224354917")
#End
SetUpdateRate UPDATE_RATE
state = IDLE
End Method
Method OnUpdate()
Select state
Case IDLE
If admobRewarded.isLoaded() Then
If TouchHit(0) Then
Print "Showing rewarded ad..."
admobRewarded.ShowAdViewRewarded()
state = AD_VISIBLE
End If
Else
' failed to load ad
If admobRewarded.failed() Then
Print "Failed to load ad!"
state = IDLE
End If
End If
Case AD_VISIBLE
If admobRewarded.isClosed() Then
state = AD_CLOSED
End If
Case AD_CLOSED
If admobRewarded.earnedReward() Then
Print "Yay! Reward earned"
Print "Reward amount:" + admobRewarded.rewardAmount()
Print "Reward type:" + admobRewarded.rewardType()
Else
Print "Sorry, no reward."
End If
state = IDLE
End Select
End Method
Method OnRender()
Cls(0,0,0)
Select state
Case IDLE
If admobRewarded.isLoaded() Then
SetColor 255,255,255
DrawText "Touch the screen to open the ad!", 10,10
End If
Case AD_VISIBLE
Case AD_CLOSED
End Select
End Method
Method OnSuspend()
Print "App suspended!"
End Method
Method OnResume()
Print "App resumed!"
End Method
End Class
Function Main()
New Game()
End Function
--- split to fit into messages ---