Midp2 0 games
Sprite, both of which are subclasses of Layer. The LayerManager class helps you to organize all of these graphical layers. The order in which you append your Layers to your LayerManager determines the order in which they will be painted.
The first one appended is the last one painted. The top layers will cover the lower layers although you can allow parts of the lower layers to show through by creating image files that have transparent regions. Probably the most useful aspect of the LayerManager class is that you can create a graphical painting that is much larger than the screen and then choose which section of it will appear on the screen. Imagine drawing a huge and elaborate drawing and then covering it with a piece of paper that has a small rectangular hole that you can move around.
The whole drawing represents what you can stock into the LayerManager, and the hole is the window showing the part that appears on the screen at any given time. Allowing the possibility of a virtual screen that is much larger than the actual screen is extremely helpful for games on devices with very small screens. It will save you huge amounts of time and effort if for example your game involves a player exploring an elaborate dungeon.
The confusing part is that this means that you have to deal with two separate coordinate systems. So keep in mind that the method LayerManager. I do this by calling the method setViewWindow int x, int y, int width, int height from the paint Graphics g method of my subclass of LayerManager called JumpManager.
JumpCanvas passes this information along to JumpManager by calling the methods setLeft boolean left or jump. If the message is to jump, the JumpManager calls jump on the cowboy Sprite. I'll explain it by going over my subclass of TiledLayer which I have called Grass. This class represents a row of grass in the background which waves back and forth as the game is being played. To make it more interesting, some of the cells in my TiledLayer have animated grasses and others have no tall grasses and hence just consist of a green line representing the ground at the bottom of the cell.
Here's the corresponding image file:. Yet the system is completely logical. In a TiledLayer , the tile index 0 indicates a blank tile i. A Sprite , however, is composed of only one cell, so if you want that cell to be blank, then you can just call setVisible false , meaning that Sprite doesn't need to reserve a special index to indicate a blank tile. This little confusion in the indices should not pose a big problem, but it's something to keep in mind if you can't figure out why your animation appears to be displaying the wrong images.
Aside from this point, the image file is divided into individual frames or tiles in TiledLayer just as in Sprite , explained above. The first step in creating your TiledLayer is to decide how many rows and columns of cells you will need. If you don't want your layer to be rectangular it isn't a problem because any unused cells are by default set to being blank which prevents them from getting in the way of other images. In my example I have only one row, and I calculate the number of columns based on the width of the screen.
Once you've set how many rows and columns you'll be using, you can fill each cell with a tile using the method setCell int col, int row, int tileIndex. The tileIndex argument is as explained in the Sprite section and the warning paragraph above. If you would like some of the cells to be filled with animated images, you need to create an animated tile by calling createAnimatedTile int staticTileIndex , which returns the tile index that has been allotted to your new animated tile.
You can make as many animated tiles as you want, but remember that each animated tile can be used in multiple cells if you want the cells to display the same animation simultaneously. In my case, I create only one animated tile and reuse it because I want all of my animated grass to be waving in sync.
The cells are set in the constructor of Grass below. To advance the animation you don't get built-in frame-sequence functionality as in Sprite , so you have to set the frames with the method setAnimatedTile int animatedTileIndex, int staticTileIndex. This sets the current frame of the given animated tile. Thus all of the cells that have been set to contain the animated tile corresponding to animatedTileIndex will change to the image given by the argument staticTileIndex.
Therefore each time I add one of these two commands to the screen, I remove the other two. Of course it is certainly possible to add several custom commands at a time to the MIDlet if your game needs them. For example the default emulator creates a menu of commands when there are more commands than available buttons. Using static field codes such as Command. BACK or Command. HELP will ensure that standard types of commands will be mapped to their usual buttons on the device. The implementation of the priority argument may vary some from device to device, but in general those commands that have higher priority indicated by a lower priority value will be more easily accessible to the user.
0コメント