我的java技能不强。只在其中编程了一两个月,所以请原谅我的愚蠢。
我正在尝试在捆绑包中的方法之间传递值,以允许我保存和加载一些游戏设置,但尽管我认为我的值正在传输,但我无法从“创建方法”中获取值以用于我的程序的其余部分。
我在这里加载和捆绑我的布尔值(我已经剪掉了很多或希望不相关的东西):
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
vV = new VortexTouch(this);
CONTEXT = this;
// LOAD DATA
SharedPreferences settings = getSharedPreferences("GAME_DATA",MODE_PRIVATE);
_dPad = settings.getBoolean("GamePad", true);
// PASS DATA
intent = new Intent();
intent.setClass(this,VortexRenderer.class);
intent.putExtra("my_data", true); // should be _dPad but put 'true' in there for now.
startActivity(intent);
// PASS DATA END
setContentView(vV);
}
然后在我的 VortexRenderer 类中接收布尔值:
public class VortexRenderer extends Activity implements GLSurfaceView.Renderer {
private static final String LOG_TAG = VortexRenderer.class.getSimpleName();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = getIntent().getExtras();
_dPad = bundle.getBoolean("my_data");
_dPad = true; // testing to see if value carries, it doesn't :-(
finish();
}
public boolean _dPad;
public void SomeGameAction(){
//try to do something with _dPad but it has not taken on a value of true. why?
}
所以我认为 _dPad 的价值是从一个活动到另一个活动,但它并没有脱离 VortexRenderer 'onCrate' 方法..显然我不明白一些东西..有人可以帮忙吗?谢谢。
如果有帮助的话,我的游戏是围绕这个优秀的教程构建的(不是说现在还剩下很多原版): http ://www.droidnova.com/android-3d-game-tutorial-part-i,312.html
不太有用,但如果您有兴趣,这就是我试图将代码添加到: https ://market.android.com/details?id=com.clockworkrobot.spacewarz