I have a button that I touch to enter a game mode. All buttons start the same activity, but the rules and physics are changed depending on what you touch.
I want to track the button pressed so that I can know if people selected Classic mode or Training mode, and set the rules accordingly. How would I do this?
Here is how I start my game modes from the menu:
MenuElement classic = mElements.get(0);
MenuElement training = mElements.get(1);
if(touchX > classic.mX && touchX < classic.mX + classic.mBitmap.getWidth()
&& touchY > classic.mY && touchY < classic.mY + classic.mBitmap.getHeight())
{
aux = "Starting game";
Context context = com.Juggle2.Menu.this.getContext();
Intent intent = new Intent(context, StartGame.class);
intent.putExtra("rule", 1);
context.startActivity(intent);
}
if(touchX > training.mX && touchX < training.mX + classic.mBitmap.getWidth()
&& touchY > training.mY && touchY < training.mY + training.mBitmap.getHeight())
{
aux = "Starting training";
Context context = com.Juggle2.Menu.this.getContext();
Intent intent = new Intent(context, StartGame.class);
intent.putExtra("rule", 2);
context.startActivity(intent);
}
And here is where it goes:
public class StartGame extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(new Panel (this)); //Start the game
}
}
Now I need that bundle of extras to be accessible by my Panel class, which is a SurfaceView.
Oh, I got it:
I found a way to do what I wanted in a lot less steps
public class Global{
public static int rules = 0;
}
And now I can just access those rules whenever and wherever I want by typing Global.rules
That seems so simple, in hindsight.
I found a way to do what I wanted in a lot less steps
And now I can just access those rules whenever and wherever I want by typing
Global.rules