1 / 33

Android Game Development

Android Game Development. Android basics. About Android. Linux based operating system Open source Designed for handheld devices Developed by Android Inc. Google (2005) Open Handset Alliance (2007) Very successful system (75% sales in 2012). Top mobile operating systems.

xanthe
Télécharger la présentation

Android Game Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Android Game Development Androidbasics

  2. AboutAndroid • Linux based operating system • Open source • Designed for handheld devices • Developed by • Android Inc. • Google (2005) • Open HandsetAlliance (2007) • Very successful system (75% sales in 2012)

  3. Top mobile operating systems

  4. Android basics • Can run Java code on Dalvik VM • Multi-user system (each application is a different user) • Unique user ID • Has its own virtual machine • Has its own Linux process • Principle of least privilege • Applications can share data

  5. Application components • Building blocks of an application • 4 types • Activity • Single screen with UI • Service • Backgroud process without UI • Content provider • Manages a shared set of application data • Broadcast receiver • Responds to system-wide broadcast announcements

  6. Applications • All components of an application runs in the same process • The system tries to keep a process as long as possible • Applications are stored in a stack • The systems duty to destroy the applications • The system uses importance hierarchy • Foreground processes • Visible process • Service process • Background process • Empty process

  7. Activitylifecycle

  8. Androiddevelopment • Andriod SDK (http://developer.android.com/sdk) • Java API libraries for different platforms • SDK manager • AVD Manager (emulator) • Developer IDE • Eclipse with ADT (Juno has it by default) • Netbeans with NBAndroidplugin • Android device • USB Driver • Enable USB debugging • Useful link: http://developer.android.com

  9. IDE basics • NetBeans • https://kenai.com/projects/nbandroid/pages/Install • https://kenai.com/projects/nbandroid/pages/Intro • Eclipse • For ADT bundle everything is set up • http://developer.android.com/sdk/installing/bundle.html • For Juno install is not required, for other existing Eclipse installs: • http://developer.android.com/sdk/installing/adding-packages.html • Add platforms and packages • http://developer.android.com/sdk/installing/adding-packages.html

  10. Set up virtual devices

  11. Set up virtual devices Presets

  12. API levels

  13. API levels

  14. New Project (NetBeans)

  15. New Project

  16. New Project

  17. AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="gamedev.android.UEngine.PlatformGame" android:versionCode="1" android:versionName="1.0"> <application android:label="@string/app_name" > <activity android:name="MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> Our application version Activity to start Icon label of our Activity We can change this to e.g.: “MyPlatformGame”

  18. Start a virtual device

  19. Build and run the project MainActivity.java: setContentView(R.layout.main); Main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Hello World, MainActivity" /> </LinearLayout>

  20. OpenGL ES – MainActivity.java import android.app.Activity; import android.opengl.GLSurfaceView; import android.os.Bundle; public class MainActivity extends Activity { private GLSurfaceViewmGLView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mGLView = new MainSurfaceView(this); setContentView(mGLView); } }

  21. OpenGL ES – MainSurfaceView.java package gamedev.android.UEngine.PlatformGame; import android.content.Context; import android.opengl.GLSurfaceView; public class MainSurfaceView extends GLSurfaceView { private MainRenderermRenderer; public MainSurfaceView(Context context) { super(context); this.mRenderer = new MainRenderer(getContext()); setRenderer(this.mRenderer); } }

  22. OpenGLES – MainRenderer.java package gamedev.android.UEngine.PlatformGame; import android.content.Context; import android.opengl.GLSurfaceView; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; public class MainRenderer implements GLSurfaceView.Renderer{ private Context context; public MainRenderer(Context context) { this.context = context; } public void onSurfaceCreated(GL10 gl, EGLConfigconfig) { gl.glClearColor(0.5F, 0.5F, 1.0F, 1.0F); } public void onDrawFrame(GL10 gl) { gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT ); } public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); } }

  23. Build and run

  24. Draw something - MainRenderer • New imports import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; • New data member protected FloatBuffer VB = null; public float rotAngle = 0;

  25. Draw something - MainRenderer public void onSurfaceCreated(GL10 gl, EGLConfigconfig) { gl.glClearColor(0.5F, 0.5F, 1.0F, 1.0F); float[] VCoords = { -1.0F, -1.0F, 0.0F, 1.0F, -1.0F, 0.0F, 1.0F, 1.0F, 0.0F, -1.0F, -1.0F, 0.0F, 1.0F, 1.0F, 0.0F, -1.0F, 1.0F, 0.0F }; ByteBuffervbb = ByteBuffer.allocateDirect(VCoords.length * 4); vbb.order(ByteOrder.nativeOrder()); this.VB = vbb.asFloatBuffer(); this.VB.put(VCoords); this.VB.position(0); }

  26. Draw something - MainRenderer public void onDrawFrame(GL10 gl) { gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT ); gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0,0,-6); gl.glColor4f(1, 0, 0, 1); gl.glRotatef(rotAngle, 0, 1, 0); gl.glEnableClientState(gl.GL_VERTEX_ARRAY); gl.glVertexPointer(3, gl.GL_FLOAT, 0, this.VB); gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6); gl.glDisableClientState(gl.GL_VERTEX_ARRAY); rotAngle += 2.5f; }

  27. Draw something - MainRenderer public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); float ratio = (float) width / height; gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustumf(-ratio, ratio, -1, 1, 1.0f, 10); }

  28. Build and run

  29. Input handling - MainSurfaceView protected float lastX = -1; public booleanonTouchEvent(MotionEvent e) { float x = e.getX(); switch (e.getAction()) { case MotionEvent.ACTION_MOVE: float dx = lastX == -1 ? 0 : x - lastX; mRenderer.rotAngle += dx * 1.0f; break; } lastX = x; return true; } Also remove rotAngle += 2.5f; from MainRenderer.onDrawFrame

  30. Build and run • Quad can be rotated with the mouse in emulator

  31. Orientation – Full screen • Fix orientation to landscape (typical in games) Activity::onCreate(): setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); • Set to full screen (typical in games) Activity::onCreate(): requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); • Rotate emulator to landscape mode: Ctrl+F12

  32. Compile and run

  33. The End

More Related