2012-05-14 101 views
0

爲什麼不通過此代碼讓我向上或向左移動?SDL x和y移動

while(quit == false) 
    { 


    apply_surface(0,0, back,screen); 
    apply_surface(playerx,playery,player, screen); 


    SDL_Flip(screen); 

     //While there's an event to handle 
     while(SDL_PollEvent(&event)) 
     { 
      if(event.type == SDL_KEYDOWN) 
      { 
       switch(event.key.keysym.sym) 
       { 
       case SDLK_UP:playery=playery-10; 
       case SDLK_DOWN:playery=playery+10; 
       case SDLK_LEFT:playerx=playerx-10; 
       case SDLK_RIGHT:playerx=playerx+10; 
       } 
      }  

回答

3

您需要在switch每個case後使用break否則執行「落空」的下一行,有可能取消你的動作(實際上SDLK_UPSDLK_LEFT是在消除發生的那些)

+1

是的,確實有效ty(在我問之前,真的需要更加小心和閱讀) – yorde