• 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

Shoot Projectile help

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a character on-screen that moves around with left,right,up, and down arrows. What I'm wondering how do I simply make an object (in this case an image) release from where he is standing and fire in a straight direction?
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll have to give more details about your program. Is this an event driven program, where you have an event loop and objects that are hooked into the event loop? If you don't know what an event loop is, then chances are the answer is "No."

If you do have an event loop, then the projectile will need a velocity property that includes both speed and direction and its current position. It will then implement an appropriate hook method to recalculate its new position. Another hook method, usually called draw() will just draw the image based on its current properties, i.e. its current position on screen.

If you don't have an event loop, you could spawn off a thread that starts drawing the projectile from the character's current position, then calculates new coordinates and redraws the projectile's image every so often at the new position. The thread ends when the projectile's position "falls off" the visible portion of the display.
reply
    Bookmark Topic Watch Topic
  • New Topic