Einzelnen Beitrag anzeigen

Benutzerbild von igel457
igel457

Registriert seit: 31. Aug 2005
1.622 Beiträge
 
FreePascal / Lazarus
 
#10

Re: Benutzerdefinierte Spritefarben

  Alt 18. Jun 2007, 17:43
Ja, das kann man. Du musst die Sprites halt "vorrendern". Ich habe das so gemacht:

Delphi-Quellcode:
//Produces the Image (with hair color etc...)
procedure TCharacter.ProduceImage;
var x,y:integer;
    abmp:TBitmap;
    col,ncol:TColor;
    r,g,b:byte;

    //Makes a color daker
    function DarkColor(acolor:TColor;value:integer):TColor;
    var r,g,b:byte;
    begin
      r := cut(getrvalue(acolor)-value);
      g := cut(getgvalue(acolor)-value);
      b := cut(getbvalue(acolor)-value);
      result := rgb(r,g,b);
    end;
begin

  //Create Bitmap
  abmp := TBitmap.Create;
  abmp.PixelFormat := pf24Bit;

  //Get the Oringinals Bitmap (TFigurImage)
  original.GetAsBitmap(abmp);

  { TODO -oAll -cCode : Scanline }
  for x := 0 to abmp.Width-1 do
  begin
    for y := 0 to abmp.Height-1 do
    begin
      col := abmp.Canvas.Pixels[x,y];
      r := getrvalue(col);
      g := getgvalue(col);
      b := getbvalue(col);
      //Skin color. In the originals Bitmap the skin colors RGB Values are all the same --> gray/white
      if (r=g) and (r=b) then
      begin
        ncol := darkcolor(skincolor,255-r);
        abmp.Canvas.Pixels[x,y] := ncol;
      end;

      //Cloths color. In the originals Bitmap the clothes color is red (GB are not set)
      if (g=0) and (b=0) then
      begin
        ncol := darkcolor(clothescolor,255-r);
        abmp.Canvas.Pixels[x,y] := ncol;
      end;

      //Hair color. In the originals Bitmap the clothes color is yellow (B is not set) R and B is the same.
      if (b=0) and (r=g) then
      begin
        ncol := darkcolor(haircolor,255-r);
        abmp.Canvas.Pixels[x,y] := ncol;
      end;
    end;
  end;

  //Assing the new bitmap to the buffer
  figurimage.Assign(abmp);

  figurimage.transparentcolor := clFuchsia;
  figurimage.transparent := true;


  //Free all things
  abmp.Free;
end;
Andreas
"Sollen sich auch alle schämen, die gedankenlos sich der Wunder der Wissenschaft und Technik bedienen, und nicht mehr davon geistig erfasst haben als die Kuh von der Botanik der Pflanzen, die sie mit Wohlbehagen frisst." - Albert Einstein
  Mit Zitat antworten Zitat