SlideShare a Scribd company logo
Series 40 Developer Training
Getting Started with Game
Development on Nokia Series 40 Full
Touch Asha Phones


Michael Samarin, Ph.D
Director,
Developer Training and Evangelism
Futurice

+358 40 518 18 09
michael.samarin@futurice.com

                                      @MichaelSamarin
Today’s topics
» This presentation is summary and compressed extracts
  relevant to game development from previous webinars:
   › Overview of full touch Asha Devices
   › Overview of graphical APIs for 2D and 3D Game
     development Mobile Java
   › User input in full touch devices
   › Useful in games performance tips on Series 40
New Series 40 Full Touch Platform



                                    Asha 305
                                    Asha 306
                                    Asha 311




                                      Retail
                                    70 – 120 $
Asha 305, 306      Asha 308, 309         Asha 311
 Jar Size       2 Mb               2 Mb               2 Mb
Java Heap       2 Mb               2 Mb              4 Mb
 CPU             --                 --               1 GHz
                Resistive        Capacitive         Capacitive
Screen                                            Multipoint-Touch
            Multipoint-Touch   Multipoint-Touch
Series 40 Graphics APIs
» 2D Game Development
   › Game API, part of the MIDP 2.0 standard, java package:
     javax.microedition.lcdui.game

   › http://www.developer.nokia.com/Resources/Library/Java/#!deve
     lopers-guides/ui-and-graphics/game-api.html

» 3D Game Development
   › Mobile 3D Graphics API, optional JSR-184 also known as M3G
   › http://www.developer.nokia.com/Resources/Library/Java/#!deve
     lopers-guides/ui-and-graphics/mobile-3d-graphics.html
› Game API Package (MIDP)
› javax.microedition.lcdui.game
  › GameCanvas
  › Layer
  › LayerManager
  › Sprite
  › TiledLayer
› GameCanvas
  › Double buffered
  › Convenient for minimizing code of
    game loop
  › Methods for querying status of keys
› GameCanvas
public class MyCanvas extends GameCanvas implements Runnable {
    public void run() {
        Graphics g = getGraphics();
        while(true) {
             // update the game state
            int k = getKeyStates();
             // respond to key events
             flushGraphics();
        }
    }
}
› Graphical Assets
› Graphical Assets – Sprite Star
› Graphical Assets – Sprite Lightning
› Layer
  › Abstract class, any visual game
    element
› LayerManager
  › Combines layers together,
    provides viewport
› Sprite
  › Animated game object
› TiledLayer
  › Game areas, backgrounds
› Sprite
  › Animated element of the game
    (character)
  › Define Sequence, Delay
  › Flip, Rotate
  › Define Reference Point
  › Detect Collisions
› TiledLayer
  › Defines game backgrounds
  › Can be animated
  › Doesn’t have Sprite methods
› Object-Oriented 3D
                         › Scene Graph based
                         › Optional MIDP JSR
Mobile 3D Graphics API   › Very compact API

      JSR-184 or M3G     › Very fast development
                         › Optimized for small
                           memory and budget CPU
                         › Excellent implementation
                           on Series 40
Lightweight API, only 30 classes
AnimationController   IndexBuffer        RayIntersection
AnimationTrack        KeyframeSequence   SkinnedMesh
Appearance            Light              Sprite3D
Background            Loader             Texture2D
Camera                Material           Transform
CompositingMode       Mesh               Transformable
Fog                   MorphingMesh       TriangleStripArray
Graphics3D            Node               VertexArray
Group                 Object3D           VertexBuffer
Image2D               PolygonMode        World
› Immediate mode
               › Similar to OpenGL ideology

            › Retained mode

M3G Modes      › Scene Graph based
               › Entire Scene Graph can be
                 restored from file
               › Well defined M3G format

            › Can be freely mixed
Scene Graph

        Background       Mesh


          Group      Morphing Mesh


World                Skinned Mesh
                                     Sprite 3D
                        Group
                                     Sprite 3D   User Object
          Group         Camera


                         Light
› World
                      › Background

                   › Morphing and Skinned Mesh

Most Interesting      › Animated Geometry Objects

   Scene Graph     › Mesh
       Elements       › 3D Geometry of Visible Object

                   › Sprite 3D
                      › 2D image in 3D space
public class Canvas3D extends Canvas

         implements Runnable {

    public Canvas3D(){

    }

    public void paint(Graphics g) {

    }

    public void run() {

    }

}
public class Canvas3D extends Canvas

         implements Runnable {
                                       private Thread thread;
    public Canvas3D(){
                                       private long startTime;
    }
                                       private Graphics3D graphics3D;
    public void paint(Graphics g) {
                                       private World world;
    }
                                       private Camera camera;
    public void run() {
                                       private boolean running = false;
    }

}
setFullScreenMode(true);

                                       thread = new Thread(this);
public class Canvas3D extends Canvas
                                       startTime = System.currentTimeMillis()
         implements Runnable {
                                       graphics3D = Graphics3D.getInstance();
    public Canvas3D(){
                                       world = new World();
    }
                                       camera = new Camera();
    public void paint(Graphics g) {
                                       float aspect = (float) getWidth() / (float) getHeight();
    }
                                       camera.setPerspective(30.0f, aspect, 1.0f, 1000.0f);
    public void run() {                world.addChild(camera);

    }                                  world.setActiveCamera(camera);

}                                      running = true;

                                       thread.start();
public class Canvas3D extends Canvas

         implements Runnable {
                                       graphics3D.bindTarget(g);
    public Canvas3D(){
                                       world.animate(
    }
                                           (int)(System.currentTimeMillis() -
                                                     startTime));
    public void paint(Graphics g) {
                                       graphics3D.render(world);
    }
                                       graphics3D.releaseTarget();
    public void run() {

    }

}
public class Canvas3D extends Canvas

         implements Runnable {

    public Canvas3D(){                 while (running){

    }                                      repaint();

    public void paint(Graphics g) {        Thread.sleep(20);

    }                                  }

    public void run() {

    }

}
› User input in full touch Asha devices
   › Game keys simulation
   › Touch events
   › Multipoint-touch
   › Gestures
   › Sensors
