- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用《Python 初学者编程》中的特殊“pygame”和“livewires”制作一个游戏,并且在大多数情况下它运行得很好。当您可以玩游戏时,计时器会滴答作响,然后当尖峰击中您时,会显示文字“输了!”时间:'然后无论你需要什么时间都会出现。但是,尽管消息生命周期为 300,但当屏幕关闭时消息持续时间不到一秒,您会看到以下错误:
Traceback (most recent call last):
File "run.py", line 105, in main
games.screen.mainloop()
File "C:\Python31\lib\site-packages\livewires\games.py, line 308, in mainloop
object._tick()
File "C:\Python31\lib\site-packages\livewires\games.py", live 506, in _tick
self.update()
File "run.py", line 27, in update
self.check_collide()
File "run.py", line 34, in check_collide
spike.handle_collide()
AttributeError: 'Message' object has no attribute 'handle_collide'
哇哦。这是相关代码(根据我的判断):
class Player(games.Sprite):
"""The player that must dodge the spikes."""
def __init__(self, image, x, y):
super().__init__(image=image, x=x, y=y)
"""
Timer
"""
self.timer = games.Text(value = 0,
size = 40,
color = color.black,
x = 600,
y = 440)
games.screen.add(self.timer)
def update(self):
"""Move to the mouse."""
self.x = games.mouse.x
self.y = games.mouse.y
self.check_collide()
self.timer.value = int(time.clock())
def check_collide(self):
"""Check for a collision with the spikes."""
for spike in self.overlapping_sprites:
spike.handle_collide()
class Spike(games.Sprite):
"""A spike!"""
def update(self):
"""Move to the left!"""
self.x -= random.randrange(3,12)
if self.x == 0 or self.x == 1 or self.x == 2 or self.x == 3 or self.x == 4 or self.x == 5 or self.x == 6 or self.x < 10:
self.x = 640
self.y = random.randrange(games.screen.height)
def handle_collide(self):
"""Destroy!"""
timebomb = int(time.clock())
man = ("Lose! Time:",timebomb)
lost_message = games.Message(value = man,
size = 100,
color = color.red,
x = games.screen.width/2,
y = games.screen.height/2,
lifetime = 300,
after_death = games.screen.quit)
games.screen.add(lost_message)
我很困惑。应该调用方法 handle_collide
以便游戏可以完成,但似乎handle_collide是对象消息的一个属性?如果这看起来很愚蠢,那么抱歉,因为我已经诚实地尽了最大努力,正如书名所暗示的那样,我是一个菜鸟。请帮忙,提前致谢。
最佳答案
找到了修复。
def check_collide(self):
"""Check for a collision with the spikes."""
for spike in self.overlapping_sprites:
spike.handle_collide()
for 循环中的“尖峰”只是与玩家发生碰撞的物体的名称。实际发生的情况是玩家与“消息”对象发生碰撞,然后询问消息对象处理 Sprite 碰撞的方式。消息对象未准备好,并且没有“handle_collide”方法来处理此问题。所以它会抛出一个错误。要修复此问题,您只需将文本移离播放器,或者使用“Message”对象并创建 for 循环所需的方法。
关于python - Pygame,livewires : Attribute error: Message object has no attribute 'handle collide' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30442127/
我正在学习如何使用 livewire 和 laravel,我试图通过输入绑定(bind)一些数据 我写了这段代码: home.blade.php: Home @livewireSt
我有一个包含几张卡片的 livewire 概览组件。在这些卡片中有一个 livewire 表单,但是当我将表单包含到概览组件中时,我的整个 livewire 停止工作。 我添加到概览组件文件中的唯一一
如 docs 中所述,您可以在自定义路径中创建组件,这与默认的 views/livewire/ 和 Http/Livewire 不同。为了更好地组织,我创建了子文件夹: $ php artisan m
如 docs 中所述,您可以在自定义路径中创建组件,这与默认的 views/livewire/ 和 Http/Livewire 不同。为了更好地组织,我创建了子文件夹: $ php artisan m
我正在尝试将用户的地理坐标(纬度和经度)发送到 livewire 组件以加载附近的地点。但是我无法发送它,因为它们是 javascript 变量。问题是如何将 javascript 变量发送到 liv
我想做的是从数据库中获取一些数据并将其显示在 Input Value 字段中,但这里的问题是当我使用 wire:model='some_input_name' 值不显示。如果我删除 wire:mode
在我应用新的 livewire V2 编程风格之前,我有一个连接到模型的各个属性的表单。为了触发字段的实时验证,我在组件中使用了这个(例如 name 属性): public function upda
有 3 个 livewire 组件 UserIsExpired、UserIsActive 和 UserIsPending 以及每个组件对应的 3 个按钮。单击按钮时,它应该用其各自的组件替换先前的组件
有 3 个 livewire 组件 UserIsExpired、UserIsActive 和 UserIsPending 以及每个组件对应的 3 个按钮。单击按钮时,它应该用其各自的组件替换先前的组件
I have used Laravel 10 with Livewire 3 and Turbolink.我已经使用Laravel 10与Livewire 3和Turbolink。 When
我有一个带有“存储”方法的 Laravel Controller 。即存储(请求 $request)。 对于 View ,我想嵌入一个 livewire 组件,然后利用 livewire 组件方法中现
在 laravel 7/livewire 1.3/alpinejs 2 项目中,我制作了 crud,当为了添加/编辑,我将 livewire.admin.app-news.form 包含在数据列表中(
我使用的是 laravel 8。 我在 RouteServiceProvider 中定义了 protected 命名空间: protected $namespace = 'App\Http\Contr
我正在使用 Laravel Livewire,这里我有 3 个表格显示在一页上,但问题是分页显示正确但不起作用(URL 更改为 http://127.0.0.1:8000/blogpost?EnPos
我想在更新父组件时刷新子组件,并且只有该组件的子组件应该更新,因为我想在页面的其他地方重用子组件。组件结构如下。UserShow.php class UserShow extends Componen
我可以将数据传递给组件,但在 Alpine js 的模态中,数据为空。 这是类: public $code, $products; public function getData($id)
我有2个livewire组件,第一个仅显示购物车的session变量,第二个只是在购物车中添加项目(一种非常原始的形式,带有sku,标题,价格和数量)。 这两个组件本身都可以正常工作。但是,当我从
我尝试通过 laravel 队列加载多个图像,如下所示: Controller : foreach ($this->imagenes as $pathGaleria) { $image
我想了解 Livewire 组件中的挂载和渲染方法有什么区别,因为我看到过这两种方法都用于定义变量初始状态的示例。例如,当您使用模型中的记录实例化一个变量时,“哪个位置是使用 ORM 语法加载数据的正
我尝试通过 laravel 队列加载多个图像,如下所示: Controller : foreach ($this->imagenes as $pathGaleria) { $image
我是一名优秀的程序员,十分优秀!