Hi basjak. Not sure I'm entirely clear what you're after but I hope this will help. If not, do say and I'll have another go!
1. Create a fully functional website with a decent amount of content
2. Buy some web hosting space and a domain name
3. Upload your website
4. Apply for a Google AdSense account and wait for approval
5. Log in to your Google AdSense account and go to My Ads>New Ad Unit
6. Use the wizard that appears to create the kind of banner you want to appear in your game, bearing in mind that it will not be resizable and so must fit on the smallest supported screen resolution
7. Create a new html page that is to display your advert
8. Copy the following code into your new page
<html>
<head>
<style type="text/css">html, body { overflow: hidden; margin: 0px;}</style>
<meta name="description" content="Description of your choice. Perhaps of the game?" />
<meta name="keywords" content="Key words to do with the game and games in general" />
<meta name="author" content="Your name" />
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Your title here</title>
</head>
<body>
<!-- SCRIPT FROM ADSENSE GOES HERE -->
</body>
</html>
9. In Google AdSense, click "Get Code" on your new advert and copy the code in to the html page where it ways "<!-- SCRIPT FROM ADSENSE GOES HERE -->"
10. Save and upload the html page to your website
11. Create a new source file in your DBP project and copy in the following code
REM *** Google AdSense Library ***
REMSTART
To use this library, either add it to your project OR add the line:
#INCLUDE "Google_AdSense.dba"
Ads will need to be directed to a web page setup as shown in the other document. This will require them to be
hosted on your website.
You will also need:
- BBB GUI
- Matrix1Utils
REMEND
type AdType
nID as integer
nDBPWindow as integer
nBannerWindow as integer
nBrowserWindow as integer
nX as integer
nY as integer
nWidth as integer
nHeight as integer
sURL as string
sCurrentURL as string
endtype
// Run this at the start of your program before you call any of the other functions in the library
// You need to run START BBB GUI at the same time before any other calls are made
// Remember to add END BBB GUI before your program ends
function InitializeAds()
global dim InAppAds(0) as AdType
empty array InAppAds(0)
endfunction
// Run this to create a new advert
// Point the URL to a page with only a Google Ad on it
function MakeAd(nID,nX,nY,nWidth,nHeight,sURL$)
for c = 0 to array count(InAppAds(0))
if InAppAds(c).nID = nID
report error "Advert " + str$(nID) + " already exists.","AdSense Error"
endif
next c
array insert at bottom InAppAds(0)
nIndex = array count(InAppAds(0))
InAppAds(nIndex).nID = nID
InAppAds(nIndex).nDBPWindow = get dbpro window()
InAppAds(nIndex).nX = nX
InAppAds(nIndex).nY = nY
InAppAds(nIndex).nWidth = nWidth
InAppAds(nIndex).nHeight = nHeight
InAppAds(nIndex).sURL = sURL$
InAppAds(nIndex).sCurrentURL = sURL$
InAppAds(nIndex).nBannerWindow = make window(InAppAds(nIndex).nX,InAppAds(nIndex).nY,InAppAds(nIndex).nWidth,InAppAds(nIndex).nHeight,"",InAppAds(nIndex).nDBPWindow,WS_CHILD)
InAppAds(nIndex).nBrowserWindow = make webbrowser(InAppAds(nIndex).sURL, InAppAds(nIndex).nBannerWindow)
endfunction
// Put this function in your main loop whenever any of the ads are displayed
// When an ad is clicked, it will open to fill the screen
// This function will attempt to pause your game by running it's own main loop so your true main loop effectively freezes
// This works well but can cause problems with timer based movement and so you will have to ensure you deal with these correctly
function HandleAds()
get event
nEvent = event get message()
nHandle = event get handle()
for c = 0 to array count(InAppAds(0))
if nHandle = InAppAds(c).nBannerWindow and nEvent = WM_MOUSEACTIVATE
for d = 0 to array count(InAppAds(0))
if d <> c
HideAd(InAppAds(d).nID)
endif
next d
bOpenedInNew as boolean = 0
window set size InAppAds(c).nBannerWindow,screen width(),screen height() - 20
window set position InAppAds(c).nBannerWindow,0,0
nButtonWindow = make window(0,screen height() - 20,screen width(),20,"",InAppAds(c).nDBPWindow,WS_CHILD)
nExitButton = make button(screen width() - 140,0,140,20,"Return To Game",nButtonWindow)
nOpenInNew = make button(screen width() - 290,0,140,20,"Open In Browser",nButtonWindow)
do
get event
webbrowser get event
nHandle = webbrowser get event handle()
nMessage = webbrowser get event message()
if nHandle = InAppAds(c).nBrowserWindow and nMessage = DISPID_BEFORENAVIGATE2
InAppAds(c).sCurrentURL = webbrowser get event string(c)
endif
if button clicked(nOpenInNew)
if bOpenedInNew = 0
bOpenedInNew = 15
execute file InAppAds(c).sCurrentURL,"",""
endif
else
if bOpenedInNew
bOpenedInNew = 0
endif
endif
if button clicked(nExitButton)
exit
endif
loop
delete window nExitButton
delete window nOpenInNew
delete window nButtonWindow
webbrowser navigate InAppAds(c).nBrowserWindow,InAppAds(c).sURL
window set size InAppAds(c).nBannerWindow,InAppAds(c).nWidth,InAppAds(c).nHeight
window set position InAppAds(c).nBannerWindow,InAppAds(c).nX,InAppAds(c).nY
InAppAds(c).sCurrentURL = InAppAds(c).sURL
for d = 0 to array count(InAppAds(0))
if d <> c
ShowAd(InAppAds(d).nID)
endif
next d
// You can add code to resolve issues with timer based movement here
endif
next c
endfunction
function PositionAd(nID,nX,nY)
for c = 0 to array count(InAppAds(0))
if InAppAds(c).nID = nID
InAppAds(c).nX = nX
InAppAds(c).nY = nY
window set position InAppAds(c).nBannerWindow,InAppAds(c).nX,InAppAds(c).nY
exit
endif
next c
endfunction
function ShowAd(nID)
for c = 0 to array count(InAppAds(0))
if InAppAds(c).nID = nID
//webbrowser refresh InAppAds(c).nBrowserWindow ` Un-comment this at your descretion. I do not refresh the browser for fear of
` generating "artificial clicks" but refreshing it would create more views and
` would show new ads to a customer each time it was shown.
show window InAppAds(c).nBannerWindow
exit
endif
next c
endfunction
function HideAd(nID)
for c = 0 to array count(InAppAds(0))
if InAppAds(c).nID = nID
hide window InAppAds(c).nBannerWindow
exit
endif
next c
endfunction
12. Make sure you have Matrix1Utils and BBB GUI plugins installed
13. Add 'InitializeAds()' and 'start bbb gui' somewhere at the top of your code before you make any other referenses to ads
14. Add 'end bbb gui' somewhere that it will be run just before the program closes
15. In your setup code, make ads in the same way as you would sprites, using the 'MakeAd(nID,nX,nY,nWidth,nHeight,sURL$)' command. sURL$ should equal the address of the html page made earlier on your website
16. Once ads are created, you can move them using 'PositionAd(ID,nX,nY)' and hide/show them using 'ShowAd(nID)' and 'HideAd(nID)'
17. In every main loop in your program where any ads could be displayed, add the 'HandleAds()' command
18. Compile and run your program!