Game keys simulation
» No touch handling in Canvas?
   › Drag gestures automatically trigger simulated key events

   › Up, Down, Left, Right
› Tap: touch + release
           › Long Press (& repeated): touch +
             hold

  Touch    › Drag: touch + drag
           › Drop: touch + drag + touch down
Gestures     (“stop”) + release
           › Flick: touch + drag + release while
             dragging
           › Pinch (new!): 2x touch + 2x drag +
             2x touch down (“stop”) + 2x release
Using Gestures
 › Register as gesture listener
public class MainCanvas extends Canvas implements GestureListener {
    private int curPinchDistance = -1;
    public MainCanvas() {
        // Set this as container (gesture source) and listener
        GestureRegistrationManager.setListener(this, this);
        // Register for pinch events in the whole canvas area
        gestureZone = new GestureInteractiveZone(GestureInteractiveZone.GESTURE_PINCH);
        GestureRegistrationManager.register(this, gestureZone);
    }

       › Zone: reacts to 1+ specified gestures
            › Whole screen or rectangular area

            › Overlap possible

       › Received events → GestureListener
Using Gestures
   › Handling gestures
public void gestureAction(Object container, GestureInteractiveZone gestureInteractiveZone, GestureEvent gestureEvent) {
    int eventType = gestureEvent.getType();
    switch (eventType) {
        case GestureInteractiveZone.GESTURE_PINCH: // Pinch detected
            curPinchDistance = gestureEvent.getPinchDistanceCurrent(); break;
        case GestureInteractiveZone.GESTURE_RECOGNITION_START: /* ... */ break;
        case GestureInteractiveZone.GESTURE_RECOGNITION_END: /* ... */ break;
    }
}


          › Executed in UI thread
                  › Lengthy operations (scaling image, etc.) → own thread!
› Single touch
                    › Canvas.pointerPressed() part
                      of MIDP
                    › Only tracks 1st touch point
Pointer events   › Multipoint Touch
          and       › Tracks multiple touch points
   Multipoint-
        Touch           › But: use Gesture API if only interested in
                          pinch

                    › Each associated with unique ID, x, y
                      and state
                    › Call-back for touch changes, but
                      status available any time
Using Multipoint-Touch

› Number of touch points                                  2 on Nokia 305 / 306
 MultipointTouch mpt = MultipointTouch.getInstance();     5 on Nokia 311
 int numTouchPoints = MultipointTouch.getMaxPointers();



