Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 有没有办法将标题爬网限制在屏幕的特定部分?_Python_User Interface_Pygame - Fatal编程技术网

Python 有没有办法将标题爬网限制在屏幕的特定部分?

Python 有没有办法将标题爬网限制在屏幕的特定部分?,python,user-interface,pygame,Python,User Interface,Pygame,我正在尝试做结束学分,如动画标题爬网上面的代码,我正在尝试对其进行以下更改:-1)文本应该从屏幕底部的某个位置开始,这样字符串中的其他文本就不会显示在屏幕上该位置的下方。2) 文本应该停在屏幕顶部的某个位置,这样当它到达该位置时,顶部的行应该被删除,为字符串中的其他行腾出空间。 我是一个python新手,我只是在尝试一些东西,下面的代码也不属于我 import pygame from pygame.locals import * pygame.init() pygame.display.set

我正在尝试做结束学分,如动画标题爬网上面的代码,我正在尝试对其进行以下更改:-1)文本应该从屏幕底部的某个位置开始,这样字符串中的其他文本就不会显示在屏幕上该位置的下方。2) 文本应该停在屏幕顶部的某个位置,这样当它到达该位置时,顶部的行应该被删除,为字符串中的其他行腾出空间。 我是一个python新手,我只是在尝试一些东西,下面的代码也不属于我

import pygame
from pygame.locals import *

pygame.init()
pygame.display.set_caption('Title Crawl')
screen = pygame.display.set_mode((1000, 800))
screen_r = screen.get_rect()
font = pygame.font.SysFont("franklingothicdemibold", 40)
clock = pygame.time.Clock()

def main():

    crawl = ["Star Wars - The Wilds"," ","It is  a dark time for the Galaxy. The evil Dark","Lord, Vitiate is rising to power. Alone, a single", "spec   is  on  a  trip,  a  trip that will ultimately", "rectify  the wrongs of the galaxy. The keepers ", "of  peace are dying out and the  DARK SIDE is", "lurking,   a   conniving   force   determined  to", "become the omniarch."]

    texts = []
    # we render the text once, since it's easier to work with surfaces
    # also, font rendering is a performance killer
    for i, line in enumerate(crawl):
        s = font.render(line, 1, (229, 177, 58))
        # we also create a Rect for each Surface. 
        # whenever you use rects with surfaces, it may be a good idea to use sprites instead
        # we give each rect the correct starting position 
        r = s.get_rect(centerx=screen_r.centerx, y=screen_r.bottom + i * 45)
        texts.append((r, s))

    while True:
        for e in pygame.event.get():
            if e.type == QUIT or e.type == KEYDOWN and e.key == pygame.K_ESCAPE:
                return

        screen.fill((0, 0, 0))

        for r, s in texts:
            # now we just move each rect by one pixel each frame
            r.move_ip(0, -1)
            # and drawing is as simple as this
            screen.blit(s, r)

        # if all rects have left the screen, we exit
        if not screen_r.collidelistall([r for (r, _) in texts]):
            return

        # only call this once so the screen does not flicker
        pygame.display.flip()

        # cap framerate at 60 FPS
        clock.tick(60)

if __name__ == '__main__': 
    main()
用于设置显示曲面的剪裁区域

e、 g.在顶部和底部夹住100行:

#设置剪切矩形
clip_rect=(0,100,screen.get_width(),screen.get_height()-200)
屏幕。设置剪辑(剪辑)
对于文本中的r,s:
#现在我们只需将每个矩形每帧移动一个像素
r、 移动ip(0,-1)
#绘画就这么简单
屏幕。blit(左、右)
#取消剪切以进行进一步绘图
屏幕。设置剪辑(无)