Header Sep
Mobile Java 3D Tips, Tricks & Code
 
My Rating Score
Login to rate page

May 2005
Using Sprite3D in JSR-184

[Back]

 

Here we describe how you can use 3D sprites, and take advantage of their special behaviour, in Sony Ericsson mobile phones based on JP 3 (Java Platform 3) and JP 4. Read about Sony Ericsson's Java Platforms here>> 

A Sprite3D is just a 2D image in 3D space. Regardless of the camera angle, or the rotation of the world, the sprite will always be facing the camera.

There are two types of sprites, Unscaled and Scaled:

  • Unscaled
    The rendered size of an unscaled sprite is measured in pixels with the width and height equal to the crop rectangle.
  • Scaled
    The size of a scaled sprite is dependant on the distance to the active camera.

The sprite's special behavior can be seen when using Sprite3D on a real target device based on JP 3 or JP 4. The sprite is not rendered at the same position and as shown by the examples below:


This image is used as the sprite. In this case, each frame is 10 pixels and the image is 100 pixels wide.

 
This is the behavior on JP 3 and JP 4 mobile phones, for example the Sony Ericsson K700. This is the behavior in the emulator and for mobile phones based on JP 5, for example the Sony Ericsson K750 and K600.

Knowing this, developers need to adapt applications to the target devices when using Sprite3D.
 
Also note, when using scaled sprites, the sprite must be scaled up to the same amount as the number of frames in the sprite (this is not needed on the emulator and you should check your target device how this is implemented).
 
Here is an example:
 
CompositingMode cm = new CompositingMode();
cm.setBlending(CompositingMode.ALPHA);
 
Appearance appearance = new Appearance();
appearance.setCompositingMode(cm);

sprite3D = new Sprite3D(false, new Image2D(Image2D.RGBA, texImg), appearance);
sprite3D.scale(10.0f, 1.0f, 1.0f); // if the sprite is built of 10 frames
sprite3D.setCrop(0, 0, 10, 10);
 
To mask out a special color, first specify this color when creating the png image, and then create the Image2D using RGBA also adding the CompositingMode to the appearance.
 
If you do scale a sprite, you will notice that when using the Transform class to move the sprite, the sprite will be translated multiplied by the scaling.
 
sprite3D.scale(6.0f, 1.0f, 1.0f);
sprite3D.translate(6.0f, 0.0f, 0.0f); // same result as postTranslate(1.0f, 0.0f, 0.0f);
 
transform.postTranslate(1.0f, 0.0f, 0.0f)
sprite3D.setTransform(transform);
 
To find out which phones belong to which Java Platform, please refer to MIDP 2.0 Developers' Guidelines>>
 
 

 
 
  
 
 
 
My Rating Score
Login to rate page