Difference between revisions of "Ads"

From GiderosMobile
(Undo revision 14511 by MoKaLux (talk))
Tag: Undo
Line 3: Line 3:
 
<languages />
 
<languages />
  
'''<translate>Supported platforms</translate>:'''<br/>
+
<!-- GIDEROSOBJ:Ads -->
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
 
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/EventDispatcher|EventDispatcher]]<br/>
+
'''<translate>Supported platforms</translate>:'''
 +
<br/>
 +
'''<translate>Available since</translate>:''' Gideros 2011.6
 +
<br/>
 +
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/EventDispatcher|EventDispatcher]]
 +
<br/>
  
 
=== <translate>Description</translate> ===
 
=== <translate>Description</translate> ===
 
<translate>
 
<translate>
 
The idea is to provide common Ads interface for most of available ad frameworks, so that user's would not have to create a plugin for each of them separately, but rather it would be possible to wrap ad framework in single Java or Objective-C class (depending on the platform) and add it to the project, without even recompiling existing Ads Interface plugin.
 
The idea is to provide common Ads interface for most of available ad frameworks, so that user's would not have to create a plugin for each of them separately, but rather it would be possible to wrap ad framework in single Java or Objective-C class (depending on the platform) and add it to the project, without even recompiling existing Ads Interface plugin.
 +
<br/>
  
 
Additionally it would be able to support multiple ad frameworks simultaneously so users could switch and fall back between ad frameworks on runtime.
 
Additionally it would be able to support multiple ad frameworks simultaneously so users could switch and fall back between ad frameworks on runtime.
 +
