I have this function:
def draw_image(image, xy ,draw_img=True,camera=False):
all_images.append(Image(image, xy, draw_img, camera))
#draw all images
for image in all_images:
image.run()
pass
and in the class I have this:
class Image:
def __init__(self, image, xy, draw_img, camera):
self.image = image
self.x = list(xy)[0]
self.y = list(xy)[1]
self.draw_img = draw_img
self.camera = camera
pass
def run(self):
global
col_up,col_down,col_left,col_right,right_speed,left_speed,up_speed,down_speed,left_key,up_key,down_key,jump_velocity, left_key,right_key,up_key,down_key,run_once6,run_once3,jumped, time, last_time,change_x,player_speed,change_y
if self.draw_img:
if not camera:
screen.blit(self.image, (self.x, self.y))
if camera:
if change_x == 'x-':
self.x += player_speed
if change_x == 'x+':
self.x -= player_speed
if change_y == 'y-':
self.y += player_speed
if change_y == 'y+':
self.y -= player_speed
if self.draw_img:
if camera:
screen.blit(self.image, (self.x, self.y))
pass
pass
I need to call draw_image()
in a while loop.
So, two things occur:
The first thing that occurs is that the program keeps adding to the list.
I can fix this by placing the variable in the while loop.
The second thing is that the init
file runs every frame.
As such, everything in init()
is ran multiple times, which is not supposed to happen.
When I say self.x += 1
, it is instantly reset to 0. As such, I'm not able to change the position of the image.