Question

I'm developing a game in j2me. I'm using one sprite for 4 set of images and changing the images for the sprite accordingly by using sprite.setImage(). I'm setting images randomly to sprite during run time.

How to know which image is being used by the sprite during run time?

Was it helpful?

Solution

Short version: you cannot and probably shouldn't.

Long version: Two common patterns (I would use them both at once) are:

  • Always use one image for all the sprites (and tiles, and everything else). Then modify sprite by changing it's frame or frame sequence;

  • apply the basic Model / View separation. Don't treat your view (sprite) as a source of knowledge about state of your game, consider it a write-only resource. The state of the game lives in some model class that knows well (perhaps on a more abstracted level) which image was set to which sprite. Such approach will solve more problems, some of which are hard to perceive before they happen (such as the difference between logical and physical location of the sprite in case you have any animation happening upon losing a life, etc).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top