Konturen einer Python-Animation verwischen sich

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
dodas
User
Beiträge: 2
Registriert: Freitag 5. Juni 2020, 08:51

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()
Benutzeravatar
hyle
User
Beiträge: 96
Registriert: Sonntag 22. Dezember 2019, 23:19
Wohnort: Leipzig

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/
Alles was wir sind ist Sand im Wind Hoschi.
Benutzeravatar
__blackjack__
User
Beiträge: 14052
Registriert: Samstag 2. Juni 2018, 10:21
Wohnort: 127.0.0.1
Kontaktdaten:

@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
“Vir, intelligence has nothing to do with politics!” — Londo Mollari
Benutzeravatar
__blackjack__
User
Beiträge: 14052
Registriert: Samstag 2. Juni 2018, 10:21
Wohnort: 127.0.0.1
Kontaktdaten:

Es gab Rückmeldung im anderen Forum, dass das Problem damit gelöst ist.
“Vir, intelligence has nothing to do with politics!” — Londo Mollari
Antworten