side scrolling background (python) - not 100% working

扶醉桌前 提交于 2019-12-24 14:28:11

问题


Hi there i am working on a side scrolling abckground to put in my game, heres what ive got at the moment:

import pygame
import sys
import pygame.sprite as sprite

theClock = pygame.time.Clock()
background = pygame.image.load('space.jpg')
background_size = background.get_size()
background_rect = background.get_rect()
screen = pygame.display.set_mode(background_size)
w,h = background_size
x = 0
y = 0
x1 = 0
y1 = -h
running = True
while running:
    screen.blit(background,background_rect)
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    y1 += 5
    y += 5
    screen.blit(background,(y,x))
    screen.blit(background,(y1,1))
    if y > h:
        y = -h
    if y1 > h:
        y1 = -h
    pygame.display.update()
    theClock.tick(25)
pygame.quit()

at the moment i am getting a flickering screen with the moving image going to the right and the original image stationary flickering over it any help would be greatly appreciated - as its for my a-level computing coursework a and have trying to implement a feature liket his into the game for ages.... again thanks for help


回答1:


i struggled with a parallax effect in my 'game' as well. I would suggest this to you: http://www.pygame.org/project-pyParallax-2623-.html

download the module, and run and disassemble the demo, it is very easy to understand and replicate. (Hint: the parallax.ParallaxSurface.add() method has a third argument you can pass to it that will scale your image appropriately for you. Very Very easy to use module.



来源:https://stackoverflow.com/questions/19576626/side-scrolling-background-python-not-100-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!