Graphics and Threads

The questions you are asking have little to do with java gaming.
I think you need to learn & understand the Java language before trying to write a game.

Hmm, Abuse is definitely right to a certain extent. It seems like you don’t yet understand programming basics.

When you load an image with ImageIO, you want to do it once so that you’re reading the image from memory rather than your hard drive. Then you need to give the applet access to that stored image so it can be drawn.

well you are correct i do just jump into stuff but thats just me…sorry. however i figured it out. in your animations class you declared the frames array but did not initialize it. after the parameters are passed i initialized frames[] to refs.length and everything works great. im not trying to correct you though cuz i know you said you didnt test it.

ok and i actually have a game related question for you. i want my characters to have two animations. if forward or backwards is pushed the legs should move like they are walking and if the up or down is pushed they should move their arm up or down. whats the best way to implement this? i was thinking maybe an image matrix? increasing one index moves feet and and the other the arms…

Ha, no worries, correct me all you want. I’ll never claim to know the best way to do things. And maybe it’s good you got that error because now you’ll learn to spot them in the future.

As for your question…

There are several ways you could implement that. The simplest way with your current animation method would be to simply allow one Unit (we’ll say your objects that can play Animations are called Unit) to have multiple animations going off at once. Logically, however, you probably don’t just want to have an array of Animation lists, because that’s confusing and makes little sense. Instead, you probably want to create a new object, like UnitElement or something, that contains independent information pertaining to that section of the body. As such, no Unit actually has references to animations; instead their UnitElement(s) do. A UnitElement knows its local position (i.e. the offset from the Unit’s position where it should draw itself, etc.), local rotation, and has its own Animation List.

So for example: (once again not complied, also probably not complete)


public abstract class UnitElement
{
     private Unit parent;
     private Vector2f localPosition;
     private float localRotation;
     private java.util.HashMap<String,Animation> animations;
     private String currentAnimation;

     public UnitElement(Unit daddy, Vector2f pos, float rot, java.util.HashMap<String,Animation> anims)
     {
          parent = daddy;
          localPosition = pos;
          localRotation = rot;
          animations = anims;
          currentAnimation = "Default";
     }

     public void draw(java.awt.Graphics g)
     {
          animations.get(currentAnimation).draw(g, localPosition.x + parent.getX(), localPosition.y + parent.getY());
     }

     public abstract void doLogic();
     /* An abstract method can't have a body. Instead, you make a subclass that inherits
      * the method and overrides it, thereby creating unique functionality. You might want
      * to have classes like LegElement, ArmElement, BodyElement, or whatever that represent
      * different useful functionality. Below is an example of what LegElement's implementation
      * might look like.

          if (KeyIsDown(Key.LEFT))
               currentAnimation = "Left";
          else if (KeyIsDown(Key.RIGHT))
               currentAnimation = "Right";
     */
}

I think that should give you the idea. I made UnitElement abstract because doLogic() doesn’t make sense generically… you’re going to want different types of UnitElements that handle input differently.

You could also just allow a Unit to contain more Unit’s as children, and do the functionality in the same sort of way as above. Basically instead of worrying about local position and whatnot they can just be stored in the same place for easy access, but using global coordinates. I don’t recommend this, but it might be easier to grasp.

thank you and second would you happen to know some good software for creating gif’s or jpegs or png’s or anything like that?

If you can afford it, Adobe Photoshop is far and away the best. If you can’t and aren’t adverse to piracy, you can get it via torrent or something.

If you don’t want to pirate it, you can download a free trial for 30 days.

If all the rest failed, check out GIMP or Graphic Converter.

is there an easy way to, once one key is pressed, tell the computer not to accept any other key presses until the initial key is released?

i am just concerned with the direction keys mainly…i dont want the user to be able to move in two directions at once. i was able to implement this behavior with if statements contingent on four conditions…is there a more simple way to do this?

http://java.sun.com/developer/onlineTraining/Programming/BasicJava1/

Yes. Create a list of buttons that have been pressed.


ArrayList pressed = new ArrayList();

...

when (somethingIsPressed && pressed.size() <= 0)
{
     doKeyboardPressStuff();
     pressed.add(thisButton);
}

...

when (somethingIsReleased)
     pressed.remove(thisButton);

No that’s not valid code. It should give you the general idea.

And as for Orangy Tang’s suggestion, he’s totally right. It is a perfectly acceptable method of learning to dive in, but you’ve got to have some general knowledge of what you’re doing when you do so. So get yourself and book you can look at alongside this programming. Most of the advice I’ve given you is really simple, especially the stuff in this post.

ok thank you that makes sense. and as for the book i do have one. i bought a book on java game programming that has helped alot. if you didnt notice my posting has decreased. although you are right, that book on the basics posted by orangy would be helpful too.