Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Animation Help
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Helldemon80




PostPosted: Thu Dec 24, 2009 1:33 am   Post subject: Animation Help

Hello Everyone


I was having problems with the KeyListener in my program, i am trying to move my character i cannot get the character to move while just holding the key, i can only get it to move if you continuously press the button required.

Is there a way to get the keylistener to work while just holding the character and getting the person to move and not lag.

Here is a zipped program with all the images and the source code for the animation

Please Help
Thanks

I know there are a lot of variables and i should use an array to get the images but i just learned them and plan on implenting arrays into this animation.......also is there an easier way to draw the images without having the type each image in the draw method

BTW Use W, A and D to animate with caps lock...i cant get it to work with lowercase -_-

Also, the delay method depends on the speed on your computer u may haveto edit the delay to get the animation to run smoothly....im trying to find another way to get that to work without my delay method...plz give tips on that too ...thanks



Briens Full Animation Final.rar
 Description:

Download
 Filename:  Briens Full Animation Final.rar
 Filesize:  54.29 KB
 Downloaded:  70 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Barbarrosa




PostPosted: Sat Dec 26, 2009 7:03 am   Post subject: Re: Animation Help

Have you tried changing movement states if the key's state (down or up) changes? If you just repeatedly check whether it's being pressed, the key has a delay before it repeats.

W down: forward
W up: not-forward

S down: back
S up: not-back

etc...

I've come across the same problem before, and this is how I dealt with it.

If you're worrying about whether breaking input altogether while in a moving-state could be a problem, remember: it'll fix itself easily when the player starts inputting again.
Kam




PostPosted: Sat Dec 26, 2009 8:46 am   Post subject: Re: Animation Help

Barbarrosa @ Sat Dec 26, 2009 7:03 am wrote:
Have you tried changing movement states if the key's state (down or up) changes? If you just repeatedly check whether it's being pressed, the key has a delay before it repeats.

W down: forward
W up: not-forward

S down: back
S up: not-back

etc...

I've come across the same problem before, and this is how I dealt with it.

If you're worrying about whether breaking input altogether while in a moving-state could be a problem, remember: it'll fix itself easily when the player starts inputting again.


It's not a issue with his case it. The problem here is within the KeyReleased method.

code:
public void keyReleased (KeyEvent e)
    {
        repaint ();

    }

Your KeyPresssed method seems to work. The KeyReleased method will only work when you released the keyboard key. (Thus, why you are getting the delay) and because the repaint() method is within that method, when you hold on to a key, it seems the character is not moving (BUT IT IS! just that the repaint() method is not being called for your eyes to see it on the screen).

For the games that I made, this is what I did: try putting a thread into your main game loop (which will do everything - including checking conditions, moving character, moving enemy, checking collision, and finally repainting). That removes the need for the for loop to run endlessly doing nothing. This method is not so efficient for different computers (slow computers will need greater time dealing with the delay while faster computers require less time).

Hope this helps.
Barbarrosa




PostPosted: Sun Dec 27, 2009 10:02 am   Post subject: Re: Animation Help

Kam @ Sat Dec 26, 2009 8:46 am wrote:

It's not a issue with his case it. The problem here is within the KeyReleased method.

code:
public void keyReleased (KeyEvent e)
    {
        repaint ();

    }

Your KeyPresssed method seems to work. The KeyReleased method will only work when you released the keyboard key. (Thus, why you are getting the delay) and because the repaint() method is within that method, when you hold on to a key, it seems the character is not moving (BUT IT IS! just that the repaint() method is not being called for your eyes to see it on the screen).


In that case, we've actually got 2 problems.

Yes, I still think the use of individual presses over state changes is a problem.

Kam @ Sat Dec 26, 2009 8:46 am wrote:

For the games that I made, this is what I did: try putting a thread into your main game loop (which will do everything - including checking conditions, moving character, moving enemy, checking collision, and finally repainting). That removes the need for the for loop to run endlessly doing nothing. This method is not so efficient for different computers (slow computers will need greater time dealing with the delay while faster computers require less time).


This would be a likely outcome to implement solution I suggested. I admit, I've gotta be more clear sometimes.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: