my dog learned polymorphism
The moose likes Java Micro Edition and the fly likes sprite question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "sprite question" Watch "sprite question" New topic

sprite question

pingkan paula
Ranch Hand

Joined: Sep 03, 2004
Posts: 117
Hi, i'm new to sprite and have been experiencing game development using game canvas. However, i've a basic question about sprite, do i need to provide 3 images in res directory suppose i want to display the image's sprite in 3 frames? because i've tried to use sprite displaying 3 frames using only one image and it throws an exceptions
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Taken from Jonathan Knudsen's book from Apress publishing.

"Interestingly, a Sprite cannot be created from seperate frame images; the frames must be packed into a single source image.

So the sprite must be in one file.

The total number of frames contained in the Sprite is returned from getRawFrameCount()

Looking further in the book he has a Sprite that has 4 frames, each frame is 48x48, so the single file itself is 192x48 pixels.

He has an int array to define the frame sequence for this guy running. He then creates an Image object from the .png file using Image.createImage() passing the filename. Then he creates a Sprite object passing in the Image and then the size of a frame, so new Sprite(image, 48, 48);
then he takes the Sprite object and calls setFrameSequence() passing in the int array.

Does that help. Also can you post the Exception and stack trace?


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: sprite question
jQuery in Action, 3rd edition