Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How do I make my sprite to shoot?  (Read 4041 times)

0 Members and 1 Guest are viewing this topic.

iHope

  • Newbie
  • *
  • Posts: 35
    • View Profile
How do I make my sprite to shoot?
« on: January 23, 2012, 07:35:27 am »
Okay, so I would need help to make my sprite/character to shoot? Is there more better way than just creating everytime a new bullet sprite? And of course how do I make bullet to go that direction where my sprite is looking? Sorry about English, hopefully you understand that much you can help me.

RedIrony

  • Newbie
  • *
  • Posts: 23
    • View Profile
How do I make my sprite to shoot?
« Reply #1 on: January 23, 2012, 08:23:08 am »
Well, you technically don't need to have an individual sprite for each bullet. You could have a list of bullet objects with position vectors, and then draw the same bullet sprite at each location. I guess that'd save some memory at the expense of slightly more operations.

How do you know where your sprite is looking? If you're keeping track of that information with a vector, you can give your bullets a velocity vector based on that.

iHope

  • Newbie
  • *
  • Posts: 35
    • View Profile
How do I make my sprite to shoot?
« Reply #2 on: January 23, 2012, 05:18:35 pm »
Thank you for your reply. I knew there would be a easier way than just drawing a new sprite every time.  :)

iHope

  • Newbie
  • *
  • Posts: 35
    • View Profile
How do I make my sprite to shoot?
« Reply #3 on: January 23, 2012, 06:40:18 pm »
Could you please correct me if I'm wrong.

1. Create a bullet class whit image & sprite of bullet, coordinates of bullet   (+ "of course" type of stuff)

2. Load the image of bullet.

3. Set position of bullet(x,y) & draw the bullet

This is how I understood what you said.

RedIrony

  • Newbie
  • *
  • Posts: 23
    • View Profile
How do I make my sprite to shoot?
« Reply #4 on: January 23, 2012, 10:04:33 pm »
The cleanest way is probably to create an image outside of the bullet class, and then base all your sprite classes off that image (Each bullet object has a sprite variable and a position variable).

The most efficient way is probably to put the sprite in some sort of manager, and then each bullet just has a position. Then you have the manager draw each bullet using that one sprite.

Either method should work, I'm not sure which one is the better design decision in this case. I'd be tempted to go for the latter myself.

iHope

  • Newbie
  • *
  • Posts: 35
    • View Profile
How do I make my sprite to shoot?
« Reply #5 on: January 24, 2012, 06:56:50 am »
So the "manager" could be like void LoadBullets()?

EDIT: I mean void DrawBullets() :)

iHope

  • Newbie
  • *
  • Posts: 35
    • View Profile
How do I make my sprite to shoot?
« Reply #6 on: January 24, 2012, 03:00:51 pm »
Got it working, no need to answer anymore :D

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
How do I make my sprite to shoot?
« Reply #7 on: January 24, 2012, 04:48:55 pm »
An easier to read example is to simply keep track of the face and move angles of your sprite and use them to tell the bullets what direction to go in.

Like in a space shooter for example you simply use the face angle to show the bullets what direction to go in.

Not sure if I'm making any sense.
I have many ideas but need the help of others to find way to make use of them.

iHope

  • Newbie
  • *
  • Posts: 35
    • View Profile
How do I make my sprite to shoot?
« Reply #8 on: January 24, 2012, 07:30:06 pm »
Quote from: "StormWingDelta"
An easier to read example is to simply keep track of the face and move angles of your sprite and use them to tell the bullets what direction to go in.

Like in a space shooter for example you simply use the face angle to show the bullets what direction to go in.

Not sure if I'm making any sense.


Thanks for your reply.

 

anything