First, this is my first week at android programming, I am trying to conceptualize how games are built. I have a setup, where I've drawn Several views, I'm just wondering how do I put all the views together, each to its thread, but in such a way they all can interact.
MainActivity: flash screen and invokes GameMenuActivity on Load
GameMenuActivity: calls GamveMenuView
GameMenuView: Keeps Track of scores/names/and launches StationActivity
StationActivity: calls StationViewsManager
StationViewsManager: hoping to be the class where I draw all objects and keep them together
/*
gameView = new GameBackgroundView(this);
movingMeteors = new MovingMeteors(this);
movingSpaceShip = new movingSpaceShip(this);
gameView.setClickable(true);
gameView.setFocusable(true);
gameView.addView(movingMeteors);
gameView.addView(movingSpaceShip);
setContentView(gameView);
this is where I'm not sure how to combine the views and draw them. Perhaps i'm not taking the problem from a right angle. any help will be appreciated
*/
GameThreadManager: setups up threads of type StationViews
here's a quick snippet, on its instantiation GameThreadManager(StationViews view) it accepts views, that can be run by the method bellow
@SuppressLint("WrongCall")
@Override
public void run() {
long ticksPS = 1000 / FPS;
long startTime;
long sleepTime;
while (running) {
Canvas c = null;
startTime = System.currentTimeMillis();
try {
c = view.getHolder().lockCanvas();
synchronized (view.getHolder()) {
view.onDraw(c);
}
} finally {
if (c != null) {
view.getHolder().unlockCanvasAndPost(c);
}
}
sleepTime = ticksPS-(System.currentTimeMillis() - startTime);
try {
if (sleepTime > 0)
sleep(sleepTime);
else
sleep(10);
} catch (Exception e) {}
}
}
StationViews: superclass of views, draws transparent background,to handle other views
StationMeteors: raining meteors
StationBackground: revolving background
StationDefender: static, left side of screen and shoots bullets