问题描述
您好我想处理在屏幕上点击。所以我不能使用任何琐碎的方法来处理点击类不扩展活动类。我知道如何处理对Android应用的点击,但我的新游戏开发,所以我对游戏的知识有限。所以,我的要求是:有过屏幕上的游戏一个共享图标。我想处理这个图标点击喜欢他什么时候会显示这个图标,用户presses一堆共享选项如Facebook,Twitter,Skype和更多的使用createChooser。我不知道该怎么做。
这是我的GameOverscreen code。
公共类GameOverScene扩展CCLayer {
//领域
私人SoundManager类_soundMananger;
私人CCSprite _background; 私人CCMenu _menu;
私人CCMenu _restart; 私人CCLabel _yourScore;
私人CCLabel _bestScore;
//方法
公共静态CCScene场景(){
CCScene场景= CCScene.node();
GameOverScene层=新GameOverScene();
scene.addChild(层);
返回现场;
} 公共GameOverScene(){
超();
BeetleshotMainActivity.app.setHideAdView(假);
_soundMananger = SoundManager.sharedSoundResourceManager();
CGSize大小= CCDirector.sharedDirector()使用winsize()。
漂浮的scaleX = size.width / 768.0f;
漂浮的scaleY = size.height / 1024.0f; 如果(BeetleshotMainActivity.app._soundplay ==真){
_soundMananger.bStopMenuSound();
_soundMananger.bPlayMenuSound();
} _background = CCSprite.sprite(图像/ GAMEOVER和清除/ Over_Bg.png);
_background.setScaleX(将scaleX);
_background.setScaleY(的scaleY);
_background.setPosition(CGPoint.ccp(size.width / 2,size.height / 2));
this.addChild(_background); CCMenuItemImage菜单项= CCMenuItemImage.item(图像/ GAMEOVER和清除/ MaiinNenu_n.png,图像/ GAMEOVER和清除/ MaiinNenu_d.png,这个menuAction);
menuItem.setScaleX(将scaleX);
menuItem.setScaleY(的scaleY);
_menu = CCMenu.menu(菜单项);
_menu.setPosition(CGPoint.ccp(size.width * 1.0F / 2.0F,size.height * 3.0F / 10.0f));
this.addChild(_menu); menuItem.setPosition(CGPoint.ccp(menuItem.getPosition()的X 50.0f,menuItem.getPosition()Y)。);
CCMoveBy dropTitle = CCMoveBy.action(1.5F,CGPoint.ccp(50.0f,0.0));
CCEaseBounceOut easeDrop = CCEaseBounceOut.action(dropTitle);
menuItem.runAction(easeDrop); CCMenuItemImage restartItem = CCMenuItemImage.item(图像/ GAMEOVER和清除/ Restart_n.png,图像/ GAMEOVER和清除/ Restart_d.png,这个restartAction);
restartItem.setScaleX(将scaleX);
restartItem.setScaleY(的scaleY);
_restart = CCMenu.menu(restartItem);
_restart.setPosition(CGPoint.ccp(size.width / 2.0F,(浮点)(size.height * 4.2f / 10.0f)));
this.addChild(_restart); restartItem.setPosition(CGPoint.ccp(restartItem.getPosition()X + 50.0f,restartItem.getPosition()y)的);
dropTitle = CCMoveBy.action(1.5F,CGPoint.ccp(-50.0f,0.0));
easeDrop = CCEaseBounceOut.action(dropTitle);
restartItem.runAction(easeDrop);
// CCMenuItemImage shareI = CCMenuItemImage.item(图像/的MainMenu / share.png,图像/的MainMenu / Share.png,这种分享);
fb.setScaleX(将scaleX);
fb.setScaleY(的scaleY);
_restart = CCMenu.menu(shareI);
_restart.setPosition(CGPoint.ccp(size.width / 2.0F,(浮点)(size.height * 1.5F / 10.0f)));
this.addChild(_restart); shareI.setPosition(CGPoint.ccp(restartItem.getPosition()X + 50.0f,restartItem.getPosition()y)的);
dropTitle = CCMoveBy.action(1.5F,CGPoint.ccp(-160.0f,0.0));
easeDrop = CCEaseBounceOut.action(dropTitle);
shareI.runAction(easeDrop);我婉处理click ..我该怎么做呢?我想告诉createChooser对话框时的共享图标用户preSS。 意向i股=新意图(Intent.ACTION_SEND);
iShare.setType(text / plain的);
iShare.putExtra(Intent.EXTRA_SUBJECT,下载游戏);
iShare.putExtra(Intent.EXTRA_TEXT,获得游戏++https://play.google.com/store/apps/details?id=com.jdtfans.jdtfootballkickers);
startActivity(Intent.createChooser(i股股份通过));
上述code我想使用的时候用户preSS共享图标。我怎么做?
。浮动比例因子= CCDirector.sharedDirector()使用winsize()高度/ 1024 * 2.3f; _yourScore = CCLabel.makeLabel(的String.format(%D,BeetleshotMainActivity.app._score),CGSize.make(120.0f *比例因子,60.0f *比例因子),TextAlignment.CENTER,字体/ Imagica.ttf,24.0 F *比例因子); _ yourScore.setPosition(CGPoint.ccp(size.width * 1.32f / 2.0F,(浮点)(size.height * 1.12 / 2.0F))); this.addChild(_yourScore);
_yourScore.setColor(ccColor3B.ccBLUE); //添加此
_bestScore = CCLabel.makeLabel(的String.format(%D,GameScene._hScoreValue),CGSize.make(120.0f *比例因子,60.0f *比例因子),TextAlignment.CENTER,字体/ Imagica.ttf,24.0f *比例因子); _ bestScore.setPosition(CGPoint.ccp(size.width * 1.32f / 2.0F,(浮子)(size.height * 1 / 2.0F))); this.addChild(_bestScore);
_bestScore.setColor(ccColor3B.ccBLUE);
//
开关(BeetleshotMainActivity.app._locationLevel){
情况1:
BeetleshotMainActivity.app._level = 1;
打破;
案例2:
BeetleshotMainActivity.app._level = 2;
打破;
案例3:
BeetleshotMainActivity.app._level = 3;
打破;
默认:
打破;
} INT currentScore = BeetleshotMainActivity.app._score;
BeetleshotMainActivity.app._score = 0; 如果(BeetleshotMainActivity.app._location == 1){
开关(BeetleshotMainActivity.app._locationLevel){
情况1:
BeetleshotMainActivity.app.loadScore(score1);
打破;
案例2:
BeetleshotMainActivity.app.loadScore(score2);
打破;
案例3:
BeetleshotMainActivity.app.loadScore(score3);
打破;
默认:
打破;
}
} 如果(currentScore> BeetleshotMainActivity.app._score){
BeetleshotMainActivity.app._score = currentScore; 如果(BeetleshotMainActivity.app._location == 1){
开关(BeetleshotMainActivity.app._locationLevel){
情况1:
BeetleshotMainActivity.app.saveScore(score1);
打破;
案例2:
BeetleshotMainActivity.app.saveScore(score2);
打破;
案例3:
BeetleshotMainActivity.app.saveScore(score3);
打破;
默认:
打破;
}
}
}
} 公共无效menuAction(对象发件人){
如果(BeetleshotMainActivity.app._soundplay ==真)
_soundMananger.ePlayButtonClickSound();
。CCDirector.sharedDirector()replaceScene(CCFadeTransition.transition(0.7f,MenuScene.scene()));
} 公共无效restartAction(对象发件人){
如果(BeetleshotMainActivity.app._soundplay ==真)
_soundMananger.ePlayButtonClickSound();
。CCDirector.sharedDirector()replaceScene(CCFadeTransition.transition(0.7f,GameScene.scene()));
} }
这是我唯一的活动类,我在我的项目。
/ **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
应用=这;
mContext =这一点;
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow()setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN)。
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
ccMacros.CCLOG(BeetleShot游戏,在OnCreate); RelativeLayout的布局=新的RelativeLayout(本);
layout.setLayoutParams(新RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT)); mGLSurfaceView =新CCGLSurfaceView(本); //创建AdView的
AD浏览=新的AdView(这一点,AdSize.BANNER,ADMOB_PUBLISH_ID); //启动一般性请求与广告加载它
adView.loadAd(新AdRequest中());
的AdView.setAdListener(本);
// AdView的添加到它
RelativeLayout.LayoutParams PARAMS =新RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,RelativeLayout.TRUE);
params.addRule(RelativeLayout.CENTER_HORIZONTAL,RelativeLayout.TRUE);
adView.setLayoutParams(PARAMS); layout.addView(mGLSurfaceView);
layout.addView(AD浏览);
////
//创建间质性
间质性=新在InterstitialAd(这一点,**********); //负荷在InterstitialAd
Ads.loadInterstitialAd(间); //设置广告监听器以使用以下回调
interstitial.setAdListener(本);
的setContentView(布局); 。CCDirector.sharedDirector()attachInView(mGLSurfaceView);
CCDirector.sharedDirector()setDisplayFPS(假)。
。CCDirector.sharedDirector()setAnimationInterval(1.0F / 30); CCTexture2D.setDefaultAlphaPixelFormat(Config.ARGB_8888); _soundplay = TRUE;
_playerSound = TRUE;
_controlShow = FALSE;
_playerPos = 1;
_level = 1;
_firstBonus = 0;
_secondBonus = 0;
_thirdBonus = 0;
_locationLevel = 1; 。CCDirector.sharedDirector()runWithScene(LogoScene.scene());
} @覆盖
保护无效调用onStart(){
super.onStart();
} @覆盖
保护无效onResume(){
super.onResume();
CCDirector.sharedDirector()onResume();
} @覆盖
保护无效的onPause(){
super.onPause();
SoundManager.sharedSoundResourceManager()._ soundEngine.pauseSound();
CCDirector.sharedDirector()的onPause()。
} @覆盖
保护无效的onDestroy(){
super.onDestroy();
。CCDirector.sharedDirector()结束();
SoundManager.releaseSoundResourceManager();
} 公共无效loadScore(字符串文件名){
尝试{
ccMacros.CCLOG(读文件,文件名+从阅读成绩);
FIN的FileInputStream = openFileInput(文件名);
InputStreamReader的ISR =新的InputStreamReader(FIN);
的char [] buf中=新的char [6];
isr.read(BUF);
_score =的Integer.parseInt(新的String(BUF).trim());
isr.close();
fIn.close();
ccMacros.CCLOG(文件读出结果,+ _score);
}赶上(例外五){
}
} 公共无效saveScore(字符串文件名){
尝试{
ccMacros.CCLOG(文件写入,写作分数+文件名);
FileOutputStream中FOUT = openFileOutput(文件名,MODE_WORLD_READABLE);
OutputStreamWriter OSW =新OutputStreamWriter(FOUT);
osw.write(+ _score);
osw.flush();
osw.close();
fOut.close();
}赶上(例外五){
}
} 公共CGPoint getBufPlayerPos(){
返回_m_playerPos;
} 公共无效setBufPlayerPos(CGPoint RPOS){
_m_playerPos = RPOS;
} // AdMob联播设置
公共无效onDismissScreen(广告为arg0){
// TODO自动生成方法存根 } 公共无效onFailedToReceiveAd(广告为arg0,错误code ARG1){
// TODO自动生成方法存根 } 公共无效onLeaveApplication(广告为arg0){
// TODO自动生成方法存根 } 在presentScreen(广告为arg0)公共无效{
// TODO自动生成方法存根 } 公共无效onReceiveAd(广告为arg0){
// TODO自动生成方法存根
//Log.d(TAG,+++++++++++++新版AdMob已收到++++++++++++++!);
}
处理程序处理程序=新的处理程序(){
公共无效的handleMessage(消息MSG){
如果(msg.what == 0){
adView.setVisibility(View.INVISIBLE);
}
其他{
adView.setVisibility(View.VISIBLE);
}
}
}; 公共无效setHideAdView(布尔拜德){
如果(拜德){
handler.sendEmptyMessage(0);
}
其他{
handler.sendEmptyMessage(1);
}
} }
在您的主要活动类,定义一个方法份额:
公共无效份额(){
runOnUiThread(新的Runnable(){
@覆盖
公共无效的run(){
意向i股=新意图(Intent.ACTION_SEND);
iShare.setType(text / plain的);
iShare.putExtra(Intent.EXTRA_SUBJECT,下载游戏);
iShare.putExtra(Intent.EXTRA_TEXT,获得游戏++https://play.google.com/store/apps/details?id=com.jdtfans.jdtfootballkickers);
尝试{
startActivity(Intent.createChooser(i股股份通过));
}赶上(android.content.ActivityNotFoundException前){
Toast.makeText(getApplicationContext(),
没有共享客户端安装,Toast.LENGTH_SHORT)
。显示();
}
}
});
}
然后在你的GameOverScene级,取消对线下变分享到shareAction
CCMenuItemImage shareI = CCMenuItemImage.item(图像/的MainMenu / share.png,图像/的MainMenu / Share.png,这个shareAction);
然后,定义如下restartAction()方法,该方法shareAction:
公共无效shareAction(对象发件人){
如果(BeetleshotMainActivity.app._soundplay ==真)
_soundMananger.ePlayButtonClickSound();
BeetleshotMainActivity.app.share();
}
Hi I want handle a click on Screen. The class does not extends an activity class so I cannot use any trivial method to handle the click. I know how to handle the click on android app but I am new to game development so I have limited knowledge about the Game. So My requirement is : There is a Share icon on Game over screen. I want to handle this icon click like when a user presses on this icon He will be shown a bunch of sharing option like facebook,Twitter, Skype and many more Using createChooser. I dont know how to do that.This is my GameOverscreen code.
public class GameOverScene extends CCLayer {
//fields
private SoundManager _soundMananger;
private CCSprite _background;
private CCMenu _menu;
private CCMenu _restart;
private CCLabel _yourScore;
private CCLabel _bestScore;
//methods
public static CCScene scene() {
CCScene scene = CCScene.node();
GameOverScene layer = new GameOverScene();
scene.addChild(layer);
return scene;
}
public GameOverScene() {
super();
BeetleshotMainActivity.app.setHideAdView(false);
_soundMananger = SoundManager.sharedSoundResourceManager();
CGSize size = CCDirector.sharedDirector().winSize();
float scaleX = size.width / 768.0f;
float scaleY = size.height / 1024.0f;
if (BeetleshotMainActivity.app._soundplay == true) {
_soundMananger.bStopMenuSound();
_soundMananger.bPlayMenuSound();
}
_background = CCSprite.sprite("Image/Gameover and Clear/Over_Bg.png");
_background.setScaleX(scaleX);
_background.setScaleY(scaleY);
_background.setPosition(CGPoint.ccp(size.width/2, size.height/2));
this.addChild(_background);
CCMenuItemImage menuItem = CCMenuItemImage.item("Image/Gameover and Clear/MaiinNenu_n.png", "Image/Gameover and Clear/MaiinNenu_d.png", this, "menuAction");
menuItem.setScaleX(scaleX);
menuItem.setScaleY(scaleY);
_menu = CCMenu.menu(menuItem);
_menu.setPosition(CGPoint.ccp(size.width*1.0f/2.0f, size.height*3.0f/10.0f));
this.addChild(_menu);
menuItem.setPosition(CGPoint.ccp(menuItem.getPosition().x-50.0f, menuItem.getPosition().y));
CCMoveBy dropTitle = CCMoveBy.action(1.5f, CGPoint.ccp(50.0f, 0.0f));
CCEaseBounceOut easeDrop = CCEaseBounceOut.action(dropTitle);
menuItem.runAction(easeDrop);
CCMenuItemImage restartItem = CCMenuItemImage.item("Image/Gameover and Clear/Restart_n.png", "Image/Gameover and Clear/Restart_d.png", this, "restartAction");
restartItem.setScaleX(scaleX);
restartItem.setScaleY(scaleY);
_restart = CCMenu.menu(restartItem);
_restart.setPosition(CGPoint.ccp(size.width/2.0f, (float) (size.height*4.2f/10.0f)));
this.addChild(_restart);
restartItem.setPosition(CGPoint.ccp(restartItem.getPosition().x+50.0f, restartItem.getPosition().y));
dropTitle = CCMoveBy.action(1.5f, CGPoint.ccp(-50.0f, 0.0f));
easeDrop = CCEaseBounceOut.action(dropTitle);
restartItem.runAction(easeDrop);
// CCMenuItemImage shareI = CCMenuItemImage.item("Image/MainMenu/share.png", "Image/MainMenu/Share.png", this, "Share");
fb.setScaleX(scaleX);
fb.setScaleY(scaleY);
_restart = CCMenu.menu(shareI);
_restart.setPosition(CGPoint.ccp(size.width/2.0f, (float) (size.height*1.5f/10.0f)));
this.addChild(_restart);
shareI.setPosition(CGPoint.ccp(restartItem.getPosition().x+50.0f, restartItem.getPosition().y));
dropTitle = CCMoveBy.action(1.5f, CGPoint.ccp(-160.0f, 0.0f));
easeDrop = CCEaseBounceOut.action(dropTitle);
shareI.runAction(easeDrop);
I wan to handle the click.. How do i Do that? I want to show createChooser dialog when user press on the share icon.
Intent iShare = new Intent(Intent.ACTION_SEND);
iShare.setType("text/plain");
iShare.putExtra(Intent.EXTRA_SUBJECT, "Download The Game");
iShare.putExtra(Intent.EXTRA_TEXT, "Get The Game"+" "+"https://play.google.com/store/apps/details?id=com.jdtfans.jdtfootballkickers");
startActivity(Intent.createChooser(iShare,"Share Via"));
Above code i want to use when user press share icon. How do i do that?
float scaleFactor = CCDirector.sharedDirector().winSize().height/1024 * 2.3f;
_yourScore = CCLabel.makeLabel(String.format("%d", BeetleshotMainActivity.app._score), CGSize.make(120.0f*scaleFactor, 60.0f*scaleFactor), TextAlignment.CENTER, "Font/Imagica.ttf", 24.0f*scaleFactor);_yourScore.setPosition(CGPoint.ccp(size.width*1.32f/2.0f, (float) (size.height*1.12/2.0f)));
this.addChild(_yourScore);
_yourScore.setColor(ccColor3B.ccBLUE);
// add this
_bestScore = CCLabel.makeLabel(String.format("%d", GameScene._hScoreValue), CGSize.make(120.0f*scaleFactor, 60.0f*scaleFactor), TextAlignment.CENTER, "Font/Imagica.ttf", 24.0f*scaleFactor);_bestScore.setPosition(CGPoint.ccp(size.width*1.32f/2.0f, (float) (size.height*1/2.0f)));
this.addChild(_bestScore);
_bestScore.setColor(ccColor3B.ccBLUE);
//
switch(BeetleshotMainActivity.app._locationLevel) {
case 1:
BeetleshotMainActivity.app._level = 1;
break;
case 2:
BeetleshotMainActivity.app._level = 2;
break;
case 3:
BeetleshotMainActivity.app._level = 3;
break;
default:
break;
}
int currentScore = BeetleshotMainActivity.app._score;
BeetleshotMainActivity.app._score = 0;
if (BeetleshotMainActivity.app._location == 1) {
switch(BeetleshotMainActivity.app._locationLevel) {
case 1:
BeetleshotMainActivity.app.loadScore("score1");
break;
case 2:
BeetleshotMainActivity.app.loadScore("score2");
break;
case 3:
BeetleshotMainActivity.app.loadScore("score3");
break;
default:
break;
}
}
if (currentScore > BeetleshotMainActivity.app._score) {
BeetleshotMainActivity.app._score = currentScore;
if (BeetleshotMainActivity.app._location == 1) {
switch(BeetleshotMainActivity.app._locationLevel) {
case 1:
BeetleshotMainActivity.app.saveScore("score1");
break;
case 2:
BeetleshotMainActivity.app.saveScore("score2");
break;
case 3:
BeetleshotMainActivity.app.saveScore("score3");
break;
default:
break;
}
}
}
}
public void menuAction(Object sender) {
if (BeetleshotMainActivity.app._soundplay == true)
_soundMananger.ePlayButtonClickSound();
CCDirector.sharedDirector().replaceScene(CCFadeTransition.transition(0.7f, MenuScene.scene()));
}
public void restartAction(Object sender) {
if (BeetleshotMainActivity.app._soundplay == true)
_soundMananger.ePlayButtonClickSound();
CCDirector.sharedDirector().replaceScene(CCFadeTransition.transition(0.7f, GameScene.scene()));
}
}
This is my only activity class that i have in my project.
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app = this;
mContext = this;
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
ccMacros.CCLOG("BeetleShot Game", "OnCreate");
RelativeLayout layout = new RelativeLayout(this);
layout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mGLSurfaceView = new CCGLSurfaceView(this);
// Create the adView
adView = new AdView(this, AdSize.BANNER, ADMOB_PUBLISH_ID);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
adView.setAdListener(this);
// Add the adView to it
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
adView.setLayoutParams(params);
layout.addView(mGLSurfaceView);
layout.addView(adView);
////
// create the interstitial
interstitial = new InterstitialAd(this, "**********");
// load interstitialAd
Ads.loadInterstitialAd(interstitial);
// set Ad Listener to use the callbacks below
interstitial.setAdListener(this);
setContentView(layout);
CCDirector.sharedDirector().attachInView(mGLSurfaceView);
CCDirector.sharedDirector().setDisplayFPS(false);
CCDirector.sharedDirector().setAnimationInterval(1.0f / 30);
CCTexture2D.setDefaultAlphaPixelFormat(Config.ARGB_8888);
_soundplay = true;
_playerSound = true;
_controlShow = false;
_playerPos = 1;
_level = 1;
_firstBonus = 0;
_secondBonus = 0;
_thirdBonus = 0;
_locationLevel = 1;
CCDirector.sharedDirector().runWithScene(LogoScene.scene());
}
@Override
protected void onStart() {
super.onStart();
}
@Override
protected void onResume() {
super.onResume();
CCDirector.sharedDirector().onResume();
}
@Override
protected void onPause() {
super.onPause();
SoundManager.sharedSoundResourceManager()._soundEngine.pauseSound();
CCDirector.sharedDirector().onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
CCDirector.sharedDirector().end();
SoundManager.releaseSoundResourceManager();
}
public void loadScore (String filename) {
try {
ccMacros.CCLOG("file reading", "reading scores from " + filename);
FileInputStream fIn = openFileInput(filename);
InputStreamReader isr = new InputStreamReader(fIn);
char[] buf = new char[6];
isr.read(buf);
_score = Integer.parseInt(new String(buf).trim());
isr.close();
fIn.close();
ccMacros.CCLOG("file reading result", "" + _score);
} catch (Exception e) {
}
}
public void saveScore (String filename) {
try {
ccMacros.CCLOG("file writing", "writing scores to " + filename);
FileOutputStream fOut = openFileOutput(filename, MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
osw.write("" + _score);
osw.flush();
osw.close();
fOut.close();
} catch (Exception e) {
}
}
public CGPoint getBufPlayerPos() {
return _m_playerPos;
}
public void setBufPlayerPos (CGPoint rpos) {
_m_playerPos = rpos;
}
// Admob Setting
public void onDismissScreen(Ad arg0) {
// TODO Auto-generated method stub
}
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
// TODO Auto-generated method stub
}
public void onLeaveApplication(Ad arg0) {
// TODO Auto-generated method stub
}
public void onPresentScreen(Ad arg0) {
// TODO Auto-generated method stub
}
public void onReceiveAd(Ad arg0) {
// TODO Auto-generated method stub
//Log.d(TAG, "+++++++++++++ New admob has received! ++++++++++++++");
}
Handler handler = new Handler() {
public void handleMessage(Message msg) {
if(msg.what == 0) {
adView.setVisibility(View.INVISIBLE);
}
else {
adView.setVisibility(View.VISIBLE);
}
}
};
public void setHideAdView(boolean bHide) {
if(bHide) {
handler.sendEmptyMessage(0);
}
else {
handler.sendEmptyMessage(1);
}
}
}
In your Main activity class, define a share method:
public void share(){
runOnUiThread(new Runnable(){
@Override
public void run() {
Intent iShare = new Intent(Intent.ACTION_SEND);
iShare.setType("text/plain");
iShare.putExtra(Intent.EXTRA_SUBJECT, "Download The Game");
iShare.putExtra(Intent.EXTRA_TEXT, "Get The Game"+" "+"https://play.google.com/store/apps/details?id=com.jdtfans.jdtfootballkickers");
try{
startActivity(Intent.createChooser(iShare,"Share Via"));
}catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getApplicationContext(),
"No Sharing Client Installed, Toast.LENGTH_SHORT)
.show();
}
}
});
}
Then in your GameOverScene Class, Uncomment the line below and change "Share" to "shareAction":
CCMenuItemImage shareI = CCMenuItemImage.item("Image/MainMenu/share.png", "Image/MainMenu/Share.png", this, "shareAction");
Then, define the shareAction method below the restartAction() method:
public void shareAction(Object sender) {
if (BeetleshotMainActivity.app._soundplay == true)
_soundMananger.ePlayButtonClickSound();
BeetleshotMainActivity.app.share();
}
这篇关于处理一个分享按钮点击Android游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!