Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 10 Aug 2010
Offline Last Active Oct 20 2012 08:43 AM

Topics I've Started

Java - Basic Animation/Threading Woes

17 October 2012 - 12:51 PM


Been stuck on this for a few days. Would really appreciate a little help.

I'm trying to learn the basics of animating movement on a 2D Tileset. Characters can move in 8 directions on the board. If I click several tiles distant, the intermediate moves are not shown - the character just moves instantly to the end point

I used println to feed back information. It seems the thread is being created, but that it is not calling the paint method.

This method gets the tiles the character must pass through to get to his destination, moves the character, starts a thread to call repaint, then sleeps to allow the animation (which doesn't happen) to occur.
[source lang="java"]public void moveActor(int destinationIn) { LinkedList <Integer> actorMoves = calculateMoves(destinationIn); // get the int values representing the co-ordinates the actor must move through to get to destination // Iterates through the actorMoves for(int i = 0 ; i < actorMoves.size() ; i++) { System.out.println("MoveActor: Move " + i + ": " + actorMoves.get(i)); // Resets the actor Id of the current position to -1 to denote empty int currentPos = actorList.get(selectedActorId).getActorPosition(); board.setActorIdInTile(currentPos, -1); // Sets the actor position in the actor object and on board actorList.get(selectedActorId).setActorPosition(actorMoves.get(i)); board.setActorIdInTile(actorMoves.get(i), selectedActorId); // Starts a thread to update the board new Thread() { public void run() { System.out.println("Paint thread started"); repaint(); } }.start(); // Puts main thread to sleep try { System.out.println("Main thread sleeping"); Thread.sleep(500); } catch (InterruptedException ex) { Logger.getLogger(ImageLoader6.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Main thread active"); } }[/source]
This is the paint method. First it draws the tiles, then the characters on top.
[source lang="java"]// Paints the map public void paint(Graphics g) { System.out.println("Paint Method started"); for(int i = 0 ; i < 100 ; i++) { String type = board.getTileType(i); int x = (i % 10) * 64; int y = (i /10) * 64; // Checks the tile object to determine whether it is grass or sand if(type.equalsIgnoreCase("grass")) { g.drawImage(grass, x, y, null); } else { g.drawImage(sand, x, y, null); } } // Works through the list of actors, draws them for(int j = 0 ; j < actorList.size() ; j++) { // Get Actor's position & convert to X,Y coordinates int actorPosition = actorList.get(j).getActorPosition(); int actorX = (actorPosition % 10) * tileSize; int actorY = (actorPosition / 10) * tileSize; g.drawImage(actorList.get(j).getActorImage(), actorX, actorY, null); } try { Thread.sleep(20); } catch (InterruptedException ex) { Logger.getLogger(ImageLoader6.class.getName()).log(Level.SEVERE, null, ex); } }// End of paint()[/source]

Here's a sample of the output. It seems the paint method is not being called by the thread.

MoveActor: Move 0: 22
Main thread sleeping
Paint thread started
Main thread active
MoveActor: Move 1: 33
Main thread sleeping
Paint thread started
Main thread active
MoveActor: Move 2: 44
Main thread sleeping
Paint thread started
Main thread active
Paint Method started

If you need me to post the whole program, no problems. Let me know. Any help hugely appreciated!

Java Game Swing or FSEM

17 October 2012 - 11:27 AM


I'm currently prototyping a game in java, which I hope to develop to a proper game. It's 2D, top down, fullscreen, turn-based strategy, with simple animation. Currently I've built it in swing, using Frames and I'm currently working on a panel which the graphics will be drawn to.

My question is, is building a game in swing (with a fullscreen, undecorated panel) a bad idea? Should I be working in fullscreen exlusive mode?

I should add, there is a management aspect to the game, which necessitates a lot of buttons and labels.

Thank you!

Basic Questions on animating tile based games & frameworks/engines

09 October 2012 - 08:18 AM


I've been working on making a simple prototype in java (netbeans) for a game for the last few months. The game is a tile & turn based strategy/RPG in the vein of JA, X-Com, Fallout.

I've built the majority of the game logic - the character system (Stats, skills, perks, levels, inventory), the TB combat system (with melee and ranged), some basic A.I.s , simple GUIs, a system for loading enemies and PCs, and a fair bit of the content: weapons (40 or so), armour, equipment, enemies. The plan was to get all the basics working and then recruit a graphics and sound person to help, when I'm fairly sure I'll be able to finish the game.

The main problem is my lack of knowledge on manipulating images. The current set up for the map (which I strongly suspect is not a good one), is a 16*30 arraylist of buttons with imageIcons. Characters (which are just portraits ATM) can be selected and moved around this grid, and the button Arrays imageIcons are changed appropriately. My main question at this point is: 1) can a simple level of animation be achieved with imageIcons - i.e. walking between tiles/buttons, crouching, firing weapons, melee attacks be easily done, even in straight down 2d? If so, how?

Here are some other thoughts/questions - please feel free to comment on any, or recommend reading.

2) Does anyone know how animation was achieved in the likes of JA, X-Com, Fallout, which all appear to be tile based?

3) I've considered some other ideas like putting a graphical layer on top of the buttons (not sure how), and somehow corresponding the upper graphical layer to what is happening beneath on the button array. Could this be achieved, and how difficult would it be.

4) The other thing I am considering is discarding the button array creating a single map for the level, and putting a set of coordinates on it which characters can move to. Would this be any good?

5) Finally, is there a better engine/framework I could use for the project? Definitely not opposed to moving to something else if it would allow me to handle the graphical end more easily. Any recommendations?

If I haven't provided enough detail, or have been unclear, please feel free to ask. Thanks for your help!

Beginner Advice - 2D, Turn Based, Combat

18 February 2012 - 08:37 AM


I’m looking for some advice on getting started in game development. I have a small amount of programming knowledge (Java) and am working my way through a book on games development in XNA through C#. I have made a few very simple games to date: a word matching game, a tetris style game, and am currently fiddling with a simple version of battleships.

What I’d like to look at next is making a simple turn based, 2D, combat game (just the combat section for now). I have a basic story, and some notes on game logic. I’d like to develop the game with rudimentary graphics which I’ll make myself, and then involve a proper visual artist later if the project looks like it’s worthwhile.

Any general advice, or pitfalls I should be aware of?

More specific questions:
  • Any rules of thumb for deciding on the tile size?
  • If I make a prototype and then get a graphics person who believes the tile size should be changed, how much work will be involved in making the changes?
  • How simple (or difficult) is it to move from 2D to isometric?
  • To what extent do engines like Torque simplify and speed up the development process?
  • Does Torque (or any similarly cheap engines) come with a graphics library I can use?
Any help is greatly appreciated!
Thank you!