/* * Callback invoked when the Surface has been created and is ready to be * used. */ public void surfaceCreated(SurfaceHolder holder) { // start the thread here so that we don't busy-wait in run() // waiting for the surface to be created if (thread.getState() == Thread.State.TERMINATED) { thread = new GameThread(holder, getContext(), new Handler()); thread.setRunning(true); thread.start(); thread.doStart(); startLevel(); } else { thread.setRunning(true); thread.start(); } }
/** * The game view. * * @param Context context * @param Activity activity * @param int stage - The stage to load. * @param int level - The level to load. * @param float screenDensity - The screen density. */ public GameView(Context context, Play activity, int stage, int level, float screenDensity) { super(context); mGameContext = context; mGameActivity = activity; mScreenDensity = screenDensity; mPlayerStage = stage; mPlayerLevel = level; mGameTileData = new GameTileData(context); mGameLevelTileData = new GameLevelTileData(context); mGameTileTemplates = mGameTileData.getTilesData(); SurfaceHolder holder = getHolder(); holder.addCallback(this); // create thread only; it's started in surfaceCreated() thread = new GameThread(holder, context, null); setFocusable(true); mUiTextPaint = new Paint(); mUiTextPaint.setStyle(Paint.Style.FILL); mUiTextPaint.setColor(Color.YELLOW); mUiTextPaint.setAntiAlias(true); Typeface uiTypeface = Typeface.createFromAsset(activity.getAssets(), "fonts/Molot.otf"); if (uiTypeface != null) { mUiTextPaint.setTypeface(uiTypeface); } mUiTextPaint.setTextSize( mGameContext .getApplicationContext() .getResources() .getDimensionPixelSize(R.dimen.ui_text_size)); startLevel(); thread.doStart(); }