Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How paint sprites in MIDP2 ?  (Read 3102 times)
0 Members and 1 Guest are viewing this topic.
Offline DamnGzM

Junior Newbie




Java games rock!


« Posted 2002-12-04 12:33:00 »

Hi, I'm really stuck here and any help is much appreciated! With the recently released MIDP2 I've created a layerManager and appended a sprite to it. But I can't manage to display the sprite. This is the code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
..
Image theImage;
Sprite theSprite;..

void someMethod() {
      try {
               LayerManager lm = new LayerManager();
               theImage = Image.createImage("/images/someImage.png");
               theSprite = new Sprite(theImage, (theImage.getWidth()/2), (theImage.getHeight()/2));
               lm.append( theSprite );               lm.setViewWindow( 0, 0, 96, 100 );
               theSprite.paint (graphicObject);
      } catch (java.io.IOException ex) {
      }
}



In this code-snippet, what should the graphicObject be onto which the sprite is to be painted? Any examples?

I also tried creating a public class "TheSprite" extending Sprite and defining a method paint() in it. But the paint-method of Sprite cannot be overrided and a constructor cannot be resolved.

Please help!
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #1 - Posted 2002-12-04 12:37:44 »

Without having any idea of the whole MIDP topic....

You are sure not to run into the IOException part? I'm sure you are, but I've seen so much in my life...

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline davidaprice

Junior Member





« Reply #2 - Posted 2002-12-04 13:48:39 »

First point: the LayerManager is doing nothing for you in this example: you could remove it. If you plan to use it for something (e.g. appending some more Sprites and/or TiledLayers) then instead of calling theSprite.paint you should call lm.paint - it will call paint on your Sprites and TiledLayers in the right order for you.

You need to use either a Canvas or a GameCanvas as the screen you draw your Sprite on. If you're using a Canvas, the system will call your Canvas's 'paint' method each time it's needed, and will pass in a Graphics object. That's the object you pass to mySprite.paint.  It's only valid for the duration of that call to your Canvas's paint method, so don't go storing it and using it later.

If you're using a GameCanvas, you can just call its method 'getGraphics', and pass the returned object to mySprite.paint. Look at the code example in the JavaDocs for GameCanvas.

Important note: I assume you're just experimenting here, but in your real MIDlet you want to create the Image object in your Canvas/GameCanvas's constructor, not each time you paint.

I'd better confess that I haven't yet had time to play with MIDP 2.0, but I've been using MIDP 1.0 for a couple of years. The notes above come from my reading of the MIDP 2.0 API docs.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DamnGzM

Junior Newbie




Java games rock!


« Reply #3 - Posted 2002-12-04 15:53:50 »

Thank you for your explanation!

Thruth is I've just started using MIDP a few weeks ago. And I'm not much of an experienced java-programmer.

The JavaDocs say "protected GameCanvas(boolean suppressKeyEvents) Creates a new instance of a GameCanvas. A new buffer is also created for the GameCanvas and is initially filled with white pixels."

But I've tried to use a GameCanvas by defining public class MyCanvas extends GameCanvas { ... } and doing MyCanvas myCanvas = new MyCanvas(false); or just by doing GameCanvas myCanvas = new GameCanvas(false); . All of this didn't work, probable reasen is that GameCanvas is an abstract class and cannot be instantiated, or am I wrong here? Then how can I invoke GameCanvas' constructor as told in the JavaDocs?!  Huh

So I figured I can use GameCanvas by importing ...lcdui.game.* in my class MyCanvas which extends Canvas. And then just invoking GameCanvas' methods. Plz correct me if I'm wrong (I'm still new to java).

Unfortunately the game examples that came with the MIDP2 package are written in MIDP1.
More or less, I'm desperately looking for a plain code-sample which reflects the basics of creating a game with MIDP2 (i.e. creating a MIDlet, creating a GameCanvas, LayerManager, Layers and Sprites and displaying the sprites in a viewwindow by the LayerManager). The ones I found don't seem to work, or consist of small code-snippets without keeping track of the bigger picture.

HMM.. as a java-rookie I'm really lost here aint I?  :-/

Offline DamnGzM

Junior Newbie




Java games rock!


« Reply #4 - Posted 2002-12-04 17:35:55 »

Hmm... didn't do my homework well i guess, just discovered that the pushpuzzle example IS actually created with MIDP2 using all of its fancy features. Thnx tho.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (33 views)
2014-09-21 01:30:30

moogie (41 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!