Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

How do I make 4 frames repeat themselves in java?

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • 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: 70625
288
  • Mark post as helpful
  • send pies
  • 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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic