Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения
KANSoftWare

Реализация анимации без мерцания

Delphi , Графика и Игры , Графика

Реализация анимации без мерцания

Оформил: DeeCo
Автор: http://www.swissdelphicenter.ch

{ 
 You will need an image, called ImageSprite, containing a sprite bitmap with 
 black as the background (the transparent part). You will also need an image, 
 called ImageMask, containing a black silouette of the sprite with white as the 
 background and an Image called ImageBackground containing the background 
 image. All these images are set to visible := false. Image1 is the image you 
 will see and is the same size as the background image. 
}

 // Global variables 
var
   Form1: TForm1;
   x, y, xvel, yvel, xold, yold: integer;

 implementation

 {$R *.dfm}

 procedure TForm1.Button1Click(Sender: TObject);
 var
   ARect: TRect; // Destination/Source rectangles 
begin
   // Initialize sprites position/velocity 
  x := 0;
   y := 0;
   xvel := 2;
    yvel := 2;
   xold := 0;
    yold := 0;

   // copy background to the image 
  ARect := Rect(0, 0, ImageBackground.Width, ImageBackground.Height);
   with Image1.Canvas do
    begin
     CopyMode := cmSrcCopy;
     CopyRect(ARect, ImageBackground.Canvas, ARect);
   end;

   // start animation 
  Timer1.Enabled := True;
 end;

 procedure TForm1.Timer1Timer(Sender: TObject);
 var
   Dest, Sour: TRect; // Destination/Source rectangles 
begin
   // Erase sprite from old position 
  Sour := Rect(xold, yold, xold + ImageMask.Width, yold + ImageMask.Height);
   with Image1.Canvas do
    begin
     CopyMode := cmSrcCopy;
     CopyRect(Sour, ImageBackground.Canvas, Sour);
   end;

   // Draw new sprite 
  Sour := Rect(0, 0, ImageMask.Width, ImageMask.Height);
   Dest := Rect(x, y, x + ImageMask.Width, y + ImageMask.Height);
   with Image1.Canvas do
    begin
     // Place mask onto image 
    CopyMode := cmSrcAnd;
     CopyRect(Dest, ImageMask.Canvas, Sour);
     // Place sprite into mask 
    CopyMode := cmSrcPaint;
     CopyRect(Dest, ImageSprite.Canvas, Sour);
   end;

   { 
   if multiple sprites are being used, then erase them all before drawing them 
   all. Do not erase and draw each sprite in turn 
  }

   // store sprites old position before updating 
  xold := x;
   yold := y;

   // Update sprites position (equations to describe movement of sprite) 
  Inc(x, xvel);
   Inc(y, yvel);
   if x >= ImageBackground.Width then x := -ImageMask.Width;
   if y >= ImageBackground.Height then y := -ImageMask.Height;
 end;

Статья Реализация анимации без мерцания раздела Графика и Игры Графика может быть полезна для разработчиков на Delphi и FreePascal.


Комментарии и вопросы


Ваше мнение или вопрос к статье в виде простого текста (Tag <a href=... Disabled). Все комментарии модерируются, модератор оставляет за собой право удалить непонравившейся ему комментарий.

заголовок

e-mail

Ваше имя

Сообщение

Введите код




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: Графика ::


реклама



©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru Rambler's Top100
19.04.2024 11:17:06/0.036556959152222/2