2017-12-04 8 views
2

3 번의 버튼 클릭 수마다 삽입 광고를 어떻게 표시 할 수 있습니까? 여기 내 게임에 내가 RESTART 버튼 여기LibGDX 게임 프레임 워크를 사용하여 Android에서 매 3 번의 클릭에 삽입 광고를 표시하는 방법

에서 간질 쇼를했습니다 핵심 모듈 ... MAIN.java 메인 레이아웃에서 코드

입니다

@Override 
public void touchUp(InputEvent event, float x, float y, int pointer, int button) { 
     super.touchUp(event, x, y, pointer, button); 

    if (((Act) event.getTarget()).enabled) { 
     if (event.getTarget().getName().equals("btnRestart")) { 
      loadScreen("game"); 
      // show AdMob Interstitial 
      nativePlatform.admobInterstitial(); 
      return; 
     } 
    .... 
    } 

XML 파일

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/root" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 

    <com.google.android.gms.ads.AdView 
     android:id="@+id/admob" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top" 
     android:layout_centerHorizontal="true" 
     ads:adUnitId="@string/adMob_banner" 
     ads:adSize="SMART_BANNER"/> 


    <FrameLayout 
     android:id="@+id/app" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

    </FrameLayout> 

</LinearLayout> 

레이아웃에 btn이 없습니다.

답변

1

정적 카운터를 사용하십시오.

public static int counter=0; 

다시 시작 버튼을 클릭 할 때마다 카운터가 증가합니다. remainder/modulus 연산자 %을 사용하여 원하는 결과를 얻으십시오.

if (((Act) event.getTarget()).enabled) { 
    if (event.getTarget().getName().equals("btnRestart")) { 
      counter++; 
      loadScreen("game"); 
      // show AdMob Interstitial 
      if(counter%3==0) 
       nativePlatform.admobInterstitial(); 
      return; 
    } 
    .... 
} 
+1

덕분에 당신을 도움이 있다면 당신이 대답을 받아 들일 수의 작품을 좋아 <3 – KiiLa

+1

@KiiLa를 아리아. – icarumbas