- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我无法理解 Stackoverflow 中的其他问题。当圆圈向屏幕末端移动时,它会向相反的方向移动。
import pygame
import sys
pygame.init()
screen = pygame.display.set_mode([640,480])
screen.fill([255,255,255])
circle = pygame.draw.circle(screen, [255,0,0],[100,100],30,0)
x = 50
y = 50
x_speed = 5
y_speed = 5
done = "False"
while done == "False":
for event in pygame.event.get():
if event.type == pygame.QUIT:
done="True"
pygame.time.delay(20)
pygame.draw.rect(screen,[255,255,255],[x,y,30,30],0)
x = x + x_speed
y = y + y_speed
if x > screen.get_width() - 30 or x < 0:
x_speed = -x_speed
if y > screen.get_height() - 30 or y < 0:
y_speed = -y_speed
screen.blit(circle,[x,y])
pygame.display.flip()
pygame.quit()
发出错误消息但未执行。
screen.blit(circle,[x,y])
TypeError: argument 1 must be pygame.Surface, not pygame.Rect
有什么问题吗?
最佳答案
pygame.draw.circle
返回 pygame.Rect
不是pygame.Surface
并且你只能blit
表面而不是矩形(这就是回溯告诉你的)。因此,创建一个表面对象,使用 pygame.draw.circle 在其上绘制一个圆圈,然后在主循环中将该表面传输到屏幕上。
import pygame
import sys
pygame.init()
screen = pygame.display.set_mode([640,480])
screen.fill([255,255,255])
# A transparent surface with per-pixel alpha.
circle = pygame.Surface((60, 60), pygame.SRCALPHA)
# Draw a circle onto the `circle` surface.
pygame.draw.circle(circle, [255,0,0], [30, 30], 30)
x = 50
y = 50
x_speed = 5
y_speed = 5
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
pygame.time.delay(20)
screen.fill((40, 40, 40))
x = x + x_speed
y = y + y_speed
if x > screen.get_width() - 60 or x < 0:
x_speed = -x_speed
if y > screen.get_height() - 60 or y < 0:
y_speed = -y_speed
# Now blit the surface.
screen.blit(circle, [x, y])
pygame.display.flip()
pygame.quit()
sys.exit()
关于Python TypeError : argument 1 must be pygame. Surface,而不是 pygame.Rect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44471789/
Surface Go是一款微软推出笔记本电脑,但不少小伙伴在使用一段时间之后总会想重装系统从而使电脑更加流畅,那么Surface Go要如何重装Win10系统,下面就和小编一起来看看如何操作吧。
在我的第二个项目中,我使用 opengl 和 SDL2。我想使用 SDL2 将文本渲染到表面,然后进行转换。 我已经在使用 SDL 从文件中加载纹理,所以我有一个可以转换曲面的函数。当我提供由 TTF
我最近更改了表面对象算法的表面引用。然后,我注意到程序运行速度变慢了。 这是一个简单示例的比较,其中我用常量值填充 3D float 数组 [400*400*400]。 表面引用API 时间:9.06
有时,当我退出我的 openGL ES 1 应用程序时,以下错误消息会不断张贴在 logcat 中,应用程序会卡住,并在某个时候终止。 E/EglHelper(4284): Surface is no
这可能是一个愚蠢的问题,但我无法在任何地方找到答案。 Microsoft Surface SDK 2.0 是否仅适用于 Microsoft Surface 产品,还是我可以将其用于其他触摸屏?我真的很
我已经将 camera2 与 textureVIew 集成在一起。它适用于所有设备,但在平板电脑上,当我们第一次捕获图像时,它会崩溃并显示以下日志。 Fatal Exception: java.la
在我正在处理的一个 pygame 项目中,角色和对象的 Sprite 会在地形上转换阴影。阴影和地形都是正常的 pygame 表面,因此,为了显示它们,阴影被 blit 到地形上。当没有其他阴影(只有
在 pygame 中将我的表面涂成黑色之后。我得到错误 pygame.error: display Surface quit. 完整错误: > D:\Programme\Anaconda3\envs\
有谁知道如何用Julia的Pyplot绘制3D曲面,例如 作为面部颜色的表面渐变? 类似于此主题适用于Python:Color matplotlib plot_surface command with
我一直在尝试将 Camera2 api 集成到我的应用程序中。它一开始捕捉图像时工作正常。但是当我第二次拍摄时,预览没有出现。我在 genymotion nexus 5 模拟器中测试了它。尝试了所有示
阅读 pygame 教程 here ,你会发现这个例子:(箭头是我的) for o in objects: screen.blit(background, o.pos, o.pos) # Re
我正在创建两个渲染目标,两者都必须共享后台缓冲区的深度缓冲区,因此我将它们设置为具有相同的多重采样参数很重要,但是 pDevice->CreateTexture(..) 没有给出任何参数设置多重采样类
我正在尝试在屏幕上对文本表面进行 blit,但出现此错误: 类型错误:参数 1 必须是 pygame.Surface,而不是元组。 可能有什么问题?我确信我的文字是一个表面。 import pygam
Joel Spolsky 在 SO 播客中提到了“浮出水面”。 这是什么意思?它是类似于“暴露”的东西吗,比如“暴露接口(interface)”? 最佳答案 这里引用自 podcast 51 的文字记
下面给了我错误 var textSurface = new Surface({ content: 'Some text here', properties:{ color: 'whit
我是一个小机器人,但有一项艰巨的任务要做。我的布局上有一个图像按钮。单击它应该开始显示 camera preview 。 (我有一个视频同时显示在另一个表面上。)两者都很好。 但是当再次按下按钮时,预
我试图每 5 秒画一个红色圆圈。我有一个 draw 和一个 run 方法,run 方法调用绘制圆圈的 draw 方法。但是,当从 run 方法调用 draw 方法时,表面无效,所以我无法绘制任何东西并
我想知道 Surfaceflinger 是否知道当前屏幕上的可点击区域,或者 SurfaceFlinger 只显示最终屏幕,它对可点击区域一无所知,并且 windowmanagerservice 将输
所以这段代码似乎是问题所在: public void surfaceCreated(final SurfaceHolder sh) { loop = new Loop(); loop.
Opengl 纹理坐标 [0,0] 位于左下角。 DDS 文件是否包含有关数据布局的信息(如果数据从左上角或左下角开始)或有一个固定的布局?例如 ktx 文件包含此类信息。 最佳答案 DDS 文件格式
我是一名优秀的程序员,十分优秀!