    › Limited accuracy of simultaneous touch points on a resistive
      screen (Nokia 305) → no on-screen joystick & shoot button

› Register: touch point listener
  public class MainCanvas extends Canvas implements MultipointTouchListener
  {
      public MainCanvas() {
          // ...
          mpt.addMultipointTouchListener(this);
      }
Using Multipoint-Touch
› Handling touch events
 public void pointersChanged(int[] pointerIds) {
     for(int i=0; i<pointerIds.length; i++) {        // Loop through the changed touch points
     {
         int pointerId = pointerIds[i];              // Get the touch point ID
         int state = MultipointTouch.getState(pointerId); // Get the touch point state
         // Get the touch point x and y coordinates
         int x = MultipointTouch.getX(pointerId);
         int y = MultipointTouch.getY(pointerId);

         // Handle the UI update based on the touch point state, ID and coordinates
         switch(state) {
             case MultipointTouch.POINTER_PRESSED:   // A new finger was pressed against the screen
                 drawTouch(pointerId, x, y); break;
             case MultipointTouch.POINTER_DRAGGED:   // A pressed finger was dragged over the screen
                 drawTouch(pointerId, x, y); break;
             case MultipointTouch.POINTER_RELEASED: // A pressed finger was lifted from the screen
                 break;
 } } }
› JSR 256 Sensor API
             › Optional Generic API: designed for
               battery, network status, also for
               temperature, blood pressure, etc.

Sensors   › Usefull in Games
             › Acceleration: –2g .. +2g, x / y / z axis
             › Double Tap: 1 .. 63, phone sides
             › Orientation: 0 .. 6, phone orientation
› Synchronous
                   › Poll sensor

                   › Example: accelerometer in
                     game loop
Sensors Modes   › Asynchronous
                   › DataListener callbacks

                   › Example: phone charger
                     plugged in
Using Multipoint-Touch
› Establish sensor connection
// Find all acceleration sensors, the contextType is left undefined
SensorInfo[] sensorInfos = SensorManager.findSensors("acceleration", null);
// Find an acceleration sensor that returns double values
for (int i = 0; i < sensorInfos.length; i++) {
    if (sensorInfos[i].getChannelInfos()[0].getDataType() == ChannelInfo.TYPE_DOUBLE) {
        accSensor = (SensorConnection) Connector.open(sensorInfos[i].getUrl());
    }
}


› Check data in game loop
 // Use   1 as a buffer size to get exactly 1 value for each axis
 Data[]   data = accSensor.getData(1);
 speedX   = -data[0].getDoubleValues()[0]; // data[0] => x-axis
 speedY   = data[1].getDoubleValues()[0];   // data[1] => y-axis
Hash Acceleration
» Some iterative algorithms are slow. Proper usage of
  collections types of data structures can increase
  performance.
» Vector.contains() is very slow, but Hashtable.containsKey() is
  very fast. Reconsider your algorithms to use Hashtables.
» Usage can be found in very surprising places. For example,
  Font.stringWidth() is slow, but necessary for drawing
  multiline text on Canvas. Creating a Hashtable with the
  width in each character you have used in the Font can
  transform this into a fast operation and increase
  Canvas.paint() speed.
Synchronized vs. Volatile Variables
» When a variable or Object needs to be accessed from more
  than one Thread.
» Marking a variable as volatile is the least restrictive
  approach and can have very high performance because no
  Thread is blocked.
» Only one Thread may enter the synchronized sections at
  any one time.
» Consider atomic operations on two variables. For example, when
  updating firstName and lastName from “John Smith” to “Jane
  Marceau”, do so within a synchronized block to avoid briefly exposing
  the transitional state “Jane Smith” to other threads.
Constants
» We can give the compiler and Proguard more opportunities
  to optimize the code at the compile step, and this will also
  give the ARM processor opportunities for handling these
  variables with more efficient byte codes.
  private static int loopCount = 10;
  private static long startTime = System.currentTimeMillis();
  private static boolean enableImages = true;

  Should be
  private static final int LOOP_COUNT = 10;
  private static final long START_TIME = System.currentTimeMillis();
  private static final boolean ENABLE_IMAGES = true;
Primitives
» Use int instead of short, byte or long.
  for (int i = 0; i < 3000000; i++) {
      short/int/long a = 123;
      short/int/long b = -44;
      short/int/long c = 12;
      a += c;
      b += a;
      c *= b;
  }


  Average times spent in loops on Nokia Asha 305 (obfuscated):
  int:   710 (580) ms
  short: 900 (850) ms 50% slower
  long:  1450 (1150) ms 100% slower
Final in methods
for (int i = 0; i < 1000000; i++) {
    a = finalMethod(1, 2, 3);
}

for (int i = 0; i < 1000000; i++) {
    a = nonFinalMethod(1, 2, 3);
}

public final int finalMethod(final int a, final int b, final int c) {
    final float x = 1.23f, y = 0.05f;
    final float z = x * y;
    final int d = a + b + c;

    return d;
}

public int nonFinalMethod(int a, int b, int c) {
    float x = 1.23f, y = 0.05f;
    float z = x * y;
    int d = a + b + c;

    return d;
}
Final in methods
Average times on a Nokia Asha 305:
finalMethod: 650 ms
nonFinalMethod: 940 ms 45% slower

In this case, the time difference comes from final keyword before
x and y. It is logical because then z value can be precalculated.
The final keywords with parameters a, b, c let us not precalculate
d or anything. And because we don’t use z, it being final does not
help us
Static
» Generally static methods and variables should be faster.
  Oddly, with some combinations of ARM and JVM, instance
  accesses are slightly faster.

   for (int i = 0; i < 1000000; i++) {
       staticMethod();
                                          Average times spent in loops
   }                                      on Nokia Asha 305
   for (int i = 0; i < 1000000; i++) {
       nonStaticMethod();
                                          (obfuscated):
   }

   private static void staticMethod() {   nonStaticMethod: 570 ms
       b++; // static variable
   }                                      staticMethod: 680 ms 20%
   private void nonStaticMethod() {       slower
       a++; // instance variable
   }
String Concatenation
If you are going to concatenate a large number of small Strings,
use:

StringBuffer.append()

instead of the

String +=

operator. String is much slower because every time you
concatenate a string to another with += operator, a new
StringBuffer is created under the hood. Depending on the number
of concatenations, a single explicit StringBuffer can be many times
faster than multiple implicit StringBuffers created by String
addition.
Addition vs. Multiplication vs. Division
for (int i = 0; i < 500000; i++) {
    a = 1.23f;
    b = 1.45f;
    c = 0.004523f;

    c += a;
    a = b + c;
}
for (int i = 0; i < 500000; i++) {
                                     Average times spent in loops
    a = 1.23f;
    b = 1.45f;
                                     on Nokia Asha 305:
    c = 0.004523f;

    c *= a;                          Multiplying: 330 ms
    a = b * c;
}                                    Addition: 360 ms 9% slower
for (int i = 0; i < 500000; i++) {
    a = 1.23f;                       Division: 560 ms 70% slower
    b = 1.45f;
    c = 0.004523f;

    c /= a;
    a = b / c;
}
Switch vs. If
The switch statement in C is implemented as a direct jump which is
extremely fast. In Java on Nokia Series 40 phones, switches are
implemented at the bytecode level as a series of if statements.
Therefore in many cases a switch statement is less efficient than a
manually created series of if..else statements in which the first
positive case is selected as the one which occurs more frequently. If
you prefer to use switch statements for code clarity, then arrange
them so that the most frequent cases appear first.
Live Demo Session
»   If you are watching these slides on SlideShare, next part is live coding
    demonstration with Nokia SDK 2.0 for Java and NetBeans. Full recording of the
    live session can be found at Nokia Developer website:

»   http://www.developer.nokia.com/Resources/Multimedia/Webinars.xhtml
› Andreas Jakl, Nokia


Special thanks
Thank you!




@MichaelSamarin

More Related Content

What's hot

Special Effects with Qt Graphics View
Special Effects with Qt Graphics ViewSpecial Effects with Qt Graphics View
Special Effects with Qt Graphics View
account inactive
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
Jussi Pohjolainen
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5
Takao Wada
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
JinTaek Seo
 
[C++ GUI Programming with Qt4] chap8
[C++ GUI Programming with Qt4] chap8[C++ GUI Programming with Qt4] chap8
[C++ GUI Programming with Qt4] chap8
Picker Weng
 
Java3 d 1
Java3 d 1Java3 d 1
Java3 d 1Por Non
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupGeometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping Setup
Mark Kilgard
 
Motionblur
MotionblurMotionblur
Motionblur
ozlael ozlael
 

What's hot (9)

Special Effects with Qt Graphics View
Special Effects with Qt Graphics ViewSpecial Effects with Qt Graphics View
Special Effects with Qt Graphics View
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
 
[C++ GUI Programming with Qt4] chap8
[C++ GUI Programming with Qt4] chap8[C++ GUI Programming with Qt4] chap8
[C++ GUI Programming with Qt4] chap8
 
Java3 d 1
Java3 d 1Java3 d 1
Java3 d 1
 
Extreme dxt compression
Extreme dxt compressionExtreme dxt compression
Extreme dxt compression
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupGeometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping Setup
 
Motionblur
MotionblurMotionblur
Motionblur
 

Similar to Developing games for Series 40 full-touch UI

Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
Jussi Pohjolainen
 
Game Development for Nokia Asha Devices with Java ME #2
Game Development for Nokia Asha Devices with Java ME #2Game Development for Nokia Asha Devices with Java ME #2
Game Development for Nokia Asha Devices with Java ME #2
Marlon Luz
 
Game development with Cocos2d
Game development with Cocos2dGame development with Cocos2d
Game development with Cocos2d
Vinsol
 
2011.05.27 ACC 기술세미나 : Adobe Flash Builder 4.5를 환경에서 Molehill 3D를 이용한 개발 소개
2011.05.27 ACC 기술세미나 : Adobe Flash Builder 4.5를 환경에서 Molehill 3D를 이용한 개발 소개2011.05.27 ACC 기술세미나 : Adobe Flash Builder 4.5를 환경에서 Molehill 3D를 이용한 개발 소개
2011.05.27 ACC 기술세미나 : Adobe Flash Builder 4.5를 환경에서 Molehill 3D를 이용한 개발 소개
Yongho Ji
 
Cocos2d 소개 - Korea Linux Forum 2014
Cocos2d 소개 - Korea Linux Forum 2014Cocos2d 소개 - Korea Linux Forum 2014
Cocos2d 소개 - Korea Linux Forum 2014
Changwon National University
 
WebGL 3D player
WebGL 3D playerWebGL 3D player
WebGL 3D player
Vasilika Klimova
 
Game development with_lib_gdx
Game development with_lib_gdxGame development with_lib_gdx
Game development with_lib_gdx
Gabriel Grill
 
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Lviv Startup Club
 
14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded GraphicsAdil Jafri
 
Introduction to 2D Game Development on Nokia Series 40 Asha Phones
Introduction to 2D Game Development on Nokia Series 40 Asha PhonesIntroduction to 2D Game Development on Nokia Series 40 Asha Phones
Introduction to 2D Game Development on Nokia Series 40 Asha Phones
Microsoft Mobile Developer
 
Minko stage3d workshop_20130525
Minko stage3d workshop_20130525Minko stage3d workshop_20130525
Minko stage3d workshop_20130525Minko3D
 
Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5
firenze-gtug
 
3D everywhere
3D everywhere3D everywhere
3D everywhere
Vasilika Klimova
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconftutorialsruby
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconftutorialsruby
 
Useful Tools for Making Video Games - Irrlicht (2008)
Useful Tools for Making Video Games - Irrlicht (2008)Useful Tools for Making Video Games - Irrlicht (2008)
Useful Tools for Making Video Games - Irrlicht (2008)
Korhan Bircan
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?
Ankara JUG
 
Scmad Chapter07
Scmad Chapter07Scmad Chapter07
Scmad Chapter07
Marcel Caraciolo
 

Similar to Developing games for Series 40 full-touch UI (20)

Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
Game Development for Nokia Asha Devices with Java ME #2
Game Development for Nokia Asha Devices with Java ME #2Game Development for Nokia Asha Devices with Java ME #2
Game Development for Nokia Asha Devices with Java ME #2
 
Game development with Cocos2d
Game development with Cocos2dGame development with Cocos2d
Game development with Cocos2d
 
2011.05.27 ACC 기술세미나 : Adobe Flash Builder 4.5를 환경에서 Molehill 3D를 이용한 개발 소개
2011.05.27 ACC 기술세미나 : Adobe Flash Builder 4.5를 환경에서 Molehill 3D를 이용한 개발 소개2011.05.27 ACC 기술세미나 : Adobe Flash Builder 4.5를 환경에서 Molehill 3D를 이용한 개발 소개
2011.05.27 ACC 기술세미나 : Adobe Flash Builder 4.5를 환경에서 Molehill 3D를 이용한 개발 소개
 
Cocos2d 소개 - Korea Linux Forum 2014
Cocos2d 소개 - Korea Linux Forum 2014Cocos2d 소개 - Korea Linux Forum 2014
Cocos2d 소개 - Korea Linux Forum 2014
 
WebGL 3D player
WebGL 3D playerWebGL 3D player
WebGL 3D player
 
Game development with_lib_gdx
Game development with_lib_gdxGame development with_lib_gdx
Game development with_lib_gdx
 
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
 
14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded Graphics
 
MIDP: Game API
MIDP: Game APIMIDP: Game API
MIDP: Game API
 
Introduction to 2D Game Development on Nokia Series 40 Asha Phones
Introduction to 2D Game Development on Nokia Series 40 Asha PhonesIntroduction to 2D Game Development on Nokia Series 40 Asha Phones
Introduction to 2D Game Development on Nokia Series 40 Asha Phones
 
Minko stage3d workshop_20130525
Minko stage3d workshop_20130525Minko stage3d workshop_20130525
Minko stage3d workshop_20130525
 
Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5
 
3D everywhere
3D everywhere3D everywhere
3D everywhere
 
Real life XNA
Real life XNAReal life XNA
Real life XNA
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
 
Useful Tools for Making Video Games - Irrlicht (2008)
Useful Tools for Making Video Games - Irrlicht (2008)Useful Tools for Making Video Games - Irrlicht (2008)
Useful Tools for Making Video Games - Irrlicht (2008)
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?
 
Scmad Chapter07
Scmad Chapter07Scmad Chapter07
Scmad Chapter07
 

More from Microsoft Mobile Developer

Intro to Nokia X software platform 2.0 and tools
Intro to Nokia X software platform 2.0 and toolsIntro to Nokia X software platform 2.0 and tools
Intro to Nokia X software platform 2.0 and tools
Microsoft Mobile Developer
 
Lumia App Labs: Lumia SensorCore SDK beta
Lumia App Labs: Lumia SensorCore SDK betaLumia App Labs: Lumia SensorCore SDK beta
Lumia App Labs: Lumia SensorCore SDK beta
Microsoft Mobile Developer
 
Nokia Asha from idea to app - Imaging
Nokia Asha from idea to app - ImagingNokia Asha from idea to app - Imaging
Nokia Asha from idea to app - Imaging
Microsoft Mobile Developer
 
Healthcare apps for Nokia X and Nokia Asha
Healthcare apps for Nokia X and Nokia AshaHealthcare apps for Nokia X and Nokia Asha
Healthcare apps for Nokia X and Nokia Asha
Microsoft Mobile Developer
 
Push notifications on Nokia X
Push notifications on Nokia XPush notifications on Nokia X
Push notifications on Nokia X
Microsoft Mobile Developer
 
DIY Nokia Asha app usability studies
DIY Nokia Asha app usability studiesDIY Nokia Asha app usability studies
DIY Nokia Asha app usability studies
Microsoft Mobile Developer
 
Lessons learned from Nokia X UI reviews
Lessons learned from Nokia X UI reviewsLessons learned from Nokia X UI reviews
Lessons learned from Nokia X UI reviews
Microsoft Mobile Developer
 
Location based services for Nokia X and Nokia Asha using Geo2tag
Location based services for Nokia X and Nokia Asha using Geo2tagLocation based services for Nokia X and Nokia Asha using Geo2tag
Location based services for Nokia X and Nokia Asha using Geo2tag
Microsoft Mobile Developer
 
HERE Maps for the Nokia X platform
HERE Maps for the Nokia X platformHERE Maps for the Nokia X platform
HERE Maps for the Nokia X platform
Microsoft Mobile Developer
 
Nokia In-App Payment - UX considerations
Nokia In-App Payment - UX considerationsNokia In-App Payment - UX considerations
Nokia In-App Payment - UX considerations
Microsoft Mobile Developer
 
Introduction to Nokia Asha SDK 1.2 (beta)
Introduction to Nokia Asha SDK 1.2 (beta)Introduction to Nokia Asha SDK 1.2 (beta)
Introduction to Nokia Asha SDK 1.2 (beta)
Microsoft Mobile Developer
 
UX considerations when porting to Nokia X
UX considerations when porting to Nokia XUX considerations when porting to Nokia X
UX considerations when porting to Nokia X
Microsoft Mobile Developer
 
Kids' games and educational app design
Kids' games and educational app designKids' games and educational app design
Kids' games and educational app design
Microsoft Mobile Developer
 
Nokia X: opportunities for developers
Nokia X: opportunities for developersNokia X: opportunities for developers
Nokia X: opportunities for developers
Microsoft Mobile Developer
 
Lumia App Labs: Nokia Imaging SDK 1.1
Lumia App Labs: Nokia Imaging SDK 1.1Lumia App Labs: Nokia Imaging SDK 1.1
Lumia App Labs: Nokia Imaging SDK 1.1
Microsoft Mobile Developer
 
Intro to Nokia X software platform and tools
Intro to Nokia X software platform and toolsIntro to Nokia X software platform and tools
Intro to Nokia X software platform and tools
Microsoft Mobile Developer
 
Lumia App Labs: Lessons learned from 50 windows phone 8 design consultations
Lumia App Labs: Lessons learned from 50 windows phone 8 design consultationsLumia App Labs: Lessons learned from 50 windows phone 8 design consultations
Lumia App Labs: Lessons learned from 50 windows phone 8 design consultations
Microsoft Mobile Developer
 
Windows Phone 8 speech: parliamo con la nostra app
Windows Phone 8 speech: parliamo con la nostra appWindows Phone 8 speech: parliamo con la nostra app
Windows Phone 8 speech: parliamo con la nostra app
Microsoft Mobile Developer
 
La pubblicazione di un'applicazione sullo store
La pubblicazione di un'applicazione sullo storeLa pubblicazione di un'applicazione sullo store
La pubblicazione di un'applicazione sullo store
Microsoft Mobile Developer
 
Il pattern mvvm come strutturare al meglio il vostro progetto
Il pattern mvvm come strutturare al meglio il vostro progettoIl pattern mvvm come strutturare al meglio il vostro progetto
Il pattern mvvm come strutturare al meglio il vostro progetto
Microsoft Mobile Developer
 

More from Microsoft Mobile Developer (20)

Intro to Nokia X software platform 2.0 and tools
Intro to Nokia X software platform 2.0 and toolsIntro to Nokia X software platform 2.0 and tools
Intro to Nokia X software platform 2.0 and tools
 
Lumia App Labs: Lumia SensorCore SDK beta
Lumia App Labs: Lumia SensorCore SDK betaLumia App Labs: Lumia SensorCore SDK beta
Lumia App Labs: Lumia SensorCore SDK beta
 
Nokia Asha from idea to app - Imaging
Nokia Asha from idea to app - ImagingNokia Asha from idea to app - Imaging
Nokia Asha from idea to app - Imaging
 
Healthcare apps for Nokia X and Nokia Asha
Healthcare apps for Nokia X and Nokia AshaHealthcare apps for Nokia X and Nokia Asha
Healthcare apps for Nokia X and Nokia Asha
 
Push notifications on Nokia X
Push notifications on Nokia XPush notifications on Nokia X
Push notifications on Nokia X
 
DIY Nokia Asha app usability studies
DIY Nokia Asha app usability studiesDIY Nokia Asha app usability studies
DIY Nokia Asha app usability studies
 
Lessons learned from Nokia X UI reviews
Lessons learned from Nokia X UI reviewsLessons learned from Nokia X UI reviews
Lessons learned from Nokia X UI reviews
 
Location based services for Nokia X and Nokia Asha using Geo2tag
Location based services for Nokia X and Nokia Asha using Geo2tagLocation based services for Nokia X and Nokia Asha using Geo2tag
Location based services for Nokia X and Nokia Asha using Geo2tag
 
HERE Maps for the Nokia X platform
HERE Maps for the Nokia X platformHERE Maps for the Nokia X platform
HERE Maps for the Nokia X platform
 
Nokia In-App Payment - UX considerations
Nokia In-App Payment - UX considerationsNokia In-App Payment - UX considerations
Nokia In-App Payment - UX considerations
 
Introduction to Nokia Asha SDK 1.2 (beta)
Introduction to Nokia Asha SDK 1.2 (beta)Introduction to Nokia Asha SDK 1.2 (beta)
Introduction to Nokia Asha SDK 1.2 (beta)
 
UX considerations when porting to Nokia X
UX considerations when porting to Nokia XUX considerations when porting to Nokia X
UX considerations when porting to Nokia X
 
Kids' games and educational app design
Kids' games and educational app designKids' games and educational app design
Kids' games and educational app design
 
Nokia X: opportunities for developers
Nokia X: opportunities for developersNokia X: opportunities for developers
Nokia X: opportunities for developers
 
Lumia App Labs: Nokia Imaging SDK 1.1
Lumia App Labs: Nokia Imaging SDK 1.1Lumia App Labs: Nokia Imaging SDK 1.1
Lumia App Labs: Nokia Imaging SDK 1.1
 
Intro to Nokia X software platform and tools
Intro to Nokia X software platform and toolsIntro to Nokia X software platform and tools
Intro to Nokia X software platform and tools
 
Lumia App Labs: Lessons learned from 50 windows phone 8 design consultations
Lumia App Labs: Lessons learned from 50 windows phone 8 design consultationsLumia App Labs: Lessons learned from 50 windows phone 8 design consultations
Lumia App Labs: Lessons learned from 50 windows phone 8 design consultations
 
Windows Phone 8 speech: parliamo con la nostra app
Windows Phone 8 speech: parliamo con la nostra appWindows Phone 8 speech: parliamo con la nostra app
Windows Phone 8 speech: parliamo con la nostra app
 
La pubblicazione di un'applicazione sullo store
La pubblicazione di un'applicazione sullo storeLa pubblicazione di un'applicazione sullo store
La pubblicazione di un'applicazione sullo store
 
Il pattern mvvm come strutturare al meglio il vostro progetto
Il pattern mvvm come strutturare al meglio il vostro progettoIl pattern mvvm come strutturare al meglio il vostro progetto
Il pattern mvvm come strutturare al meglio il vostro progetto
 

Recently uploaded

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 

Recently uploaded (20)

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 

Developing games for Series 40 full-touch UI

  • 1. Series 40 Developer Training Getting Started with Game Development on Nokia Series 40 Full Touch Asha Phones Michael Samarin, Ph.D Director, Developer Training and Evangelism Futurice +358 40 518 18 09 michael.samarin@futurice.com @MichaelSamarin
  • 2. Today’s topics » This presentation is summary and compressed extracts relevant to game development from previous webinars: › Overview of full touch Asha Devices › Overview of graphical APIs for 2D and 3D Game development Mobile Java › User input in full touch devices › Useful in games performance tips on Series 40
  • 3. New Series 40 Full Touch Platform Asha 305 Asha 306 Asha 311 Retail 70 – 120 $
  • 4. Asha 305, 306 Asha 308, 309 Asha 311 Jar Size 2 Mb 2 Mb 2 Mb Java Heap 2 Mb 2 Mb 4 Mb CPU -- -- 1 GHz Resistive Capacitive Capacitive Screen Multipoint-Touch Multipoint-Touch Multipoint-Touch
  • 5. Series 40 Graphics APIs » 2D Game Development › Game API, part of the MIDP 2.0 standard, java package: javax.microedition.lcdui.game › http://www.developer.nokia.com/Resources/Library/Java/#!deve lopers-guides/ui-and-graphics/game-api.html » 3D Game Development › Mobile 3D Graphics API, optional JSR-184 also known as M3G › http://www.developer.nokia.com/Resources/Library/Java/#!deve lopers-guides/ui-and-graphics/mobile-3d-graphics.html
  • 6. › Game API Package (MIDP) › javax.microedition.lcdui.game › GameCanvas › Layer › LayerManager › Sprite › TiledLayer
  • 7. › GameCanvas › Double buffered › Convenient for minimizing code of game loop › Methods for querying status of keys
  • 8. › GameCanvas public class MyCanvas extends GameCanvas implements Runnable { public void run() { Graphics g = getGraphics(); while(true) { // update the game state int k = getKeyStates(); // respond to key events flushGraphics(); } } }
  • 10. › Graphical Assets – Sprite Star
  • 11. › Graphical Assets – Sprite Lightning
  • 12. › Layer › Abstract class, any visual game element › LayerManager › Combines layers together, provides viewport
  • 13. › Sprite › Animated game object › TiledLayer › Game areas, backgrounds
  • 14. › Sprite › Animated element of the game (character) › Define Sequence, Delay › Flip, Rotate › Define Reference Point › Detect Collisions
  • 15. › TiledLayer › Defines game backgrounds › Can be animated › Doesn’t have Sprite methods
  • 16. › Object-Oriented 3D › Scene Graph based › Optional MIDP JSR Mobile 3D Graphics API › Very compact API JSR-184 or M3G › Very fast development › Optimized for small memory and budget CPU › Excellent implementation on Series 40
  • 17. Lightweight API, only 30 classes AnimationController IndexBuffer RayIntersection AnimationTrack KeyframeSequence SkinnedMesh Appearance Light Sprite3D Background Loader Texture2D Camera Material Transform CompositingMode Mesh Transformable Fog MorphingMesh TriangleStripArray Graphics3D Node VertexArray Group Object3D VertexBuffer Image2D PolygonMode World
  • 18. › Immediate mode › Similar to OpenGL ideology › Retained mode M3G Modes › Scene Graph based › Entire Scene Graph can be restored from file › Well defined M3G format › Can be freely mixed
  • 19. Scene Graph Background Mesh Group Morphing Mesh World Skinned Mesh Sprite 3D Group Sprite 3D User Object Group Camera Light
  • 20. › World › Background › Morphing and Skinned Mesh Most Interesting › Animated Geometry Objects Scene Graph › Mesh Elements › 3D Geometry of Visible Object › Sprite 3D › 2D image in 3D space
  • 21. public class Canvas3D extends Canvas implements Runnable { public Canvas3D(){ } public void paint(Graphics g) { } public void run() { } }
  • 22. public class Canvas3D extends Canvas implements Runnable { private Thread thread; public Canvas3D(){ private long startTime; } private Graphics3D graphics3D; public void paint(Graphics g) { private World world; } private Camera camera; public void run() { private boolean running = false; } }
  • 23. setFullScreenMode(true); thread = new Thread(this); public class Canvas3D extends Canvas startTime = System.currentTimeMillis() implements Runnable { graphics3D = Graphics3D.getInstance(); public Canvas3D(){ world = new World(); } camera = new Camera(); public void paint(Graphics g) { float aspect = (float) getWidth() / (float) getHeight(); } camera.setPerspective(30.0f, aspect, 1.0f, 1000.0f); public void run() { world.addChild(camera); } world.setActiveCamera(camera); } running = true; thread.start();
  • 24. public class Canvas3D extends Canvas implements Runnable { graphics3D.bindTarget(g); public Canvas3D(){ world.animate( } (int)(System.currentTimeMillis() - startTime)); public void paint(Graphics g) { graphics3D.render(world); } graphics3D.releaseTarget(); public void run() { } }
  • 25. public class Canvas3D extends Canvas implements Runnable { public Canvas3D(){ while (running){ } repaint(); public void paint(Graphics g) { Thread.sleep(20); } } public void run() { } }
  • 26. › User input in full touch Asha devices › Game keys simulation › Touch events › Multipoint-touch › Gestures › Sensors
  • 27. Game keys simulation » No touch handling in Canvas? › Drag gestures automatically trigger simulated key events › Up, Down, Left, Right
  • 28. › Tap: touch + release › Long Press (& repeated): touch + hold Touch › Drag: touch + drag › Drop: touch + drag + touch down Gestures (“stop”) + release › Flick: touch + drag + release while dragging › Pinch (new!): 2x touch + 2x drag + 2x touch down (“stop”) + 2x release
  • 29. Using Gestures › Register as gesture listener public class MainCanvas extends Canvas implements GestureListener { private int curPinchDistance = -1; public MainCanvas() { // Set this as container (gesture source) and listener GestureRegistrationManager.setListener(this, this); // Register for pinch events in the whole canvas area gestureZone = new GestureInteractiveZone(GestureInteractiveZone.GESTURE_PINCH); GestureRegistrationManager.register(this, gestureZone); } › Zone: reacts to 1+ specified gestures › Whole screen or rectangular area › Overlap possible › Received events → GestureListener
  • 30. Using Gestures › Handling gestures public void gestureAction(Object container, GestureInteractiveZone gestureInteractiveZone, GestureEvent gestureEvent) { int eventType = gestureEvent.getType(); switch (eventType) { case GestureInteractiveZone.GESTURE_PINCH: // Pinch detected curPinchDistance = gestureEvent.getPinchDistanceCurrent(); break; case GestureInteractiveZone.GESTURE_RECOGNITION_START: /* ... */ break; case GestureInteractiveZone.GESTURE_RECOGNITION_END: /* ... */ break; } } › Executed in UI thread › Lengthy operations (scaling image, etc.) → own thread!
  • 31. › Single touch › Canvas.pointerPressed() part of MIDP › Only tracks 1st touch point Pointer events › Multipoint Touch and › Tracks multiple touch points Multipoint- Touch › But: use Gesture API if only interested in pinch › Each associated with unique ID, x, y and state › Call-back for touch changes, but status available any time
  • 32. Using Multipoint-Touch › Number of touch points 2 on Nokia 305 / 306 MultipointTouch mpt = MultipointTouch.getInstance(); 5 on Nokia 311 int numTouchPoints = MultipointTouch.getMaxPointers(); › Limited accuracy of simultaneous touch points on a resistive screen (Nokia 305) → no on-screen joystick & shoot button › Register: touch point listener public class MainCanvas extends Canvas implements MultipointTouchListener { public MainCanvas() { // ... mpt.addMultipointTouchListener(this); }
  • 33. Using Multipoint-Touch › Handling touch events public void pointersChanged(int[] pointerIds) { for(int i=0; i<pointerIds.length; i++) { // Loop through the changed touch points { int pointerId = pointerIds[i]; // Get the touch point ID int state = MultipointTouch.getState(pointerId); // Get the touch point state // Get the touch point x and y coordinates int x = MultipointTouch.getX(pointerId); int y = MultipointTouch.getY(pointerId); // Handle the UI update based on the touch point state, ID and coordinates switch(state) { case MultipointTouch.POINTER_PRESSED: // A new finger was pressed against the screen drawTouch(pointerId, x, y); break; case MultipointTouch.POINTER_DRAGGED: // A pressed finger was dragged over the screen drawTouch(pointerId, x, y); break; case MultipointTouch.POINTER_RELEASED: // A pressed finger was lifted from the screen break; } } }
  • 34. › JSR 256 Sensor API › Optional Generic API: designed for battery, network status, also for temperature, blood pressure, etc. Sensors › Usefull in Games › Acceleration: –2g .. +2g, x / y / z axis › Double Tap: 1 .. 63, phone sides › Orientation: 0 .. 6, phone orientation
  • 35. › Synchronous › Poll sensor › Example: accelerometer in game loop Sensors Modes › Asynchronous › DataListener callbacks › Example: phone charger plugged in
  • 36. Using Multipoint-Touch › Establish sensor connection // Find all acceleration sensors, the contextType is left undefined SensorInfo[] sensorInfos = SensorManager.findSensors("acceleration", null); // Find an acceleration sensor that returns double values for (int i = 0; i < sensorInfos.length; i++) { if (sensorInfos[i].getChannelInfos()[0].getDataType() == ChannelInfo.TYPE_DOUBLE) { accSensor = (SensorConnection) Connector.open(sensorInfos[i].getUrl()); } } › Check data in game loop // Use 1 as a buffer size to get exactly 1 value for each axis Data[] data = accSensor.getData(1); speedX = -data[0].getDoubleValues()[0]; // data[0] => x-axis speedY = data[1].getDoubleValues()[0]; // data[1] => y-axis
  • 37. Hash Acceleration » Some iterative algorithms are slow. Proper usage of collections types of data structures can increase performance. » Vector.contains() is very slow, but Hashtable.containsKey() is very fast. Reconsider your algorithms to use Hashtables. » Usage can be found in very surprising places. For example, Font.stringWidth() is slow, but necessary for drawing multiline text on Canvas. Creating a Hashtable with the width in each character you have used in the Font can transform this into a fast operation and increase Canvas.paint() speed.
  • 38. Synchronized vs. Volatile Variables » When a variable or Object needs to be accessed from more than one Thread. » Marking a variable as volatile is the least restrictive approach and can have very high performance because no Thread is blocked. » Only one Thread may enter the synchronized sections at any one time. » Consider atomic operations on two variables. For example, when updating firstName and lastName from “John Smith” to “Jane Marceau”, do so within a synchronized block to avoid briefly exposing the transitional state “Jane Smith” to other threads.
  • 39. Constants » We can give the compiler and Proguard more opportunities to optimize the code at the compile step, and this will also give the ARM processor opportunities for handling these variables with more efficient byte codes. private static int loopCount = 10; private static long startTime = System.currentTimeMillis(); private static boolean enableImages = true; Should be private static final int LOOP_COUNT = 10; private static final long START_TIME = System.currentTimeMillis(); private static final boolean ENABLE_IMAGES = true;
  • 40. Primitives » Use int instead of short, byte or long. for (int i = 0; i < 3000000; i++) { short/int/long a = 123; short/int/long b = -44; short/int/long c = 12; a += c; b += a; c *= b; } Average times spent in loops on Nokia Asha 305 (obfuscated): int: 710 (580) ms short: 900 (850) ms 50% slower long: 1450 (1150) ms 100% slower
  • 41. Final in methods for (int i = 0; i < 1000000; i++) { a = finalMethod(1, 2, 3); } for (int i = 0; i < 1000000; i++) { a = nonFinalMethod(1, 2, 3); } public final int finalMethod(final int a, final int b, final int c) { final float x = 1.23f, y = 0.05f; final float z = x * y; final int d = a + b + c; return d; } public int nonFinalMethod(int a, int b, int c) { float x = 1.23f, y = 0.05f; float z = x * y; int d = a + b + c; return d; }
  • 42. Final in methods Average times on a Nokia Asha 305: finalMethod: 650 ms nonFinalMethod: 940 ms 45% slower In this case, the time difference comes from final keyword before x and y. It is logical because then z value can be precalculated. The final keywords with parameters a, b, c let us not precalculate d or anything. And because we don’t use z, it being final does not help us
  • 43. Static » Generally static methods and variables should be faster. Oddly, with some combinations of ARM and JVM, instance accesses are slightly faster. for (int i = 0; i < 1000000; i++) { staticMethod(); Average times spent in loops } on Nokia Asha 305 for (int i = 0; i < 1000000; i++) { nonStaticMethod(); (obfuscated): } private static void staticMethod() { nonStaticMethod: 570 ms b++; // static variable } staticMethod: 680 ms 20% private void nonStaticMethod() { slower a++; // instance variable }
  • 44. String Concatenation If you are going to concatenate a large number of small Strings, use: StringBuffer.append() instead of the String += operator. String is much slower because every time you concatenate a string to another with += operator, a new StringBuffer is created under the hood. Depending on the number of concatenations, a single explicit StringBuffer can be many times faster than multiple implicit StringBuffers created by String addition.
  • 45. Addition vs. Multiplication vs. Division for (int i = 0; i < 500000; i++) { a = 1.23f; b = 1.45f; c = 0.004523f; c += a; a = b + c; } for (int i = 0; i < 500000; i++) { Average times spent in loops a = 1.23f; b = 1.45f; on Nokia Asha 305: c = 0.004523f; c *= a; Multiplying: 330 ms a = b * c; } Addition: 360 ms 9% slower for (int i = 0; i < 500000; i++) { a = 1.23f; Division: 560 ms 70% slower b = 1.45f; c = 0.004523f; c /= a; a = b / c; }
  • 46. Switch vs. If The switch statement in C is implemented as a direct jump which is extremely fast. In Java on Nokia Series 40 phones, switches are implemented at the bytecode level as a series of if statements. Therefore in many cases a switch statement is less efficient than a manually created series of if..else statements in which the first positive case is selected as the one which occurs more frequently. If you prefer to use switch statements for code clarity, then arrange them so that the most frequent cases appear first.
  • 47. Live Demo Session » If you are watching these slides on SlideShare, next part is live coding demonstration with Nokia SDK 2.0 for Java and NetBeans. Full recording of the live session can be found at Nokia Developer website: » http://www.developer.nokia.com/Resources/Multimedia/Webinars.xhtml
  • 48. › Andreas Jakl, Nokia Special thanks