Seite 1 von 1

Konturen einer Python-Animation verwischen sich

Verfasst: Freitag 26. Juni 2020, 11:56
von dodas
Hallo!

Ich habe ein kleines Python-Skript im Anhang, welches eine kleine Animation ausführt. Der Pirat Guybrush von Monkey Island läuft über einen Steg, während der Hintergrund von rechts nach links scrollt. Das funktioniert auch. Jedoch verschwimmen der Hintergrund und auch das Männchen nach einer Weile. Hat jemand eine Idee, wie es dazu kommen kann? Das Py-Script habe ich auch beigefügt. Danke!

Grüße Thomas

Code: Alles auswählen

#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import sys
import pygame

os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ['SDL_VIDEODRIVER']="fbcon"

SIZE = WIDTH, HEIGHT = 480, 320 #the width and height of our screen
#BACKGROUND_COLOR = pygame.Color('black') #The background colod of our window
FPS = 10 #Frames per second

class MySprite(pygame.sprite.Sprite):
	def __init__(self):
		super(MySprite, self).__init__()

		self.images = []
		self.images.append(pygame.image.load('/home/pi/wanduhr/images/Guybrush_0_0.png'))
		self.images.append(pygame.image.load('/home/pi/wanduhr/images/Guybrush_0_1.png'))
		self.images.append(pygame.image.load('/home/pi/wanduhr/images/Guybrush_0_2.png'))
		self.images.append(pygame.image.load('/home/pi/wanduhr/images/Guybrush_0_3.png'))
		self.images.append(pygame.image.load('/home/pi/wanduhr/images/Guybrush_0_4.png'))
		self.images.append(pygame.image.load('/home/pi/wanduhr/images/Guybrush_0_5.png'))

		self.index = 0

		self.image = self.images[self.index]

		self.rect = pygame.Rect(200, 140, 100, 100)

	def update(self):
		self.index += 1

		if self.index >= len(self.images):
			self.index = 0
		
		self.image = self.images[self.index]

def main():
	global xx
	xx = 0
	pygame.init()
	screen = pygame.display.set_mode(SIZE)
	my_sprite = MySprite()
	pygame.mouse.set_visible(0)	
	my_group = pygame.sprite.Group(my_sprite)
	clock = pygame.time.Clock()
	back_image = pygame.image.load('/home/pi/wanduhr/images/monkey-bg.png')
	back_rect = back_image.get_rect()


	while True:
		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				pygame.quit()
				quit()

		my_group.update()
		#screen.fill(BACKGROUND_COLOR)
		screen.blit(back_image, back_rect)
		screen.blit(back_image, back_rect.move(back_rect.width, 0))
		back_rect.move_ip(-2, 0)
		if back_rect.right == 0:
			back_rect.x = 0
		my_group.draw(screen)  
		pygame.display.update()
		clock.tick(60)
		pygame.display.flip()

if __name__ == '__main__':
	main()

Re: Konturen einer Python-Animation verwischen sich

Verfasst: Freitag 26. Juni 2020, 15:41
von hyle
Zur Info für die Leser: https://forum-raspberrypi.de/forum/thre ... chen-sich/

@dodas Dieser Link ist hier nochmals für Dich: https://www.linux-tips-and-tricks.de/de ... ie-keiner/

Re: Konturen einer Python-Animation verwischen sich

Verfasst: Freitag 26. Juni 2020, 16:31
von __blackjack__
@dodas: Meine Glaskugel sagt "/home/pi/wanduhr/images/monkey-bg.png" könnte eine ungerade Breite haben. Dann überleg mal warum das hier ein Problem ist:

Code: Alles auswählen

        back_rect.move_ip(-2, 0)
        if back_rect.right == 0:
            back_rect.x = 0

Re: Konturen einer Python-Animation verwischen sich

Verfasst: Montag 29. Juni 2020, 11:18
von __blackjack__
Es gab Rückmeldung im anderen Forum, dass das Problem damit gelöst ist.