-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTexture.py
More file actions
61 lines (49 loc) · 1.32 KB
/
Texture.py
File metadata and controls
61 lines (49 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'''
==============================================================================
Texture class for wrapping Pygame Surfaces
(C++ version)
3/11/2014
SDLTutorials.com
Tim Jones
(Python3 version)
22/03/2016
www.inf.ufsm.br/~rtrindade
Rafael Gauna Trindade
==============================================================================
'''
from pygame import image
from Log import Log
class Texture:
Filename = None
Width = 0
Height = 0
PygameSurface = None
Display = None
def Load(self, Display, Filename):
self.Display = Display
self.Filename = Filename
# Load Pygame Surface
try:
self.PygameSurface = image.load(Filename)
except Exception as e:
Log("Unable to load image:",Filename,":",e)
return False
# Grab dimensions
self.Width = self.PygameSurface.get_width()
self.Height = self.PygameSurface.get_height()
return True
def Render(self, X, Y, Width=None, Height=None, SX=None, SY=None, SWidth=None, SHeight=None):
if Width is None:
Width = self.Width
if Height is None:
Height = self.Height
if None in (SX, SY, SWidth, SHeight):
area = None
else:
area = (SX, SY, SWidth, SHeight)
dest = (X, Y, Width, Height)
self.Display.blit(self.PygameSurface, dest, area=area)
def GetWidth(self):
return self.Width
def GetHeight(self):
return self.Height