python get rect 函数_Pygame:如何正确使用get_rect()
我想了解get_rect()是如何工作的。在这个简单的例子中,我有两个图像,希望获得第二个图像的位置,并将第一个图像移动到第二个图像。
我在网上看过各种各样的例子,但都无法让它发挥作用。我做错什么了?import pygame, sys
from pygame.locals import *
import time
pygame.init()
FPS = 10 # frames per second setting
fpsClock = pygame.time.Clock()
# Set up the window
DISPLAYSURF = pygame.display.set_mode((600, 400), 0, 32)
pygame.display.set_caption('Test program for get_rect()')
WHITE = (255, 255, 255)
# Load two images
baseImg = pygame.image.load('image1.jpg')
spaceshipImg = pygame.image.load('image2.jpg')
DISPLAYSURF.fill(WHITE)
# Place one image at the bottom of the screen
DISPLAYSURF.blit(baseImg, (300, 300))
pygame.display.update()
# Place the second image at the top of the screen
DISPLAYSURF.blit(spaceshipImg, (300, 0))
pygame.display.update()
# Wait for one second
time.sleep(1)
# Obtain the rectangle for each image
baseRect = baseImg.get_rect()
spaceshipRect = spaceshipImg.get_rect()
# This is where I believe I'm going wrong
# I understand this to obtain the x,y of the spaceship image
# Set the xy coordinates for the top image to the xy of the bottom image
spaceshipRect.x = baseRect.x
spaceshipRect.y = baseRect.y
# Move the top image to new xy position
# However this doesn't work
DISPLAYSURF.blit(spaceshipImg, (spaceshipRect.x, spaceshipRect.y))
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
python get rect 函数_Pygame:如何正确使用get_rect()相关推荐
- python get rect 函数_Python之Pygame.rect函数
1.参数设置 Pygame 通过 Rect 对象存储和操作矩形区域.一个 Rect 对象可以由 left,top,width,height 几个值创建.Rect 也可以是由 Pygame 的对象所创建 ...
- 在python中有关函数的表达正确的是_在 Python 中有关函数的表达中正确的是( )。_学小易找答案...
[单选题]会稽有佳山水,名士多居之,爱好养生的王羲之常与( )等宴集于山阴之兰亭. [判断题]截交线既在截平面上,又在立体表面上,故截交线是截平面与立体表面的共有线,截交线上每一点均为其共有性. [单 ...
- python get rect 函数_python笔记之函数
函数 >>> def funTest(param1): ... 'this is function document string.' #正文需要有缩进 ... return par ...
- python中rect用法_pyGame中rect对象的方法解释,pygame,Rect,详解
目录 copy () 功能:复制矩形 属性:copy() -> Rect 返回与原始矩形具有相同位置和大小的新矩形. New in pygame 1.9 move () 功能:移动矩形 属性:m ...
- python中rect函数_使用类和函数的面向对象Python-rectangle
我正在用Python创建一个程序,它将利用面向对象的编程来打印给定矩形的属性.该项目有以下限制:The purpose of this lab is to give you practice crea ...
- 在python中对于函数定义代码的理解正确的理解是_Python 5 函数
一.判断题(共10小题,10分) 在Python中,自定义函数的关键字是def.(1分) A.对 B.错 参考答案: A 形参可以看做是函数内部的局部变量,函数运行结束之后形参就不可访问了.(1分) ...
- python中len 函数_python len
广告关闭 腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元! 在python中除了print函数之外,len函数和type函数应该算是使用最频 ...
- python使用什么函数接收用户输入的数据_python 3.x:调用和执行函数的用户输入...
有许多类似的问题,但没有一个答案解决了我的问题. 我定义了几个解析大型数据集的函数.首先,我调用数据,然后将数据(在.txt中表示为行和列)组织到列表中,我将为各个数据条目编制索引.在此之后,我建立了 ...
- python怎么用函数查看变量类型_查看变量类型的Python内置函数是()。
[单选题]下列不属于反射的是( ) [判断题]传统通俗史学有普及型和通俗型 [单选题]当前最流行和最受重视的资料分析是( ). [简答题]什么情况下采用斜视图比较合适? [单选题]下列命题正确的是( ...
- 开发函数计算的正确姿势 —— 爬虫
2019独角兽企业重金招聘Python工程师标准>>> 在 <函数计算本地运行与调试 - Fun Local 基本用法> 中,我们介绍了利用 Fun Local 本地运行 ...
最新文章
- Linux系统自动更新时间
- nowcoder172C 保护 (倍增lca+dfs序+主席树)
- Android 7.0 获取相机拍照图片,适配三星手机拍照,解决三星手机拍照屏幕旋转,判断设备是否有摄像头
- 配色方案--构图必学
- Atitit Loading 动画效果
- python调用mt4_python mt4
- java 排秩,lamd(java lambda表达式)
- 什么是原码,1’s Complement Code反码和2’s Complement Code补码
- wordpress的excerpt()函数
- 【Selenium】控制当前已经打开的 chrome浏览器窗口
- C语言编程 体型预测
- 五. Tomcat 常见问题解决及面试题
- 《Linux操作系统 - RK3288开发笔记》第2章 G-3288-02开发环境搭建
- 【Weiler-Atherton算法】 计算机图形学多边形裁剪算法
- MongoDB 复制集 (一) 成员介绍
- 有参函数和无参函数的区别
- 算一个数的阶乘(例如100的阶乘)
- 情人节程序员用HTML网页表白【做我女朋友】 HTML5七夕情人节表白网页源码 HTML+CSS+JavaScript
- 互联网世界里的大忽悠,纯属娱乐
- python源码图片_初学者用python爬凡客图片的源码
热门文章
- 安卓开发中wifi连接打印机打印图片
- \t\t中国机械工程师资格认证中心及各分中心通讯录
- shark恒破解笔记2-绕过自校验
- matlab中的sprintf函数,Matlab中disp和sprintf函数使用方法和区别介绍
- 《结构分析的有限元法与MATLAB程序设计》笔记
- ue4 unreal 使用 Download Image 下载图片 下载多张图片 批量下载 类似untiy协程
- Hbase数据库介绍
- AUTOCAD圆角半径过大问题的思考和计算
- ACM/ICPC World Finals 2012 B Curvy Little Bottles
- JDK7和JDK8的区别