2012-02-19 12 views
2

私と私の友達はプロジェクトに取り組んでいます。正確なゲーム。そして、我々はゲームプレイを破壊する大きな問題に遭遇しました。プレーヤーの透明部分は黒でなければなりません。SDL on blit、透明度を失って黒くなる

MergeSurfaces関数は、blitです。 rect自体はSDL_Rectに書き込まれ、blitが実行されます。

void MergeSurfaces(SDL_Surface *From, SDL_Surface *To, int FromX, int FromY, int FromWidth, int FromLenght, int ToX, int ToY){ 




      SDL_Rect srcRect;  
      srcRect.x = FromX;  
      srcRect.y = FromY; 
      srcRect.w = FromWidth; 
      srcRect.h = FromLenght; 

      SDL_Rect dstRect;  
      dstRect.x = ToX;  
      dstRect.y = ToY;  

      SDL_BlitSurface(From, &srcRect, To, &dstRect); 
     } 

これはプレーヤ形成機能です。

//------------------------------------------------------------------------------------------ 
//----MAIN LOAD FUNCTION 
//------------------------------------------------------------------------------------------  

    void LoadPlayerGraphics(SDL_Surface* BodyID[], int PlayerHeight, int PlayerWidth, long EquipmentID[], int MovementAmountX, int MovementAmountY){ 
     SDL_Surface* Image; 
     SDL_Surface* EquipmentColorization; 
     std::string FileName; 
     int ID; 


     Clean(BodyID,MovementAmountX*MovementAmountY,PlayerWidth,PlayerHeight); 


     for(int i = -1; i < 8; i++){ 
      ID = 0; 
      //here we put a small exception to firstly load the player. And only then dress Him 
      if(i == -1){ 
       FileName = "resource/images/Player/WhiteMaleBody.png"; 
       goto playerbody; 
      } 
      if(EquipmentID[i] != 0){ 
       GetFileNameByID(EquipmentID[i],FileName); 
      playerbody: 
       Image = IMG_Load(FileName.c_str()); 
       if(Image == NULL){ 
        exit(1); 
       } 

       //Needed for equipment coloring. At this point we will put RGB masks in order to color the armor by it's type 
       EquipmentColorization = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA, MovementAmountX*PlayerWidth, MovementAmountY*PlayerHeight, 32, 0, 0, 0, 0); 


       GraphicsFunctions.MergeSurfaces(Image,EquipmentColorization,0,0,MovementAmountX*PlayerWidth,MovementAmountY*PlayerHeight,0,0); 

       for(int i = 0; i < MovementAmountY; i++){ 
        for(int j = 0; j < MovementAmountX; j++){ 
         ID++; 
         //We put the graphics on and on on top. So we dress the frames. BodyID[ID] are frames by motion ID. We just fill this up. 
         GraphicsFunctions.MergeSurfaces( EquipmentColorization,BodyID[ID], 
                  (j * PlayerWidth), 
                  (i * PlayerHeight), 
                  PlayerWidth,PlayerHeight, 
                  0,0); 

         if(BodyID[i] == NULL){ 
          exit(2); 
         } 
        } 
       } 
      } 

     } 
    } 

あなたが何をしているのだろうか?私はまだここの表面を解放しない。私はプログラムの終わりにそれをやるので、これはこれまでに一度読み込まれます。したがって、基本的には、それらのサーフェスを埋めるためにサーフェスを作成するだけです。

void Clean(SDL_Surface* TheSurface[], int MovementAmount, int PlayerWidth, int PlayerHeight){ 
     GraphicsFunctions.Setrgba(); 
     for(int i = 0; i <= MovementAmount; i++){ 
      TheSurface[i] = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA, PlayerWidth, PlayerHeight, 32, 0, 0, 0, 0); 
     } 
    } 

次は、フレーミング部分に移動するか、文字が動いているように見えるようにします。他の場所で呼ばれているので、速度を簡単に制御できます。

void Variate(SDL_Surface* Graphical_Output){ 
     GraphicsFunctions.MergeSurfaces(BodyID[MovementVariationID[MovementID][Variation]], Graphical_Output, 0, 0, PlayerWidth, PlayerHeight, 0, 0); 
     Variation++; 
     if(Variation == MovementVariationIn[MovementID]){ 
      Variation = 0; 
     } 
    } 

ここにメインスレッドコントロールがあります。メインシステムのスレッド、Blits、そしてここに見えるものを表面に反転させます。

//------------------------------------------------------------------------------------------ 
//----MAIN Thread Function (As Thread Repeat to infinity LOL) 
//------------------------------------------------------------------------------------------ 
    int Player_Main(void *unused){ 

     GraphicsFunctions.Setrgba(); 
     PlayerGraphics = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA, 1024, 768, 32, GraphicsFunctions.r, GraphicsFunctions.g, GraphicsFunctions.b, GraphicsFunctions.a); 
     while(!EndProgram){ 

      PlayerMovementGraphics::Variate(PlayerGraphics); 

      SDL_Delay(200); 
     } 
     return 0; 
    } 

もちろん、ここで実装する必要がある改善点があります。しかし、私はわずか数週間前にSDLに取り組み始めて以来です。私はまだ多くのことを学ぶ必要があります。これは基本的にはグラフィックスのあるところです。だから、なぜあなたは透明でなければならないのか、プレーヤー自体が黒くなっている理由を検出することができます。

答えて

3

あなたが書く:documentationから

SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA, 
         PlayerWidth, PlayerHeight, 
         32, 0, 0, 0, 0); 

:RGBマスクのためのゼロを使用し

は深さに基づいて、デフォルト値を設定します。しかし、あなたはアルファチャンネルが必要な場合は、明示的にマスクを指定する必要があります0

AmaskAmask結果を得るためにゼロを使用して:

SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA, 
         PlayerWidth, PlayerHeight, 32, 
         0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); 
関連する問題