topdownengine.visual_utils Reference¶
VisualUtils
¶
Source code in topdownengine\visual_utils.py
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
create_outline(surface, thickness, outline_color)
staticmethod
¶
Create an outline of a given thickness and color on a Surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
surface
|
Surface
|
The surface to outline. |
required |
thickness
|
int
|
The thickness of the outline. |
required |
outline_color
|
ColorLike
|
The color of the outline. |
required |
Source code in topdownengine\visual_utils.py
draw_low_res_line(surface, color, start_pos, end_pos, res=256)
staticmethod
¶
Draw a line that matches the game's pixel resolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
surface
|
Surface
|
The surface to draw the line on. |
required |
color
|
ColorLike
|
The color of the line. |
required |
start_pos
|
Point
|
The start position. |
required |
end_pos
|
Point
|
The end position. |
required |
res
|
int
|
The amount to divide by. Defaults to 256. |
256
|
Source code in topdownengine\visual_utils.py
flip_animation(anim, flip_x=False, flip_y=False)
staticmethod
¶
Flip an animation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
anim
|
list[Surface]
|
The animation to flip. |
required |
flip_x
|
bool
|
Flip x? Defaults to False. |
False
|
flip_y
|
bool
|
Flip y? Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
list[Surface]
|
list[pygame.Surface]: The animation. |
Source code in topdownengine\visual_utils.py
load_animation(filename, frame_width, frame_height, new_frame_width=None, new_frame_height=None)
staticmethod
¶
Loads an animation from a given file with a given frame width and height.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
File path. |
required |
frame_width
|
int
|
Frame width. |
required |
frame_height
|
int
|
Frame height. |
required |
new_frame_width
|
int
|
New frame width. Defaults to None. |
None
|
new_frame_height
|
int
|
New frame height. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[Surface]
|
list[pygame.Surface]: The animation. |
Source code in topdownengine\visual_utils.py
load_animations(filename, frame_width, frame_height, scale_to=None)
staticmethod
¶
Loads multiple animations from a given spritesheet with a given frame width and height.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
File path. |
required |
frame_width
|
int
|
Frame width. |
required |
frame_height
|
int
|
Frame height. |
required |
scale_to
|
int | tuple
|
Integer/tuple to scale by/to. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[list[Surface]]
|
list[list[pygame.Surface]]: The list of animations. |
Source code in topdownengine\visual_utils.py
make_img_white(surface, amount=255)
staticmethod
¶
Whiten a surface to a given degree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
surface
|
Surface
|
The surface to modify. |
required |
amount
|
int
|
The degree to whiten by. Defaults to 255. |
255
|
Returns:
| Type | Description |
|---|---|
Surface
|
pygame.Surface: The new Surface. |
Source code in topdownengine\visual_utils.py
replace_color(surface, old_color, new_color)
staticmethod
¶
Replace all of one given color in a Surface with another.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
surface
|
Surface
|
The surface to modify. |
required |
old_color
|
ColorLike
|
The old color to replace. |
required |
new_color
|
ColorLike
|
The new color to replace with. |
required |
Returns:
| Type | Description |
|---|---|
Surface
|
pygame.Surface: The new Surface. |