GameMaker Tips: Positioning Windows Phone Ads

icon__newsitevibes The Windows Phone export in GameMaker: Studio has caused me more issues than any other. The export module’s stability probably suffers from the lack of popularity of the platform in general, which creates a vicious cycle because developers find it hard to create exciting games for Windows Phone!

Having released a whole bunch of titles successfully for Windows Phone, the one thing that had me stumped until just last week was advertising. The default built-in pubCenter (now being phased out by Microsoft) and MS Advertising options in GameMaker: Studio have pretty much been the only way forward for developers since the Windows Phone module was launched. The problem is, positioning them to look good on all devices is about as confusing as it would be to write yourself a whole new Ad extension from scratch.

The Problem

The built-in GameMaker functions for positioning ads relative to the screen have a completely counter-intuitive effect on Windows Phone ads. If you’ve only invested in one Windows Phone test device, you may not have even noticed that this problem exists. If so, you should probably get another device with a different screen resolution, to be sure that your game works on all devices. If you happen to have a Lumia 820 and Lumia 1020 to hand, like I do, try the following experiment. Use the following ad position code, as detailed in the GameMaker: Studio help file, to place your ads in the bottom-center of the screen:

ads_move((display_get_gui_width()/2) – (ads_get_display_width(0)/2),
display_get_gui_height() – ads_get_display_height(0), 0);

Now test the game on both devices and see what happens (playing the game in Landscape orientation will usually exaggerate the issue). You would expect the both devices to place the ads in the bottom-center of the screen, but actually you get something more like this:

WPA_Problem

A little debugging reveals that ads_get_display_width and ads_get_display_height return different values on different devices, and annoyingly, using this value to position ads relative to the GUI layer doesn’t work at all.

The Solution

I have tried many solutions to this problem, all of which seem to work at the time but I realise later that they still cause issues on some devices. I may be completely overthinking an otherwise simple problem, and anyone with a solid knowledge of GameMaker: Studio and/or Windows Phone should feel free to educate me on correct procedure, but I have stumbled upon what I believe is the solution to the problem.

It appears that, no matter what ads_get_display_* tells you about Windows Phone Ads, there is actually a constant (seemingly arbitrary) value across all devices. That is, the advert is 240 pixels wide and 40 pixels tall. This is half the size of an XXL 6:1 Image Ad in all Microsoft documentation, so I’m not sure where these values come from, but in practice they seem to work. You should also note that, if you were treating the ad is if it were a standard GameMaker sprite, its X-Origin is half way across the image (120, 0), as seen in the image below:

WPA_Solution

With this in mind I altered my advertising code to display the ad relative to the GUI layer like so:

var adsX = (display_get_gui_width()/2)-120;
var adsY = display_get_gui_height()-40;
ads_enable(adsX,adsY,0);

This produces the result seen in the image above, where the advert is in the correct place on both the Lumia 820 and Lumia 1020. Based on the deduction made above about the size of the advert and its position relative to the GUI layer, this should work on all Windows Phone devices. However, I lack access to any more devices at the moment and, with the lack of information available on the YoYo Games Helpdesk, I cannot confirm that this tip works 100% of the time (but I trust it enough to use it for all future Chequered Ink projects until somebody tells me otherwise).

Hope that’s been helpful, and if not I hope it illuminates the true solution for you! (If that’s the case, give me a shout :P)

Published by Dan