The people will be special tile objects that will have their own animation sequences so they look like they're waddling, sleeping, or doing something in their area.

Should I just paint them all to the screen with everything else and loop their animations and call "repaint()" all of the time, or should I create a label or panel object the size of the tile and have that panel object run it's own paint() method?

Why not store npcs in an array. This would allow them to move as well. Then have some sort of cell system where the loop determines what picture is going to be painted next.

I'm afraid that with your current system its not possible to keep the design simple and use only one thread for doing this. I see changing the behaviour of the messages as easier task than trying to figure out workaround or use two threads.

If you want animation, there has to be a rendering loop. If you want rendering loop there must manager which decides what is drawn. Perhaps you should make the messages as objects which will be displayed for x number of frames. This shouldn't be too hard to implement and in my opinion the best sollution.

In update cords, you move the objects however you want like for example in asteroids or make the player walk in rpg. In updateFrame, the loop decides what frame is painted next.

public updateFrame(int i){

npc.setPicture(pic);

}

Now this is very simple example and not very good for doing big animations since handling every single animation by your self is kind of stupid. With loops and simple anim design from Black Art of Java Game Programming(the sprite structure) its easy to handle even quite big scale animations where more than 10 objects must be animated.

I think you can get the source on the internet. If you need it, please ask me.

I'm quite sure you have to make some modification to the above code, and its not very practical to use the sleep method. At shared code there is the Timer Hack or you could use JNI system timer.

What you need is sleep based timer-hack. It makes you life tons and metric tons easier.

I don't even think that you need to extend the thread in this situation. In your approach you start moving mountains if the sollution doesn't come close to you, such as figuring a work around by extendin thread. This could be accomplished with much less work and brain power, but of course if you are the man for moving mountains, then man's got to do what man's go to do.

In your approach, the mountain is very hard to change. Thats why you need to work different way to do this.

The best thing for you would be setting FPS. All programs with animation have FPS and I can't think of exceptations, except for animated gifs. (HAR HAR I MAKES TEH FUNNAY)

Now, once you have set fps, let's say 60 or 75 would be great since about then the fps is high enough to be unnoticable. You must understand that refresh rate is the same as FPS, but done by your monitor. Computer on the other hand has capability to achieve much greater speeds than your monitor.

Although it might sound useless, it is not, since more objects you add to screen, the more it takes from the computer to do whatever required to keep them in animation.*****************Here is the simple part. Just set the thread running with the FPS, which is frames per second divided by 1000, since we are using milliseconds.

Now make that as the general speed of the loop. Now you have window/applet which screen content updates every fps/1000 millisecond. Amazing, isn't it. Now you want to have something to animate. This even easier. Just make method which decides what to draw, and when.

Now comes the fun part: If you want things to animatie different speeds and want to see actually see the animation you have to set how many loops each picture is visible.

If you don't set the delay for each picture to stay on screen, you will see bunch of pictures just flashing. This is not what you want. It makes you dizzy, you want animation, right?

Now you just set the delay, not hard and then decide how many loops each picture stays. You can do this by time too if you want the are afraid of high end systems going too fast, but if you have set cap FPS it won't go too hard.

I have seen many different implementations, but time is harder, and generally better sollution.

Each sprite has animationtime attribute, which is the number of renderloops it stays on screen or switches to next frame. When its at next frame again it takes certain amount of loops untill it switches again to next one.

I'm sorry for my primitive grasp of english language, but if you have more questions, I will answer.

What I did this morning was extend the Thread class and let that determine how often it renders the next image in a sequence of images to produce the effect of animation.

I pass the thread a timeslice (milliseconds), the main program, the main program's graphics object, and a string name.

I calculate what should be shown and when and if it should stop running after a specific time. It manipulates the graphics object and passes it back to the main program's paint method, which then paints everything.

This works so far... it isn't very robust, so I need to modify it a bit, but it sounds close to what you're talking about... unless I'm totally off

/***************************************************************** method: run() purpose: Handles the determination of the next image, sets up the new graphics object properties and passes it back to the paint() method in the main program. *****************************************************************/publicvoidrun() {// If the thread is in running mode, then calculate// the next image to be displayed by the programwhile(running) {// First imageif (mode == MODE_ON) {background = Toolkit.getDefaultToolkit().getImage(firstimage);//System.out.println("Printing player_old.gif");mode = MODE_OFF; }// Second imageelse {background = Toolkit.getDefaultToolkit().getImage(secondimage);//System.out.println("Printing player2.gif");mode = MODE_ON; }

// Repaint the scene to clear what was there lastmainprog.repaint();

// Draw the new imageg.drawImage(background, xpos, ypos, mainprog);

// Put the thread to sleep for the specified amount of time// in the sleep duration variabletry{Thread.sleep(sleeptime); }catch (InterruptedExceptione) {} }

// If we are no longer running, we want to repaint the sceneif (!running) {mainprog.repaint(); } }

Flickering is likely caused because you are not using swing rendering..

Quote

mainprog.repaint();

// Draw the new image g.drawImage(background, xpos, ypos, mainprog);

SO you are triggering drawing in the GUI thread AND painting in this other thread... you are asking for trouble. Keep all the painting in one thread. If you can't then you will at least need to synchronize the painting between the threads somehow.. but that is too complex. You shouldn't need to paint in more than one thread.

Ok, now that I've fixed that little problem... now I have encountered another!

I removed the paint calls from the Thread. So now the flickering has stopped, but if I have another thread for another NPC running, the screen flickers really badly and alternates between the two characters.

I guess what I'm getting at is how would I animate other objects on the screen? Do I keep track of how many "frames" I have drawn and draw certain pieces at certain times, or do I need these separate threads for each one?

A seperate Thread for each NPC is fundamentally not going to work. The fewer threads you have interacting with your rendering, the better. There are a lot of ways to approach this, some have been suggested earlier. If I may, here's one route that may be simpler for you right now.

Once you have as many NPCs working as you need and you feel comfortable, improve the NPC class by syncing it with a global timer and provide methods to set the rate at which the current frame is iterated.

Just my suggestion. (coming from someone who makes extensive use of animated gifs )

Just thought I'd come back to edit this and say THANK YOU to everyone that helped I finally got the idea through my thick skull and I have several little guys on the screen all moving randomly at their own speeds without any flickering

Hi, well I don't think this well help you but more me. Well I want to design a platform game and was woundering where you got the bitmaps and images from for your game......I want to design a game but am not very good at images drawing so just woundering where I can download some.ok thanks

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