GithubHelp home page GithubHelp logo

Comments (3)

gumaciel avatar gumaciel commented on July 20, 2024

Hi, are you trying to set an ad size manually?

from godot-admob-android.

catabriga avatar catabriga commented on July 20, 2024

I'm not changing the ad size manually.

Here are the only scripts that interact with the addon in my code:

extends Control

var ad_view : AdView

signal ad_loaded

func _ready():
	#The initializate needs to be done only once, ideally at app launch.
	MobileAds.initialize()
	create_ad_view()
	

func create_ad_view() -> void:
	print("create_ad_view")
	var ad_switch = get_node("GameAdSwitch")
	
	if ad_switch.are_ads_enabled():
		if ad_view:
			destroy_ad_view()
			
		var unit_id = ad_switch.get_ad_unit_id()				
		ad_view = AdView.new(unit_id, AdSize.FULL_BANNER, AdPosition.Values.BOTTOM)
		
		register_ad_listener()
			
		var ad_request := AdRequest.new()
		ad_view.load_ad(ad_request)

func destroy_ad_view() -> void:
	print("destroy_ad_view")
	if ad_view:
		#always call this method on all AdFormats to free memory on Android/iOS
		ad_view.destroy()
		ad_view = null

func register_ad_listener() -> void:
	print("register_ad_listener")
	if ad_view != null:
		print("ad_view not null")
		var ad_listener := AdListener.new()

		ad_listener.on_ad_failed_to_load = func(load_ad_error : LoadAdError) -> void:
			print("_on_ad_failed_to_load: " + load_ad_error.message)
		ad_listener.on_ad_clicked = func() -> void:
			print("_on_ad_clicked")
		ad_listener.on_ad_closed = func() -> void:
			print("_on_ad_closed")
		ad_listener.on_ad_impression = func() -> void:
			print("_on_ad_impression")
		ad_listener.on_ad_loaded = func() -> void:
			print("_on_ad_loaded")
			print(ad_view.get_width(), ' ', ad_view.get_height())
			print(ad_view.get_width_in_pixels(), ' ', ad_view.get_height_in_pixels())			
			ad_loaded.emit()
		ad_listener.on_ad_opened = func() -> void:
			print("_on_ad_opened")

		ad_view.ad_listener = ad_listener

And also this one:

extends MarginContainer

# Called when the node enters the scene tree for the first time.
func _ready():
	visibility_changed.connect(_update_size)
	
	var ad_holder = get_node("/root/GameRootNode/Ad_holder")
	ad_holder.ad_loaded.connect(_update_size)

func _on_visibility_changed():
	#print("_on_visibility_changed")
	_update_size.call_deferred()

func _update_size():
	#print("_update_size")
	#var ad_holder = get_tree().get_root().find_child("Ad_holder")
	var ad_holder = get_node("/root/GameRootNode/Ad_holder")
	if ad_holder.ad_view:	
		self.custom_minimum_size.x = ad_holder.ad_view.get_width_in_pixels()
		self.custom_minimum_size.y = ad_holder.ad_view.get_height_in_pixels()
	else:
		self.custom_minimum_size.x = 0
		self.custom_minimum_size.y = 0


from godot-admob-android.

catabriga avatar catabriga commented on July 20, 2024

I have created a PR that solves this issue:
#233

from godot-admob-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.