comparison gamelib/cursor.py @ 302:6d93e04036c9

CursorSprite: Default pointer-position to the centre of the cursor
author Stefano Rivera <stefano@rivera.za.net>
date Sat, 28 Aug 2010 01:32:54 +0200
parents fbfd8e748ac0
children 3476e8f3b100
comparison
equal deleted inserted replaced
301:cecdb67f4f4b 302:6d93e04036c9
11 import pygame.mouse 11 import pygame.mouse
12 12
13 class CursorSprite(Sprite): 13 class CursorSprite(Sprite):
14 "A Sprite that follows the Cursor" 14 "A Sprite that follows the Cursor"
15 15
16 def __init__(self, filename, x, y): 16 def __init__(self, filename, x=None, y=None):
17 Sprite.__init__(self) 17 Sprite.__init__(self)
18 self.filename = filename 18 self.filename = filename
19 self.pointer_x = x 19 self.pointer_x = x
20 self.pointer_y = y 20 self.pointer_y = y
21 self.highlighted = False 21 self.highlighted = False
23 def load(self): 23 def load(self):
24 if not hasattr(self, 'plain_image'): 24 if not hasattr(self, 'plain_image'):
25 self.plain_image = get_image('items', self.filename) 25 self.plain_image = get_image('items', self.filename)
26 self.image = self.plain_image 26 self.image = self.plain_image
27 self.rect = self.image.get_rect() 27 self.rect = self.image.get_rect()
28
29 if self.pointer_x is None:
30 self.pointer_x = self.rect.size[0] // 2
31 if self.pointer_y is None:
32 self.pointer_y = self.rect.size[1] // 2
33
28 self.highlight = pygame.Surface(self.rect.size) 34 self.highlight = pygame.Surface(self.rect.size)
29 color = pygame.color.Color(255, 100, 100, 0) 35 color = pygame.color.Color(255, 100, 100, 0)
30 self.highlight.fill(color) 36 self.highlight.fill(color)
31 37
32 def update(self): 38 def update(self):