Wednesday, December 17, 2014

Project 1 - Rendering - Player Class & Sprite Sheet

I thought it suitable to start the Player Class and was able to render a rectangle onto the screen. This was done relatively easy - when initializing the player class, I needed to include an x & y coordinate as well as an image, gravity and velocity. Two methods were also created, an update method and a render method, each called by the main-loop. The render method was relatively simple -

pygame.draw.rect(window, (150, 150, 150), (self.x, self.y, self.width, self.height))

This basically draws a rectangle on the screen. Note - the sprite has not been rendered yet.


The sprite I'm using is from spriters resource - an online archive of a bunch of sprites and maps etc. I didn't want to spend too long choosing one, so I just picked above. To select a sprite from this sheet, the most suitable way is to use the set_clip and get_clip functions of Pygame as well as some simple mathematics. 


No comments:

Post a Comment