2017-09-14 46 views
-4

example :添加更多應用程序按鈕到我的遊戲?

我想要的東西,就像這個例子

這裏是我的按鈕代碼: 我想刪除的幫助按鈕,並在谷歌按鈕添加到應用程序發揮市場

你能幫助我請:它是一個java文件

正如我說,我想,列出的遊戲遊戲3就像截圖

我已經什麼搜索的例子,但它不工作FR我

// buttons 
    CCMenuItemImage play = CCMenuItemImage.item("menu/play1.png", "menu/play2.png", this, "onPlay"); 
    play.setAnchorPoint(1, 0); 
    play.setPosition(G.width, 0); 

    CCMenuItemToggle sound = CCMenuItemToggle.item(this, "onSound", 
     CCMenuItemImage.item("menu/sound_off.png", "menu/sound_off.png"), 
     CCMenuItemImage.item("menu/sound_on.png", "menu/sound_on.png")); 
    sound.setSelectedIndex(G.sound?1:0); 
    sound.setPosition(G.width*0.4f, 70); 

    CCMenuItemToggle music = CCMenuItemToggle.item(this, "onMusic", 
     CCMenuItemImage.item("menu/music_off.png", "menu/music_off.png"), 
     CCMenuItemImage.item("menu/music_on.png", "menu/music_on.png")); 
    music.setSelectedIndex(G.music?1:0); 
    music.setPosition(G.width*0.5f, 70); 
    CCMenuItemImage help = CCMenuItemImage.item("menu/help1.png", "menu/help2.png", this, "onHelp"); 
    help.setPosition(G.width*0.6f, 70); 

    CCMenu menu = CCMenu.menu(play, sound, music, help); 
    menu.setPosition(0, 0); 
    addChild(menu); 

    setIsKeyEnabled(true); 
} 

public void onPlay(Object sender) 
{ 
    if(G.sound) G.soundClick.start(); 

    CCScene s = CCScene.node(); 
    s.addChild(new SelectLayer(false)); 
    CCDirector.sharedDirector().replaceScene(CCFadeTransition.transition(0.7f, s)); 
} 

public void onSound(Object sender) 
{ 
    if(G.sound) G.soundClick.start(); 

    G.sound = !G.sound; 
    SharedPreferences sp = CCDirector.sharedDirector().getActivity().getSharedPreferences("GameInfo", 0); 
    SharedPreferences.Editor et = sp.edit(); 
    et.putBoolean("sound", G.sound); 
    et.commit(); 
} 

public void onMusic(Object sender) 
{ 
    if(G.sound) G.soundClick.start(); 

    G.music = !G.music; 
    SharedPreferences sp = CCDirector.sharedDirector().getActivity().getSharedPreferences("GameInfo", 0); 
    SharedPreferences.Editor et = sp.edit(); 
    et.putBoolean("music", G.music); 
    et.commit(); 

    if (G.music) 
    { 
     G.bgSound.start(); 
    } 
    else 
    { 
     G.bgSound.pause(); 
    } 
} 

public void onHelp(Object sender) 
{ 
    if(G.sound) G.soundClick.start(); 

    CCScene s = CCScene.node(); 
    s.addChild(new HelpLayer()); 
    CCDirector.sharedDirector().replaceScene(CCFadeTransition.transition(0.7f, s)); 
} 

public boolean ccKeyDown(int keyCode, KeyEvent event) 
{ 
    int pid = android.os.Process.myPid(); 
    android.os.Process.killProcess(pid); 
    Runtime r = Runtime.getRuntime(); 
    r.gc(); 
    System.gc(); 
    return true; 
} 

} 
+1

歡迎堆棧溢出!請[參觀](http://stackoverflow.com/tour)以查看網站的工作原理和問題,並相應地編輯您的問題。另請參閱:[爲什麼「有人可以幫我嗎?」不是一個實際的問題?](http://meta.stackoverflow.com/q/284236) –

+0

我會的,謝謝喬 –

回答

0

你可以試試這個,它爲我工作

final ImageButton mybutton = (ImageButton) findViewById(R.id.imageButton); 
mybutton.setOnClickListener(new View.OnClickListener() { 

    @Override 
    public void onClick(View v) { 

     String str ="https://play.google.com/store/apps/details?id=ws.crandell.newspaperpuzzles"; 
     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(str))); 

    } 

}); 
相關問題