online camp #1: pengenalan j2me, eclipse, dan game canvas
DESCRIPTION
Materi pertama Online Camp MGDW4. Jika dirasa terlalu cepat pada bagian programming, silahkan pause lalu lanjutkan setelah sTRANSCRIPT
Mobile Game Developer War 4: Online Camp
MGDW4 Online Camp #1
Pengenalan J2ME, Eclipse, dan Game Canvas
Mobile Game Developer War 4: Online Camp
Software pendukung
• Java JDK(http
://www.oracle.com/technetwork/java/javase/downloads/jdk-7u1-download-513651.html)
• Wireless Toolkit [emulator default dari Java](http://www.oracle.com/technetwork/java/download-135801.html)
• Eclipse Pulsar(http://eclipse.org/pulsar/)
• Opsional:– Nokia S40/S60 Emulator– Perl [dibutuhkan oleh Nokia Emulator]
Mobile Game Developer War 4: Online Camp
JDK – J2ME – dan Eclipse Pulsar
• FAQ:– Apakah saya bisa menggunakan JDK versi
1.x saya?– Apakah saya bisa menggunakan Eclipse yang
biasa saya gunakan?• Bisa, asal Eclipsenya bisa membuat J2ME Project
Mobile Game Developer War 4: Online Camp
Mobile Game Developer War 4: Online Camp
Workspace Eclipse1. Project Explorer
2. Work here!
3. Class explorer
4. Console and debugger
5. Eclipse Menu and Toolbars
Mobile Game Developer War 4: Online Camp
Menambahkan emulator ke Eclipse
• Install Wireless Toolkit atau Nokia Emulator terlebih dahulu• Pada Eclipse, pilih Window > Preferences akan muncul menu seperti dibawah
Untuk Pulsar versi lama pilihannya bernama Import
Pulsar terbaru menggunakan menu Manual Install
Mobile Game Developer War 4: Online Camp
Klik Manual Install (atau Import)…
Mobile Game Developer War 4: Online Camp
Browse ke folder dimana kita menyimpan Emulatornya. Lalu tekan finish, tunggu
beberapa saat, nanti akan muncul seperti ini.
Lalu tekan OK untuk menutup Preferences
Mobile Game Developer War 4: Online Camp
Membuat MIDlet Project baru
Mobile Game Developer War 4: Online Camp
Buat MIDlet dalam project
MIDlet adalah class utama yang akan dijalankan oleh aplikasi J2ME
Mobile Game Developer War 4: Online Camp
Fill detail for MIDletForm tersebut adalah:• Package, mendefinisikan package dari midlet kita nanti
• Name, nama file midlet
• Modifiers, mendefinisikan modifiers pada file midlet tersebut
• Superclass, mendefinisikan midlet tersebut akan inheritance terhadap class apa
• Interface, jika file yang kita buat akan implements terhadap suatu interface
Mobile Game Developer War 4: Online Camp
Standar file MIDlet1. TebakAngka() merupakan
konstruktor
2. startApp(), fungsi yang pertama kali dijalankan
3. pauseApp(), fungsi yang dijalankan ketika game dipause
4. destroyApp(), fungsi yang dijalankan ketika game akan diberhentikan
Mobile Game Developer War 4: Online Camp
KERANGKA MIDLET DAN GAMECANVAS
Kode awal
Mobile Game Developer War 4: Online Camp
Struktur MIDlet [MainMidlet.java]import javax.microedition.midlet.MIDlet;import javax.microedition.midlet.MIDletStateChangeException;
public class MainMidlet extends MIDlet {public MainMidlet() {}protected void destroyApp(boolean arg0) throws MIDletStateChangeException {}protected void pauseApp() {}protected void startApp() throws MIDletStateChangeException {}
}
Mobile Game Developer War 4: Online Camp
Running ProjectKlik kanan pada project yang ingin di running, lalu Run As > Emulated Java ME MIDlet
Mobile Game Developer War 4: Online Camp
Hello World!import javax.microedition.midlet.MIDlet;import javax.microedition.midlet.MIDletStateChangeException;
public class MainMidlet extends MIDlet {public MainMidlet() {}protected void destroyApp(boolean arg0) throws MIDletStateChangeException {}protected void pauseApp() {}protected void startApp() throws MIDletStateChangeException {
System.out.println("Hello world!");}
}
Mobile Game Developer War 4: Online Camp
Struktur MIDlet [MainMidlet.java]import javax.microedition.midlet.MIDlet;import javax.microedition.midlet.MIDletStateChangeException;import javax.microedition.lcdui.Display;
public class MainMidlet extends MIDlet {public MainCanvas canvas;public MainMidlet() {
canvas = new MainCanvas();}protected void destroyApp(boolean arg0) throws MIDletStateChangeException {}protected void pauseApp() {}protected void startApp() throws MIDletStateChangeException {
Display display = Display.getDisplay(this);display.setCurrent(canvas);canvas.mulai();
}}
Pada tahap ini akan muncul beberapa error, biarkan dulu.
Mobile Game Developer War 4: Online Camp
Buat GameCanvas
• File>New>Class– Set superclass– Add interface
Mobile Game Developer War 4: Online Camp
Struktur GameCanvas [MainCanvas.java]import javax.microedition.lcdui.game.GameCanvas;import javax.microedition.lcdui.Graphics;public class MainCanvas extends GameCanvas implements Runnable {
public Graphics g;Thread runner;public static int SLEEP_TIME = 1000/30;protected MainCanvas() {
super(false);this.setFullScreenMode(true);g = getGraphics();runner = new Thread(this);
}public void mulai(){
runner.start();}public void run() {
//di slide berikutnya}
}
Mobile Game Developer War 4: Online Camp
Struktur GameCanvas [MainCanvas.java]public void run() {
while(true){System.out.println("Testing dulu yah...");flushGraphics();try {
Thread.sleep(SLEEP_TIME);} catch (InterruptedException e) {
e.printStackTrace();}
}}
Mobile Game Developer War 4: Online Camp
Game Looppublic void run() {
while(true){System.out.println("Testing dulu yah...");flushGraphics();try {
Thread.sleep(SLEEP_TIME);} catch (InterruptedException e) {
e.printStackTrace();}
}}
while(!gameOver){GetInput();UpdateGame();DrawGame();flushGraphics();try {Thread.sleep(SLEEP_TIME);}catch (InterruptedException e){
e.printStackTrace();}}
Mobile Game Developer War 4: Online Camp
Layar Device
Terdapat 2 jenis layar pada device, yaitu:• Landscape, dimana lebar > tinggi layar• Portrait, dimana tinggi > lebar layar
Mobile Game Developer War 4: Online Camp
Cartesian system on Device
Mobile Game Developer War 4: Online Camp
Screen Size
• Landscape, rata – rata 320 x 240 pixel
• Portrait, rata – rata 240 x 320 pixel
Mobile Game Developer War 4: Online Camp
How to develop landscape game
• Emulator WTK, Qwerty Device– Layar ada yang berlebih
dibagian bawah– Tidak dapat menggunakan
getHeight() secara langsung
Mobile Game Developer War 4: Online Camp
How to develop portrait game
• Emulator WTK 2.5.2, DefaultColorPhone– Just use it nice and simple emulator
Mobile Game Developer War 4: Online Camp
Terima kasih.
• Untuk menyelesaikan materi, kunjungi http://bit.ly/KJmFfA
• Untuk pertanyaan atau diskusi, bisa dilakukan via forum: http://bit.ly/mgdw4forum