0

为什么这段代码不能让我向上或向左移动?

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;
                }
            }       
4

1 回答 1

3

您需要break在每个之后case使用aswitch 否则执行“失败”到下一行,可能会取消您的操作(实际上SDLK_UP并且SDLK_LEFT是发生取消的操作)

于 2012-05-14T15:33:01.077 回答