2017-09-25 5 views
1

私は初めて質問します。私はPythonで "Alien Invasion"と呼ばれるゲームを作っています。 "Play"をクリックすると、それはwork.Iはこのエラーを取得し続けるdoes't:pygame: 'Group'オブジェクトには 'rect'という属性はありません

Traceback (most recent call last): 
    File "alien_invasion.py", line 30, in <module> 
    File "alien_invasion.py", line 24, in run_game 
    Flie "D:\python_work\alien_invasion\game_function.py", line 38, in check_events 
    Flie "D:\python_work\alien_invasion\game_function.py", line 41, in check_play_button 
AttributeError:'Group' object has no attribute 'rect' 

これはgame_functionについての私のコードです:

私はなぜこれが起こっているかを知りたい
def check_events(ai_settings,stats,play_button,screen,ship,aliens,bullets): 
    for event in pygame.event.get(): 
     if event.type==pygame.QUIT: 
      sys.exit() 
     elif event.type==pygame.KEYDOWN: 
      check_keydown_events(event,ai_settings,screen,ship,bullets)   
     elif event.type==pygame.KEYUP: 
      check_keyup_events(event,ship) 
     elif event.type==pygame.MOUSEBUTTONDOWN: 
      mouse_x,mouse_y=pygame.mouse.get_pos() 
      check_play_button(ai_settings,screen,ship,aliens,bullets,stats,play_button,mouse_x,mouse_y) 

def check_play_button(ai_settings,screen,stats,play_button,ship,aliens,bullets,mouse_x,mouse_y): 
    button_clicked=play_button.rect.collidepoint(mouse_x,mouse_y) 
    if button_clicked and not stats.game_active: 
     pygame.mouse.set_visible(False) 
     stats.reset_stats() 
     stats.game_active=True 
     aliens.empty() 
     bullets.empty() 
     create_fleet(ai_settings,screen,ship,aliens) 
     ship.center_ship() 

や方法についてit.Thanksを修正するにはあなたの助け。

答えて

1

引数を間違った順序で渡しています。彼らは、関数定義と同じ順序である必要があります:あなたは四番目の引数として、明らかにスプライト基であり、aliensを渡すため

check_play_button(ai_settings,screen,stats,play_button,ship,aliens,bullets,mouse_x,mouse_y) 

エラーが発生しました。次にcheck_play_button関数では、このaliensグループはローカル変数play_buttonに割り当てられ、rect属性がないため、AttributeErrorが生成されます。

+0

ありがとうございます。それは動作します! – Christine

関連する問題