Im creating a back-gammon game and my problem is that I would like to move a piece on the board.
I can draw a piece somewhere else than the original position but how do I delete the old drawing at the old position ????
Ive looked at the translate function but it seems to me that this function translate the origon for the entire graphics content - that the hole board.
Likewise Ive read about a function called "repaint" but my compiler dosnt support this function - is this general ???
repaint() is a call to the paint() method of a Canvas class. So it is not called within the paint method, but rather outside it,
ie. A player makes a move, and you update the positions of the pieces and call repaint() which will in turn call paint().
Consider using sprites or TiledLayers. You can very easily move stuff around using move() or setPosition().
I dont know must about TileLayers but managed to get the repaint() to draw a new figure but I cant delete the old figure.
The thing is I want to move a cursor and Ive implemented a pressedkey and a movecorsur. It moved the the cursor but the old cursor remains........
Likewise ive looked at GameCanvas but how do i parse args i the GameCanvas const
//2-D koord til kursoren
private Command BACK = new Command("Back",Command.BACK,0);
private Command Roll = new Command("Roll",Command.OK,1);
private Display display;
private Displayable currentDisplayable;
private static final int WHITE = 0x00FFFFFF;
private static final int RED = 0x00FF0000;
public Board(Game the_game)
// There must be a call to super because this is the Canvas.class no arg constructor
// This lines parses the instance of Game to the var the_game
// The instance of Game, instance_Game, is parsed to Board() - no arg constr - in Game.startApp()
//die1= new Die(6);
//die2= new Die(6);
gamePlay = new GamePlay();
When you rely solely on the graphics paint without the use of layers, there is no way to erase whatever is underneath because it is all considered as one big layer. You will either have to paint over the old position before painting the piece's new position, or paint the entire board again.
Though that will work, many games use layers. Sprite and TiledLayer are layer classes, meaning you will not have to repaint the entire area over. (ie. one layer for your board and another for your pieces) Both have animation capabilities.
If you use Sprites for your pieces, you can use methods move() or setPostion() to move them without having to bother about where they last were.
TiledLayers can also be moved around with the methods above. TiledLayers is one way to minimize code size. Say for example a checkers board, you only load one image of a black tile and a red tile into your game and use a tiled layer to paint your entire board using the two images.
If you want to find out more, check out the link i gave you in previous post, or do a search.
ps: do use the [code] tags next time you include code. Makes reading easier.