python 2.7 - Get sprite to stay on screen? -


how sprite remain on screen , on green platform? sprite keeps falling off screen, can please?

player_image = pygame.image.load("bcquestchar.png") player_image.set_colorkey(white) def draw_background(screen, x, y):     pygame.draw.line(screen, ground_green, [0, 400], [700, 400], 200)     pygame.draw.line(screen, sky_blue, [0,0], [700,0], 400)     pygame.draw.line(screen, sky_white, [0, 270], [700, 270], 150)  #jumping player definition  class player(pygame.sprite.sprite):     def __init__(self):         self.playing = false         self.color = blue         self.x = 50         self.y = 210         self.goaly= 450         self.gameover = false     def jump(self):         self.goaly -= 45     def draw(self, screen):         screen.blit(player_image, [self.x, self.y])         #create player player = player() 

simply make function make sure when sprite's bottom touching bottom of screen, stops there, waiting other commands. example:

if self.x >= 1000:         self.x = 1000 

the above code means if x position greater or equal 1000, set x 1000 doesn't go lower. number can change fit needs well. need call update function need work:

def update(self):        #put function player class     if self.x >= 1000:         self.x = 1000  #put following while loop or call player = player() player.update()    #call update() 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -