侧面滚动背景(python)-无法100%工作 [英] side scrolling background (python) - not 100% working

查看:87
本文介绍了侧面滚动背景(python)-无法100%工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在侧面滚动背景中放入我的游戏,这是我现在得到的内容:

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()

此刻,我得到一个闪烁的屏幕,其中运动图像向右移动,原始图像在其上平稳地闪烁,这将不胜感激-因为它对于我的A级计算课程a并已尝试实现一个功能使他很久以来就喜欢这款游戏....再次感谢您的帮助

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

推荐答案

我也在游戏"中也遇到了视差效果.我会向您建议: http://www.pygame.org/project-pyParallax -2623-.html

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

下载该模块,并运行和反汇编该演示,这非常容易理解和复制. (提示:parallax.ParallaxSurface.add()方法具有第三个参数,您可以将其传递给该参数,它将为您适当地缩放图像.非常易于使用的模块.

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.

这篇关于侧面滚动背景(python)-无法100%工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