Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Creating in-game advertisements

In-Game Advertisements
A Tutorial by Wyatt

Why?...
If you are creating a large game with tons of custom graphics, music, or scripts, you'll inevitably have to pay somebody something. One way to get this money is to introduce ads into your game. They can be anything from huge 500x100 banners, to small 88x31 buttons.

To begin with...
You need to have two scripts installed into your game first of all, for this to work properly. These are:

-Hyperlinks Module
-Mouse Input Module

Working out sizes

The standard sizes for advertisements are:

Leaderboard: 720x90
Horizontal banner: 468 x 60
Half banner: 234 x 60
Square button: 125x125
Vertical banner: 120x240
Large button: 120x90
Button: 120x60
Mini button: 88x31

You don't have to stick to these, but it saves the advertiser having to make new banners, they will generally have these sizes already made as they are pretty much standard sizes.

For this tutorial I am going to use the Horizontal Banner size, which is the most common size used for a google ad.

Creating ad space
You can, if you want, use Selwyn's resolution script to ad space for your ads to go in to. This is what I am going to do.

I made the resolution larger than normal (640 x 580).

Create an image to go behind the ad, such as this one:

http://img.photobucket.com/albums/v108/dudemaster/adspace.png

That's basically it, for now.

Create a sample ad
This is quite easy, just create an example ad for now, or use the ones below, until you get advertisers.

http://img.photobucket.com/albums/v108/ ... plead0.png[/IMG]

http://img.photobucket.com/albums/v108/ ... plead1.png[/IMG]

http://img.photobucket.com/albums/v108/ ... plead2.png[/IMG]

A simple script
This is a Scene_Map mod I made. It basically does this:
-Checks if the mouse is over the advertisement
-Goes to the website named in the script if it is left clicked

The methods I am using for this are from the Mouse and Hyperlink modules I listed above:

A.href('website_here') opens up the website.

Code:
class Scene_Map

  alias ads_script_main main

  alias ads_script_update update

  

  def main

    @ad = rand(2)

    @ad_background = Sprite.new

    @ad_background.bitmap = RPG::Cache.picture('adspace')

    @ad_background.z = 9998

    @advert = Sprite.new

    @advert.bitmap = RPG::Cache.picture('samplead' + @ad.to_s + '.png')

    @advert.z = 9999

    @advert.x = 93

    @advert.y = 501

    ads_script_main

    @ad_background.dispose

    @advert.dispose

  end

  def update

    # if mouse is clicked and over advertisement

    Mouse.update

    if@ad = 0

      A.href('www.rmxp.org') if Mouse.click?(1)         and

                    Mouse.pixels[0] > 93    and

                    Mouse.pixels[0] < 560   and

                    Mouse.pixels[1] > 501   and

                    Mouse.pixels[1] < 560

    elsif@ad = 1

      A.href('www.rmxp.org/') if Mouse.click?(1)         and

                    Mouse.pixels[0] > 93    and

                    Mouse.pixels[0] < 560   and

                    Mouse.pixels[1] > 501   and

                    Mouse.pixels[1] < 560

    elsif@ad = 2

      A.href('www.rmxp.org/') if Mouse.click?(1)         and

                    Mouse.pixels[0] > 93    and

                    Mouse.pixels[0] < 560   and

                    Mouse.pixels[1] > 501   and

                    Mouse.pixels[1] < 560

    end

    ads_script_update

  end

end

And there you have it!

If you use this, be sure to credit:
-Aleworks
-DerVVulfman
-Selwyn
-DraycosGoldaryn

-Me (if you want to).


And here's a demo.

http://www.vengeance-rpg.co.nr/Advertisements.zip
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top