Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

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: 72478
315
  • 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?
 
No matter. Try again. Fail again. Fail better. This time, do it with this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic