Yandex Mobile Ads in Ren'Py Game

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
Andredron
Miko-Class Veteran
Posts: 719
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Yandex Mobile Ads in Ren'Py Game

#1 Post by Andredron »

https://github.com/valery-iwanofu/rapt-yandex-ads

This repository contains modified files from the rapt folder that will allow you to add an advertising banner to the game made on Ren'Py

Installation
The rapt folder is located in the directory where the Ren'Py executable (renpy.exe) is located.

1. Duplicate the rapt/templates and rapt/prototype folders (for backup purposes)

2. Download this repository

3. Move all files from the downloaded_archive/rapt folder to the rapt folder (agree to replace)

4. Move the yandex_ads.py file to the game folder of your Ren'Py project

5. Import the yandex_ads module into your Ren'Py project using the following code:

Code: Select all

# this code can be written in any file of your project (for example, in script.rpy)

init python:
   if renpy.android:
     import yandex_ads
6. Delete the rapt/project folder or the rapt/project/build.txt file to have Ren'Py regenerate the build files

Creating a banner

Code: Select all

init python:
   if renpy.android:
     banner = yandex_ads.create_banner()

     # the first step is to set the size of the banner
     # remember - you can only do this once
     banner set_sticky_size(-1)

     # by default the banner will be "under the game"
     # with set_position you can change the position of the banner at any time
     banner.set_position('above_game') # if set to above_game, the banner will be "above the game"

     # ad_unit_id can be taken in the affiliate account
     banner.set_ad_unit_id("R-M-XXXXXX-Y")

     # don't forget to upload ad
     banner.load_ad()

Available values for set_position()

Code: Select all

bottom
top
center
left
right
center_horizontal
center_vertical
fill
fill_horizontal
fill_vertical
start
end
under_game
above_game
More about banner size

Code: Select all

# responsive size, where width is the width of the banner (you can use -1 to stretch the banner to the entire available area)
banner set_sticky_size(width)

# adaptive size, where width and height are the maximum possible width and height, respectively
banner set_flexible_size(width, height)

# Exact size
banner set_size(width, height)
The width and height are specified in dp(density-independent pixels).

Installation video (not fully relevant)




PythonSDLActivity.java does not need to be edited!*
Last edited by Andredron on Wed Aug 31, 2022 9:51 am, edited 2 times in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Yandex Mobile Ads in Ren'Py Game

#2 Post by PyTom »

Note that replacing PythonSDLActivity.java like this might work for the version of Ren'Py this was designed for, but it may cause problems as new versions are released.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
Andredron
Miko-Class Veteran
Posts: 719
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: Yandex Mobile Ads in Ren'Py Game

#3 Post by Andredron »

PyTom wrote: Fri Aug 19, 2022 4:06 pm Note that replacing PythonSDLActivity.java like this might work for the version of Ren'Py this was designed for, but it may cause problems as new versions are released.
Good afternoon, I have forwarded your comment to the author.
Thank you for your comment. I'm planning to write a walkthrough, but it's only in draft format at the moment
- https://gist.github.com/valery-iwanofu/ ... 7bb4d7720a

At the expense of not working after changes in Ren'Py itself, I already thought about it, but so far I have no idea how to solve this problem

I created an issue to further try to solve this problem

https://github.com/renpy/renpy/issues/3882

User avatar
Andredron
Miko-Class Veteran
Posts: 719
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: Yandex Mobile Ads in Ren'Py Game

#4 Post by Andredron »

Yandex Mobile Ads update for Ren'Py (version 8 and higher)

The main change is that now you can add and manage banners directly from rpy files


Post Reply

Who is online

Users browsing this forum: No registered users