Thema: Delphi [DelphiX] Phantom Sprite

Einzelnen Beitrag anzeigen

Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#1

[DelphiX] Phantom Sprite

  Alt 22. Aug 2006, 16:53
Hi,

Also mir ist grad was seltsames passiert.
Ich wollte mir eine DXButton Klasse machen.

Hier ist sie:

Delphi-Quellcode:
  TSpriteButton = class
   private
    FSprite: TImageSprite;
    FTop: Single;
    FLeft: Single;
    FCaption: String;
    FFont: TFont;
    FPicture: TPictureCollectionItem;
    FHeight: Word;
    FWidth: Word;
    procedure SetCaption(const Value: String);
    procedure SetFont(const Value: TFont);
    procedure SetHeight(const Value: Word);
    procedure SetLeft(const Value: Single);
    procedure SetPicture(const Value: TPictureCollectionItem);
    procedure SetTop(const Value: Single);
    procedure SetWidth(const Value: Word);
   public
    constructor Create(Engine: TSprite; APicture: TPictureCollectionItem);
    property Left: Single read FLeft write SetLeft;
    property Top: Single read FTop write SetTop;
    property Width: Word read FWidth write SetWidth;
    property Height: Word read FHeight write SetHeight;
    property Image: TPictureCollectionItem read FPicture write SetPicture;
    property Font: TFont read FFont write SetFont;
    property Caption: String read FCaption write SetCaption;
  end;
So.. Das eine Problem ist halt das ich in SetCaption die Caption auf das Bild des Sprites malen will. Aber nicht nur das das nicht funktioniert, das Sprite bewegt sich auch noch o.O
Aber das ist nicht alles. Die Koordinaten des Sprites bleiben unverändert
Wie kann das sein? Das Sprite malt nicht sondern verschiebt sich wobei nichtmal die Koordinaten geändert werden o.Ô.

Hier mal die SetCaption Procedure:

Delphi-Quellcode:
procedure TSpriteButton.SetCaption(const Value: String);
begin
  FCaption := Value;
  with FSprite.Image.Picture.Bitmap.Canvas do
  begin
   TextOut((Width div 2) + (FSprite.Image.Picture.Bitmap.Canvas.TextWidth(Value) div 2),
           (Height div 2) + (FSprite.Image.Picture.Bitmap.Canvas.TextHeight(Value) div 2),
            Value);
  end;
end;
Aufruf:
Delphi-Quellcode:
procedure TfrmMain.DXDraw1Click(Sender: TObject);
begin
  B.Caption := 'HALLO';
end;
Gruß
Neutral General
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat