• Post Reply Bookmark Topic Watch Topic
  • New Topic

Shoot Projectile help  RSS feed

 
Ricky Peddicord
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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?
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!