[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Sprite Classes



I'm far from an expert programmer, so maybe someone has better advice than this, but I don't think you should make the player and the things it shoots parts of the same sprite. A 'bullet' should be a new sprite that tracks its own movement, independent of the player. 

So what you'd do is to make a new sprite class that's image is the bullet.  When you call your playerSprite's Shoot() function, what you would do is create a new bullet and start it moving.  You could use parameters already contained in the player like Direction, Velocity, etc. to help determine the bullet's initial conditions depending on how you want the bullets to behave.  The point though is that as soon as it's created, the player can forget about it, the bullet will take care of updating its own movement and figuring out where it should be drawn.

Hope this helps.


On Tue, Dec 13, 2011 at 11:59 PM, Andrew Godfroy <killerrin@xxxxxxxxxxx> wrote:
Hi,
 
I was wondering some things about sprites to help me understand them better. I currently have a sprite class which loads up the player and can move it around using the joystick/keyboard as well as rotate the character based on what direction they are moving. What I want to be able to do is add into the class a shoot function that will take the parameters I pass to it (I already have the control system for joysticks ready for it)
 
What I want to know is how sprite track what they draw, and if it is possible to have it track two different images and locations per instance?
 
 
With Thanks,
 
 
Andrew Godfroy