Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Work with sprites in J2ME

John Muchow, Author
John Muchow, a freelance technical writer and consultant, is the author of Core J2ME Technology and MIDP. Visit Core J2ME for additional source code, articles, and developer resources. Send John e-mail for additional information about writing or consulting projects.

Summary:  With the release of the Mobile Information Device Profile (MIDP) version 2.0, J2ME developers can now access a new sprite class. A sprite is a representation of an image in memory. However, a sprite offers inherent capabilities that provide vastly more robust image manipulation beyond that available in a standard image. This tutorial presents the basic principles for working with both animated and nonanimated sprites. Moreover, you'll have the opportunity to create two complete MIDlets (J2ME applications) that demonstrate the inner workings of the sprite class.

Date:  16 Dec 2003
Level:  Introductory PDF:  A4 and Letter (509 KB | 36 pages)Get Adobe® Reader®

Activity:  15859 views
Comments:  

Before you start

About this tutorial

The latest Mobile Information Device Profile (MIDP) 2.0 for J2ME (Java 2 Platform, Micro Edition) added support for sprites -- images with additional attributes and methods to facilitate animation, transformation (rotate, flip and mirror), and collision detection. In this tutorial you'll explore the differences between nonanimated and animated sprites, learn about sprites placement using a reference pixel, and discuss how to detect collisions between sprites.

During the course of this tutorial you'll create two MIDlets (J2ME applications). The first will demonstrate how to create and display an animated sprite, whereas the second will be a simple game that illustrates collision detection in action.

Once you've completed this tutorial, you'll have a base knowledge from which to begin incorporating sprites into your J2ME applications.


Software prerequisites

You'll need two software tools to complete this tutorial:

  • The Java Development Kit (JDK): The JDK provides the Java source code compiler and a utility to create Java Archive (JAR) files. When working with the Wireless Toolkit 2.0 (as you will be here), you'll need to download JDK version 1.4 or greater. Download JDK version 1.4.1.
  • The Wireless Toolkit (WTK): The Sun Microsystems Wireless Toolkit integrated development environment (IDE) creates J2ME MIDlets. The WTK download contains an IDE, as well as the libraries required for creating MIDlets. Download J2ME Wireless Toolkit 2.0.

Install the software

The Java Development Kit (JDK)

Use the JDK documentation to install the JDK. You can choose either the default directory or specify another directory. If you choose to specify a directory, make a note of where you install the JDK. During the installation process for the Wireless Toolkit, the software attempts to locate the Java Virtual Machine (JVM); if it cannot locate the JVM, you are prompted for the JDK installation path.

The Wireless Toolkit (WTK)

This tutorial builds on an earlier developerWorks tutorial "MIDlet Development with the Wireless Toolkit" (see Resources), which explains the basics of creating MIDlets with the toolkit. This tutorial is an excellent starting point if you are new to the Wireless Toolkit.

The Wireless Toolkit is contained within a single executable file. Run this file to begin the installation process. It is recommended that you use the default installation directory. However, if you do not use the default directory, make sure the path you select does not include any spaces.

1 of 7 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Java technology
ArticleID=137099
TutorialTitle=Work with sprites in J2ME
publish-date=12162003
author1-email=
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Special offers