Implemented moving/hiding ad from C code, updated admob test project with moving ad

This commit is contained in:
pelya
2012-09-06 19:41:40 +03:00
parent 8c54a7643d
commit 6dec5b8a1e
8 changed files with 116 additions and 27 deletions

View File

@@ -16,6 +16,7 @@
#include "SDL.h"
#include "SDL_image.h"
#include "SDL_android.h"
/*----------------------------------------------------------
@@ -430,9 +431,18 @@ int main(int argc, char* argv[])
int fps_count = 0;
int fps_start = 0;
float x_speed, y_speed, z_speed;
SDL_Rect adSize;
int physicalW = 0, physicalH = 0;
int showAd = 0;
SDL_ANDROID_GetAdvertisementParams(NULL, &adSize);
__android_log_print(ANDROID_LOG_INFO, "Ballfield", "Advertisement size %dx%d pos %d:%d", (int)adSize.w, (int)adSize.h, (int)adSize.x, (int)adSize.y);
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
physicalW = SDL_GetVideoInfo()->current_w;
physicalH = SDL_GetVideoInfo()->current_h;
atexit(SDL_Quit);
screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, bpp, flags);
@@ -555,8 +565,22 @@ int main(int argc, char* argv[])
fps = (float)fps_count * 1000.0 / (tick - fps_start);
fps_count = 0;
fps_start = tick;
showAd++;
if(showAd > 3)
showAd = 0;
SDL_ANDROID_SetAdvertisementVisible(showAd);
}
int adX = abs(x_offs / 100) % (physicalW - adSize.w);
int adY = abs(y_offs / 80) % (physicalH - adSize.h);
SDL_ANDROID_SetAdvertisementPosition(adX, adY);
SDL_Rect adRect;
adRect.x = adX * SCREEN_W / physicalW;
adRect.w = adSize.w * SCREEN_W / physicalW;
adRect.y = adY * SCREEN_H / physicalH;
adRect.h = adSize.h * SCREEN_H / physicalH;
SDL_FillRect(screen, &adRect, 0xff0);
print_num(screen, font, screen->w-37, screen->h-12, fps);
++fps_count;

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB