[JAVA] Threads vs Timers

I havn’t used a timer before :-\ but I was told to use them instead of multithreading. What I’m trying to do is get this enemy to stop for a few seconds and then continue his moving path. Right now he just moves side to side non-stop. It’s somewhat like enemies on Mario.

Explain how to use a timer for such a situation and if I should learn to multithread instead. ???

A Timer is used for just what it sounds like: Scheduling events to occur at a set time.

I’m not going to tell you how to use one because that’s what the Official Java Tutorials are for.

Ok, but will you at least say if I should use timer over multithreading?

No, because I can’t read your mind. I don’t know exactly what you are trying to do, and I’m not sure you do either. That’s why you read the tutorial, so then you can say: “Yeah, that’s what I need to use here.”
It’s also why you (eventually) establish a working knowledge of (nearly) all the basic language concepts and functions, because then you don’t even think about what it is you need to solve a problem, you just know, and you do it.

Chances are, in a year or two when you are in this same situation again, you will know exactly what the issue is, and you will know what the solution is to that given problem. That’s programming.

That has happened before except in a different situation. Thanks for saying that, and I figured it out anyway.

Guess you mean something like this?

private void movementPattern3() {
		if (movementPatternLoopCounter < 4) {
			y = y + 4;
		}
		if (movementPatternLoopCounter > 3 && movementPatternLoopCounter < 7) {
			y = y - 1;
		}
		if (movementPatternLoopCounter > 6 && movementPatternLoopCounter < 16) {
			y = y + 1;
		}
		if (movementPatternLoopCounter > 16) {
			y = y + 3;
		}

		if (movementPatternLoopCounter < 32) {
			movementPatternLoopCounter += 1;
		} else {
			movementPatternLoopCounter = 0;
		}
	}

This is just an example from a movementpattern test from my game.
I added a variable movementPatternLoopCounter that i increments +1 every Enemy#update() and gets reset when it’s value reaches 32 which basically functions as a timer.
Now you can code your enemy to have different movement values (or dont move at all) at certain timer values.
You can make your movementpatterns as complex as u like.

Hope this will help u a bit.

You don’t want to do timings with by spawning more threads. Either you hack together something yourself (e.g: http://www.java-gaming.org/topics/would-there-be-any-thread-sleep-problems/28774/msg/262512/view.html#msg262512) by figuring out how much time/how many game loops have passed or you might be interested in some kind of Tweening engine (found this for Java: http://www.aurelienribon.com/universal-tween-engine/gwt/demo.html)

I figured everything out don’t worry. I figured out multi threading and now I’m trying to add more levels. ;D

By figuring out I hope you mean that you figured out that you shouldn’t use them.

We have told him several times, I have specifically told him several times.

Nothing gets through.