Witam,
stawiam pierwsze kroki jesli chodzi o Androida i mam problem ktory nie wiem jak rozwiazac. Stworzylem prosta klase dziedziczacza po SurfaceView lecz po stworzeniu jej instancji metoda surfaceCreated() nie jest wywolywana, w czasie debugowania watek wchodzi w konstruktor i dalej nic sie nie dzieje, na telefonie mam czarny ekran.
Prosze o pomoc jesli ktos wie o co moze chodzic. Ponizej kod.
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gameModel_ = new GameModel();
//turn off the title at the top of the screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
//turn on full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Activity extends context
setContentView(new GameView(this, gameModel_));
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
protected void onStop() {
super.onStop();
}
//private section
GameModel gameModel_;
}
--
public class GameView extends SurfaceView implements SurfaceHolder.Callback{
public GameView(Context context, GameModel gameModel){
super(context);
getHolder().addCallback(this);
gameModel_ = gameModel;
snake_ = new Snake(BitmapFactory.decodeResource(getResources(), R.drawable.snakes_segment));
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
gameModel_.init(this);
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {//TODO: IMPROVE
gameModel_.getGameEngine().setGameRunning(false);
}
public void render(Canvas canvas){
snake_.draw(canvas);
}
//private section
GameModel gameModel_;
private Snake snake_;
}
--
plik XML:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.andro...pk/res/android"
package="com.example.jakub.snake2">
<application android:allowBackup="true" android:label="@string/app_name"
android:icon="@mipmap/ic_launcher" android:theme="@[member=stylezzz]/AppTheme">
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>