- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
给定一张图片,如何将其“包裹”在屏幕上?
例如,如果您将图像的 rect 样式对象设置在屏幕边缘下方 - 不可见的一半会 blit 到屏幕顶部。
imageRect.top=800 #Below screen edge
screen.blit(image,imageRect) #Blit on both sides of the screen
这有可能吗(在 pygame 中)?
最佳答案
当我尝试侧边掉落和收集风格的游戏时,我遇到了同样的问题。经过进一步检查,我找到了一种用两张图片实现这一壮举的方法。下面是我使用的代码。
首先创建两个变量 display_width
和 display_height
它们是游戏窗口的宽度和高度。
display_width = [width of window]
display_height = [height of window]
接下来为第一张和第二张图片的“x”位置再创建两个变量。然后在 obj_width
变量下声明以像素为单位的图像宽度。
img_x = ['x' position of first image]
img2_x = ['x' position of second image, works best with same 'x' as 'img_x' above]
obj_width = [width of img]
现在制作一个接受img_x
和img_y
的图像函数。 img_x
是局部变量,不要与其他 img_x
混淆。
def img(img_x,img_y):
screen.blit([image file here], (img_x,img_y))
这是我在程序中使用的条件。随意复制和粘贴。
if img_x + img_width > display_width:
img(img2_x, display_height * 0.8)
img2_x = img_x - display_width
if img_x < 0:
img(img2_x, display_height * 0.8)
img2_x = img_x + display_width
if img2_x + bag_width > display_width:
img(img_x, [where you want the image to appear, ex. display_height * 0.8])
img_x = img2_x - display_width
if img2_x < 0:
img(img_x, display_height * 0.8) #same as above
img_x = img2_x + display_width
在此示例中,图像水平移动,如果您想要垂直移动,只需根据自己的喜好更改变量即可。我希望这能回答您的问题,如果有什么地方不能正常工作或者有任何拼写错误,请随时在下面发表评论。我知道这是大约一年前发布的问题,如果为时已晚,我深表歉意。
祝你好运,JC
关于python - 如何在屏幕边缘包裹 blit?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28326911/
我想了解如何正确地从 Parcel 中读取空值。让我们看看我的用例: public class MyModel implements Parcelable { private Long id;
好吧,我知道我必须使用 JDBC 等,但我不确定如何将 jar 实现到我的代码中,我有一个基本代码来打开文件等,但我如何才能真正将 sqlite jar 与我的 java 一起合并类文件可以在任何地方
我想知道是否可以打包(或序列化)ClassLoader 以通过 Message 将其发送到 Android 中的另一个进程。 ClassLoader没有实现 Parcelable/Serializab
在上传到我的域时尝试让我的 SVG 出现在浏览器中时,我 - 类似于我拥有 的其他项目包裹安装 - 创建了一个 静态文件夹 我会将 SVG 文件放入的位置。它现在出现在浏览器中,但是,正在播放的“绘图
我有这样的东西: 我希望以最简单的方式实现这样的事情:
当我们使用一个独立的函数语句作为 IIFE 时,我们需要用 () 包装它以使其工作 // IFFE (function a(){ console.log('Hello') }()); // I
我正在为 WCF 开发一个 Java 客户端,并且模板运行良好。我最初使用的是 eclipse 的 Web 服务客户端项目,但后来发现 android 平台不支持所需的库。当时我打算使用 ksoap,
我希望将整行变为可点击。现在行看起来像 Group Obj
我有以下标记(使用 Bootstrap 4): .resource{ border:1px solid red; } tes
#parent{ max-width:1100px; margin: auto; border: 1px solid red; padding: 40px; } #ch
我正在尝试用自定义指令包裹 Angular 带的弹出框。 弹出窗口应该能够使用由使用我的指令的人提供的自定义模板,并且该模板应该能够使用 Controller 的范围。 对于范围部分,我发现我可以将
我有一个 HTML 页面,其中一个 div 包含另一个包含数据库(聊天系统)中所有用户的 div,但是 ul li 标签没有占用父 div 的整个宽度。这是预期结果的图像:http://prntscr
我正在尝试通过套接字将包裹发送到 Android 应用程序。客户端在 libbinder(c++) 中,服务器是一个必须重建包裹的 android 应用程序。我一直在寻找解决方案有一段时间了,但我不知
当我部署一个网站(有多个入口点,许多 HTML 文件)并且主机使用构建命令时:parcel build index.html aboutme.html。部署的网站给我一个 404 错误。但是,如果我在
在 Quarkus 中,异常映射器返回的实体似乎被包装在另一个实体中。 提供一个 JAX-RS 异常映射器,例如: @Provider public class WebhookExceptionMap
如果我设置 textLayer.wrapped = YES , 如何调整大小 textLayer包含包装的文本?即,我如何获得 textLayer 的新高度? 基本上,我想要类似 -[UILabel
您好,如果类有 anchor ,我会尝试用 anchor 包裹图像。 jQuery: if ( $(".views-row:has(a)").length) { var noderef = $
所以,我以前多次使用 Parcel,我从来没有遇到过问题。 这一次它抛出了一些关于 SemVer 版本控制的愚蠢错误,我真的很想找到解决这个问题的解决方案。 我开始了新项目:安装了 npm w/npm
我将 Kotlin 与 Anko 一起使用,我想向另一个 Activity 发送玩家列表。 class Player(var name: String?) { var score: Int = 0 i
我正在尝试使用 Parcelable 通过 Activity 传递数据。这是我的代码: public class Player implements Parcelable { public stati
我是一名优秀的程序员,十分优秀!