<br/>
  
 
More information available in [http://docs.giderosmobile.com/interface/ads](Ads interface guide).
 
More information available in [http://docs.giderosmobile.com/interface/ads](Ads interface guide).
Line 17: Line 24:
  
 
=== <translate>Examples</translate> ===
 
=== <translate>Examples</translate> ===
'''Example 1: Admob'''<br/>
+
<br/>
 +
 
 +
'''Example 1: Admob'''
 +
<br/>
  
 
<source lang="lua">
 
<source lang="lua">
Line 23: Line 33:
  
 
function Ads:init()
 
function Ads:init()
 +
 
   -- ads
 
   -- ads
 
   self.ADMOB_APP_ID = "ca-app-pub-3940256099942544~3347511713" -- google test id
 
   self.ADMOB_APP_ID = "ca-app-pub-3940256099942544~3347511713" -- google test id
Line 52: Line 63:
 
   self:addEventListener("exitBegin", self.onTransitionOutBegin, self)
 
   self:addEventListener("exitBegin", self.onTransitionOutBegin, self)
 
   self:addEventListener("exitEnd", self.onTransitionOutEnd, self)
 
   self:addEventListener("exitEnd", self.onTransitionOutEnd, self)
 +
 
end
 
end
  
Line 68: Line 80:
 
end
 
end
 
</source>
 
</source>
 
+
<br/>
 +
<br/>
  
 
'''Example 2: creating fallbacks with Ads frameworks'''
 
'''Example 2: creating fallbacks with Ads frameworks'''
 +
<br/>
  
 
<source lang="lua">
 
<source lang="lua">
Line 104: Line 118:
  
 
{|-
 
{|-
 
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
 
 
=== <translate>Methods</translate> ===
 
=== <translate>Methods</translate> ===
 
[[Special:MyLanguage/Ads.new|Ads.new]] ''<translate>initializes new ad framework</translate>''<br/><!-- GIDEROSMTD:Ads.new(adframework) initializes new ad framework -->
 
[[Special:MyLanguage/Ads.new|Ads.new]] ''<translate>initializes new ad framework</translate>''<br/><!-- GIDEROSMTD:Ads.new(adframework) initializes new ad framework -->
Line 126: Line 138:
  
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
 
 
=== <translate>Events</translate> ===
 
=== <translate>Events</translate> ===
 
[[Special:MyLanguage/Event.AD_ACTION_BEGIN|Event.AD_ACTION_BEGIN]]<br/><!-- GIDEROSEVT:Event.AD_ACTION_BEGIN adActionBegin-->
 
[[Special:MyLanguage/Event.AD_ACTION_BEGIN|Event.AD_ACTION_BEGIN]]<br/><!-- GIDEROSEVT:Event.AD_ACTION_BEGIN adActionBegin-->
Line 137: Line 148:
  
 
=== <translate>Constants</translate> ===
 
=== <translate>Constants</translate> ===
 
 
|}
 
|}
  
 
{{Ads}}
 
{{Ads}}

Revision as of 11:31, 4 December 2019



Supported platforms:
Available since: Gideros 2011.6
Inherits from: EventDispatcher

Description

The idea is to provide common Ads interface for most of available ad frameworks, so that user's would not have to create a plugin for each of them separately, but rather it would be possible to wrap ad framework in single Java or Objective-C class (depending on the platform) and add it to the project, without even recompiling existing Ads Interface plugin.

Additionally it would be able to support multiple ad frameworks simultaneously so users could switch and fall back between ad frameworks on runtime.

More information available in [1](Ads interface guide).

Examples


Example 1: Admob

Ads = Core.class(Sprite) -- you need to add "Ads" and "Gaming" to your project Plugins

function Ads:init()

   -- ads
   self.ADMOB_APP_ID = "ca-app-pub-3940256099942544~3347511713" -- google test id
   self.ADMOB_UNIT_ID = "ca-app-pub-3940256099942544/6300978111" -- google test id

   -- admob (setup for simple banner adverts), note: only visible on phone/tablet
   if application:getDeviceInfo() == "Android" then
      require 'ads' --create real object for on device
      self.ADMOB = Ads.new('admob')
      self.ADMOB:setKey(self.ADMOB_APP_ID)
      self.ADMOB:addEventListener(Event.AD_RECEIVED, function() -- show ad
         self.ADMOB:showAd('banner')
--         self.ADMOB:setAlignment('center', 'bottom')
         self.ADMOB:setAlignment('center', 'top')
      end)
      self.ADMOB:addEventListener(Event.AD_FAILED, function(e) end)
      self.ADMOB:addEventListener(Event.AD_ACTION_BEGIN, function() end)
      self.ADMOB:addEventListener(Event.AD_ACTION_END, function() end)
      self.ADMOB:addEventListener(Event.AD_DISMISSED, function() end)
   else
      self.ADMOB = {} -- create fake object for testing in windows player
      self.ADMOB.loadAd = function() end
      self.ADMOB.showAd = function() end
   end

   -- LISTENERS
   self:addEventListener("enterBegin", self.onTransitionInBegin, self)
   self:addEventListener("enterEnd", self.onTransitionInEnd, self)
   self:addEventListener("exitBegin", self.onTransitionOutBegin, self)
   self:addEventListener("exitEnd", self.onTransitionOutEnd, self)

end

-- EVENT LISTENERS
function Ads:onTransitionInBegin()
end

function Ads:onTransitionInEnd()
   self.ADMOB:loadAd("banner", self.ADMOB_UNIT_ID)
end

function Ads:onTransitionOutBegin()
end

function Ads:onTransitionOutEnd()
end



Example 2: creating fallbacks with Ads frameworks

--require plugin
require "ads"

--initialize amazon
amazon = Ads.new("amazon")
amazon:setKey("amazon-key")

--initialize admob
admob = Ads.new("admob")
admob:setKey("admob-key")

--if amazon fails
--show admob
amazon:addEventListener(Event.AD_FAILED, function(e)
	print("amazon AD_FAILED", e.error)
	admob:showAd("auto")
end)

--if admob fails
--show amazon
admob:addEventListener(Event.AD_FAILED, function(e)
	print("admob AD_FAILED", e.error)
	amazon:showAd("auto")
end)

--start displaying amazon ads
amazon:showAd("auto")


Methods

Ads.new initializes new ad framework
Ads:enableTesting enable testing ads
Ads:get gets property value of the ad
Ads:getHeight gets the height of the ad
Ads:getPosition gets x and y position of the ad
Ads:getWidth gets width of the ad
Ads:getX gets x position of the ad
Ads:getY gets y position of the ad
Ads:hideAd hides ads
Ads:set sets property value of the ad
Ads:setAlignment sets alignment of the ad
Ads:setKey set keys for the framework
Ads:setPosition sets position of the ad
Ads:setX Sets x position of the ad
Ads:setY sets y position of the ad
Ads:showAd display ad

Events

Event.AD_ACTION_BEGIN
Event.AD_ACTION_END
Event.AD_DISMISSED
Event.AD_ERROR
Event.AD_FAILED
Event.AD_RECEIVED
Event.AD_REWARDED

Constants