• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do I make 4 frames repeat themselves in java?

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to add 4 frames to run in a cycle so it seems as if my character is running on the spot but I don't know how to do this with more than 2 frames.

here is my code, what should I adjust to it so it works and that its bug free?

 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to our GUIs forum.

You can have an array of images. Try a Timer to make the frames appear in turn. You can have an index and use the remainder operator to bring it back to the beginning of the array.
Don't make the timer fire more frequently than about once per 20ms or once per 25ms. Your four‑element array would move far too fast at that speed. You can try about once every 100ms, but I think your animation will be horribly jerky. Is there any way you can interpose more frames and make the motion smoother?
What does Bitmap mean?
 
reply
    Bookmark Topic Watch Topic
  • New Topic