English 中文(简体)
我怎样才能使我所要创造的 rec子在性质上变得更重要,而不是其规模的5倍[重复]。
原标题:How do I make my rectangle to be created just bigger then the character and not 5 times its size [duplicate]

I am fairly new to pygame and am working on my first game. (So sorry if I m asking a stupid question) I am trying to get the title of the game to slowly increase and decrease in size like a sort of breathing effect in order to make the home screen more visually appealing.

这里,我已想到的是,要输入形象:

name = self.dir_path + "pixeltitle.png"
self.pixeltitle = pg.image.load(name)
self.pixeltitlerect = self.pixeltitle.get_rect()
self.pixeltitlerect.center = (250,120)
self.screen.blit(self.pixeltitle,self.pixeltitlerect)

我先看一看一眼,我会增加休养的体积,然而,它却被转移到右上下。 是否有办法增加面积,并在同一地点保留中心? 是否有办法使增减规模更加顺利? 该法典的其余部分:

clicked = False
        grow = 0
        mode =  grow 
        while not clicked:
            if grow>40:
                mode =  shrink 
            if grow<1:
                mode =  grow 
                self.pixeltitle = pg.transform.scale(self.pixeltitle,(400,400))


            if mode ==  grow :
                grow+=1
            else:
                grow-=1

            xsize=400+int(grow)
            ysize=400+int(grow)

            self.pixeltitle = pg.transform.scale(self.pixeltitle,(xsize,ysize))
            self.pixeltitlerect.center = (250,120)
            self.screen.blit(self.pixeltitle,self.pixeltitlerect)
            pg.display.flip()
问题回答

在水面缩小后,你未能更新<代码>本身。

self.pixeltitle = pg.transform.scale(self.pixeltitle,(xsize,ysize))

# size of surface has been changed get the new rectangle
self.pixeltitlerect = self.pixeltitle.get_rect()

self.pixeltitlerect.center = (250,120)
self.screen.blit(self.pixeltitle,self.pixeltitlerect)

甚至更短(见pyega.Surface.get_rect():

self.pixeltitle = pg.transform.scale(self.pixeltitle,(xsize,ysize))
self.pixeltitlerect = self.pixeltitle.get_rect(center = (250,120))
self.screen.blit(self.pixeltitle,self.pixeltitlerect)

不包括原水面。 如果原水面缩小,就会发生扭曲。 保存原始形象<代码>。

self.pixeltitle = pygame.transform.scale(self.pixeltitleorig,(xsize,ysize))

另见

例如:

”/</a

import pygame
pygame.init()
window = pygame.display.set_mode((500, 500))
clock = pygame.time.Clock()

class ScalingSurface:
    def __init__(self):
        name = "pixeltitle.png"
        self.pixeltitleorig = pg.image.load(name)
        self.pixeltitle     = self.pixeltitleorig
        self.pixeltitlesize = self.pixeltitle.get_size()
        self.pixeltitlerect = self.pixeltitle.get_rect()
        self.pixeltitlerect.center = (250,120)
        self.mode =  grow 
        self.grow = 0

    def update(self):
        if self.grow > 40:
            self.mode =  shrink 
        if self.grow<1:
            self.mode =  grow 
        self.grow += 1 if self.mode ==  grow  else -1

        xsize = self.pixeltitlesize[0] + round(self.grow)
        ysize = self.pixeltitlesize[1] + round(self.grow)
        self.pixeltitle = pygame.transform.scale(self.pixeltitleorig,(xsize,ysize))
        self.pixeltitlerect = self.pixeltitle.get_rect(center = (250,120))

    def draw(self, surf):
        surf.blit(self.pixeltitle,self.pixeltitlerect)

img = ScalingSurface()
run = True
while run:
    clock.tick(60)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    window.fill(0)
    img.update()
    img.draw(window)
    pygame.display.flip()




相关问题
Get webpage contents with Python?

I m using Python 3.1, if that helps. Anyways, I m trying to get the contents of this webpage. I Googled for a little bit and tried different things, but they didn t work. I m guessing that this ...

What is internal representation of string in Python 3.x

In Python 3.x, a string consists of items of Unicode ordinal. (See the quotation from the language reference below.) What is the internal representation of Unicode string? Is it UTF-16? The items ...

What does Python s builtin __build_class__ do?

In Python 3.1, there is a new builtin function I don t know in the builtins module: __build_class__(...) __build_class__(func, name, *bases, metaclass=None, **kwds) -> class Internal ...

what functional tools remain in Python 3k?

I have have read several entries regarding dropping several functional functions from future python, including map and reduce. What is the official policy regarding functional extensions? is lambda ...

Building executables for Python 3 and PyQt

I built a rather simple application in Python 3.1 using PyQt4. Being done, I want the application to be distributed to computers without either of those installed. I almost exclusively care about ...

热门标签