Solution to AdMob / PubCenter / IAP and others...?

Monkey Targets Forums/Windows 8/Solution to AdMob / PubCenter / IAP and others...?

SLotman(Posted 2014) [#1]
I just found out this page:
https://github.com/chukong/cocos-docs/blob/master/manual/framework/native/v2/sdk-integration/wp8-thirdSDK/en.md

And it shows somehow a way to communicate between the c# layer and the c++ layer of the application...!

Ok, it talks a lot about cocos2d-x, and I'm still trying to wrap my mind around the code - but I'm quite positive this would give us means to show/hide ads in the C++ side, integrate IAP and more.

What do you guys think? Any insights?


dragon(Posted 2014) [#2]
iap is working out of the box here in monkey
admob works with custom code, but you can not hide it...
mark should add admob support


SLotman(Posted 2014) [#3]
admob works with custom code, but you can not hide it...

That's exactly the problem the link above tried to fix. The same thing happens with Pubcenter.


Shockblast(Posted 2014) [#4]
Nice find, Slotman. So it is indeed doable somehow. I'm going to try and follow that tutorial when I have time. Did you managed to get it working?


SLotman(Posted 2015) [#5]
I still didn't manage to get this running, but I just found a LOT of code for cocos-2d-x, maybe it can be adapted to Monkey somehow?

http://stackoverflow.com/questions/28533001/admob-interstitial-cocos2d-x-wp8

Edit: Also, this: http://www.robwirving.com/2014/07/21/calling-c-methods-c-winrt-components/

(adding links here so I can come back to it later)


Xaron(Posted 2015) [#6]
Will check it. :)


Ferdi(Posted 2015) [#7]
I have managed to get Admob Interstitial working on Windows Phone 8.0. It was a nightmare getting this going, and I can sometime see that it works may be 99% of the time, and there is a reset problem popping here and there =) So if you want this, test it over and over again.

Admob for Windows Phone only works in 8.0. It does NOT work on 8.1. You will always get the error "No Fill". If you go to Admob groups for Windows Phone, you will see alot of people asking for 8.1 support:

https://groups.google.com/forum/#!categories/google-admob-ads-sdk/windows-phone-8

I have also managed to get Smaato going but there fill rate is so low, like 2% low. You will be getting like 1 cent a day, if you are lucky =P haha

Anyway, I needed other functionality that is in 8.1 and not in 8.0. So I won't be using ads, and I will be just selling some IAP.

Where to start?

When I was going through MainPage.xaml.cs, I noticed this function:

using System.Diagnostics;   // For Debug.WriteLine - very useful!	
...
        private void ActivateKeyboard( bool activate ){
            Debug.WriteLine("Yeah! Mark has done all the hard stuff for us!");
            if (activate)
            {
                KeyboardTextBox.IsEnabled = true;
                KeyboardTextBox.Focus();
            }
            else
            {
                KeyboardTextBox.IsEnabled = false;
            }
        }
 ...


So I quickly put using System.Diagnostics and put a Debug.Writeline. I then created a banana in Monkey Code that when I press the screen it calls EnableKeyboard(). This is my starting point, I just had to follow Mark's code from EnableKeyboard in Monkey to ActivateKeyboard in C#.

I actually modified the ActivateKeyboard and see whether I can display ad from there. Then at least I know that works, and it did. So the next step is ...

Following Mark's C# <-> C++

Ok here we go ... ready ready =) ... I am just going to dump it here. I really want to finish my game.

File: modules/brl/gametarget.monkey

	Method SetKeyboardEnabled:Void( enabled:Bool )

	Method CreateAd:Void(unitId:String)
	Method ShowAd:Void()
	Method RequestAd:Void()
	Method IsAdAvailable:Bool()
	Method IsAdComplete:Bool()


File: modules/brl/native/gametarget.winrt.cpp



I suggest you create a new target.

File: targets/winrt_winphone8/modules/native/monkeytarget.cpp



File: targets/winrt_winphone8/modules/template/MonkeyGame.PhoneComponent.h



Finally we are at C#.

File: targets/winrt_winphone8/modules/template/MainPage.xaml.cs



I think I got everything. If not just follow Mark's code from EnableKeyboard in Monkey to ActivateKeyboard in C#.

Hope it helps.


SLotman(Posted 2015) [#8]
Thanks Ferdi, this is great!!!

Very sad to hear about Admob though :(
Specially since Microsoft "forced" me into WP8.1 to re-activate my phone :(


Ferdi(Posted 2015) [#9]
NP SLotman

Sorry for my poor explanation, I worry you misunderstand me in regard to Admob not working in WP8.1. It is not the phone version, it is the Visual Studio Project version. So you can still get it working on your "forced" WP8.1.

Open up "MonkeyGame.sln" in Visual Studio. In the Solution Explorer, you should see MonkeyGame, and MonkeyGame.PhoneComponent. Next to MonkeyGame, you should see "Windows Phone 8.0". Admob will work if you see this.

If next to MonkeyGame you see "Windows Phone Silverlight 8.1", Admob will always give you error NoFill.

So you can still get admob working on your phone.


SLotman(Posted 2015) [#10]
Ok, I'm looking at all the code, trying to understand and implement it here.

First thing I noticed, is that you turned uiaction into an array? Why would you need that? AFAIK, uiaction is just a pointer to any function - so you wouldn't need to have several "uiaction"s....?

And...

// Yes you do need that ^ symbol, and don't ask me what it is. I don't know.


The only thing I could find about it was this:"^ means a Windows Runtime reference counted object" O_o


SLotman(Posted 2015) [#11]
Hmmm... I managed to get it working (to the point of touching the screen, and seeing in the logs that CreateAd was called) - and now I see the reason for the arrays, I think.

Calling more than one command at a time (like CreateAd and EnableKeyboard) crashes the program...


Ferdi(Posted 2015) [#12]
Yeah, the whole C++, C# interaction is very "fragile". Yes, to use it you really have to understand that one part, AND that it is on a thread.

I should also point out there is a 2-3 seconds delay before C# code gets executed, because it is on a thread.

Another test case you should try. For example, when the user want to show an ad they have to press the button. What happen if the user double click on the button? Have to think about those type of things.


SLotman(Posted 2015) [#13]
Just got admob banners working ^_^

The only thing I can't get to work right now is display rotation. When I rotate the phone, Monkey will rotate everything correctly, but the ad stays in place :/

I thought that since the ad is child to background, that it all should rotate... but guess I was wrong :/

At least for now, it'll have to do... I'll now look into implementing this without changing monkey's gametarget - so I could only drop a "module" and a "target" and have it working...


Xaron(Posted 2015) [#14]
That would be awesome Slotman. Looking forward to this!


Ferdi(Posted 2015) [#15]
Congrats on getting admob working!

I think it may be possible to make it module only, because if you look at modules/brl/native/monkeystore.winrt.cpp, it looks like Mark is calling C# from C++. I don't know where to start though. I don't understand the syntax at all.


SLotman(Posted 2015) [#16]
Urg. No go at using smart banners, even in test mode it returns "no fill"... yay Admob! :/


SLotman(Posted 2015) [#17]
I did it!

Function names will be different as the ones above - but I think you can all understand.

First of all, put this in a module, or on top of your monkey program:

Import "admob.cpp"

Extern

	Function CreateAd(unitId:String, layout:Int, testing:Int)
	Function ShowAd:Void()
	Function HideAd:Void()

Public


Then, in the same path as your monkey code or your module, create a file called "admob.cpp", with this code:
static void CreateAd(String unitId, int layout, int testing)
{
	BBMonkeyGame *mgame = (BBMonkeyGame *) (BBWinrtGame::Game());
	mgame->CreateAd(unitId, layout, testing);
}

static void ShowAd()
{
	BBMonkeyGame *mgame = (BBMonkeyGame *) (BBWinrtGame::Game());
	mgame->ShowAd();
}

static void HideAd()
{
	BBMonkeyGame *mgame = (BBMonkeyGame *) (BBWinrtGame::Game());
	mgame->HideAd();
}


Now you don't have to change anything in gametarget.monkey and gametarget.cpp!


Ferdi(Posted 2015) [#18]
Cool!!! This makes the code ALOT neater. =) Thanks Slotman.


SLotman(Posted 2015) [#19]
Not only neater - but you won't have to change Monkey internals on every release to use it :)

You guys can check this at work here: Chroma Wheel on Microsoft Store
(Some ads may appear with a white background around it... it's Google's fault - it happens even if I just drag an Adview control into an empty project, in landscape mode!)

And if you like the game, please vote for it on the Indie Game Making Contest! :)

Too bad that contest doesn't have a prize for game made in Monkey... I think I'm the only one there using it ^_^


SLotman(Posted 2016) [#20]
Just great.

Google killed Admob on Windows 8. Or it will... support ends on November 1st.
Another hit on the poor Windows mobile :(

Can anyone recommend an alternative?


Xaron(Posted 2016) [#21]
Yeah that's odd. I haven't found anything other yet. Probably I'm going to drop Windows Phone at all. It's simply not worth it anymore - not even for small ones like me.


SLotman(Posted 2016) [#22]
Yeah, me too. Microsoft even ditched Pubcenter itself for WP8 - now they only suppor UWP. Since I don't have a WP10 and neither have Windows 10 installed on any computer... UWP isn't for me :P