Primeiro de tudo, configure seu ambiente de desenvolvimento e crie um novo Projeto Android.
Nossa primeira Activity é uma Tela de Apresentação (GameSplash) que aparece durante alguns segundos enquando o jogo está carregando e que vai transicionar para a próxima tela (GameSelect).
GameSplash.java
- não tratar nenhum evento de tecla
- não ficar na activity stack (android:noHistory)
- transicionar para a próxima tela após alguns segundos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
package br.com.thiagorosa.pingpongmadness.tutorial; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.KeyEvent; public class GameSplash extends Activity { // tempo para esperar durante a tela de aprensetaćão private static final int SPLASH_SCREEN_DELAY = 3000; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); new Thread() { @Override public void run() { try { // fazer as inicializacões aqui // espere alguns segundos antes de ir para a próxima tela sleep(SPLASH_SCREEN_DELAY); } catch (InterruptedException e) { } catch (Exception e) { } finally { // inicie a tela de selecão de level Intent intentSelect = new Intent(GameSplash.this, GameSelect.class); startActivity(intentSelect); } } }.start(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // ignore qualquer tecla pressionada na tela de apresentacao return true; } } |
splash.xml
- RelativeLayout com um fundo preto
- ImageView com o logo e centralizado no parent
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FF000000" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_gravity="center" android:src="@drawable/logo" /> </RelativeLayout> |
GameSelect.java
- mostra um simples layout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
package br.com.thiagorosa.pingpongmadness.tutorial; import android.app.Activity; import android.os.Bundle; public class GameSelect extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.level_list); } } |
level_list.xml
- RelativeLayout com um fundo preto
- TextView com uma mensagem temporária
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FF000000" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="This activity will have a list of all the levels available." /> </RelativeLayout> |
AndroidManifest.xml
- versão mínima do sdk versão 7
- preferir instalar no sd card (precisa do target sdk versão 8)
- activities são sempre landscape
- activities são sempre full screen sem title bar
- activities cuidam de mudanças na orientação e no teclado
- GameSplash removido da activity stack
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="preferExternal" package="br.com.thiagorosa.pingpongmadness.tutorial" android:versionCode="1" android:versionName="Tutorial - Part 01" > <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="8" /> <application android:debuggable="true" android:icon="@drawable/icon" android:label="@string/app_name" > <activity android:configChanges="orientation|keyboard|keyboardHidden" android:name=".GameSplash" android:noHistory="true" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:configChanges="orientation|keyboard|keyboardHidden" android:name=".GameSelect" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" /> </application> </manifest> |
Projeto SVN:
PingPong Madness Tutorial – Parte 01 SVN
APK:
PingPong Madness Tutorial – Parte 01.apk
Trackbacks/Pingbacks