如何解决为什么我得到了一个意想不到的关键字参数“calculate_hit_box”
我正在尝试制作纸牌游戏,但出于某种原因,我每次运行代码时都会遇到意外的关键字参数“calculate_hit_Box”错误
import arcade
# Screen title and size
SCREEN_WIDTH = 1024
SCREEN_HEIGHT = 768
SCREEN_TITLE = "Bahraini Deal"
# Constants for sizing
CARD_SCALE = 0.6
# How big are the cards?
CARD_WIDTH = 140 * CARD_SCALE
CARD_HEIGHT = 190 * CARD_SCALE
# How big is the mat we'll place the card on?
MAT_PERCENT_OVERSIZE = 1.25
MAT_HEIGHT = int(CARD_HEIGHT * MAT_PERCENT_OVERSIZE)
MAT_WIDTH = int(CARD_WIDTH * MAT_PERCENT_OVERSIZE)
# How much space do we leave as a gap between the mats?
# Done as a percent of the mat size.
VERTICAL_MARGIN_PERCENT = 0.10
HORIZONTAL_MARGIN_PERCENT = 0.10
# The Y of the bottom row (2 piles)
BottOM_Y = MAT_HEIGHT / 2 + MAT_HEIGHT * VERTICAL_MARGIN_PERCENT
# The X of where to start putting things on the left side
START_X = MAT_WIDTH / 2 + MAT_WIDTH * HORIZONTAL_MARGIN_PERCENT
# Card constants
CARDS_NAMES = ["City_Center_1","Clock_Roundabout_1","Extra_Play_1","Its_Friday_1","Just_Say_No_1","Pay_Me_Rent_BlackGray_1","Pay_Me_Rent_brownBlue_1","Pay_Me_Rent_GreenPurple_1","Pay_Me_Rent_PinkOrange_1","Pay_Me_Rent_RedYellow_1","Pay_Me_Rent_Mix_1","Shake_Pockets_1","Social_Housing_1","Two_More_Cards_1","World_Trade_Center_1","Zallaq_Sofitel_1"]
CARDS_VALUE = {"City_Center_1" : 4,"Clock_Roundabout_1" : 3,"Extra_Play_1" : 2,"Its_Friday_1":2,"Just_Say_No_1":4,"Pay_Me_Rent_BlackGray_1":1,"Pay_Me_Rent_brownBlue_1":1,"Pay_Me_Rent_GreenPurple_1":1,"Pay_Me_Rent_PinkOrange_1":1,"Pay_Me_Rent_RedYellow_1":1,"Pay_Me_Rent_Mix_1":3,"Shake_Pockets_1":3,"Social_Housing_1":2,"Two_More_Cards_1":1,"World_Trade_Center_1":4,"Zallaq_Sofitel_1":5}
class Card(arcade.Sprite):
""" Card sprite """
def __init__(self,name,scale=1):
""" Card constructor """
# Attributes for suit and value
self.name = name
# Image to use for the sprite when face up
self.image_file_name = f":CardsFinal:images/{self.name}.png"
# Call the parent
super().__init__(self.image_file_name,scale,calculate_hit_Box=False)
class MyGame(arcade.Window):
""" Main application class. """
def __init__(self):
super().__init__(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_TITLE)
self.card_list = None
arcade.set_background_color(arcade.color.french_SKY_BLUE)
def setup(self):
""" Set up the game here. Call this function to restart the game. """
self.card_list = arcade.SpriteList()
# Create every card
for card_name in CARDS_NAMES:
for card_value in CARDS_VALUE:
card = Card(card_name,card_value,CARD_SCALE)
card.position = START_X,BottOM_Y
self.card_list.append(card)
def on_draw(self):
""" Render the screen. """
# Clear the screen
arcade.start_render()
# Draw the cards
self.card_list.draw()
def on_mouse_press(self,x,y,button,key_modifiers):
""" Called when the user presses a mouse button. """
pass
def on_mouse_release(self,x: float,y: float,button: int,modifiers: int):
""" Called when the user presses a mouse button. """
pass
def on_mouse_motion(self,dx: float,dy: float):
""" User moves mouse """
pass
def main():
""" Main method """
window = MyGame()
window.setup()
arcade.run()
if __name__ == "__main__":
main()
我尝试了多种方法来解决问题,但是在解决问题的过程中,我每次都把它弄得越来越乱,很明显问题出在calculate_hit_Box 上,但我不明白为什么?我尝试的每一个灵魂最终都会越来越混乱
解决方法
从 Arcade.Sprite source code 来看,它看起来不像 calculate_hit_box
是 Sprite
的 __init__
参数之一:
class Sprite:
def __init__(self,filename: str = None,scale: float = 1,image_x: float = 0,image_y: float = 0,image_width: float = 0,image_height: float = 0,center_x: float = 0,center_y: float = 0,repeat_count_x: int = 1,repeat_count_y: int = 1,flipped_horizontally: bool = False,flipped_vertically: bool = False,flipped_diagonally: bool = False,mirrored: bool = None,hit_box_algorithm: str = "Simple",hit_box_detail: float = 4.5):
# ...
也许它曾经在旧版 Arcade 中使用,这可以解释如果您在学习旧教程时的困惑。
,从此处删除 calculate_hit_box=False
:
super().__init__(self.image_file_name,scale,calculate_hit_box=False)
似乎 "Solitaire" tutorial 中存在错误。我为 arcade
库创建了一个 issue。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。