CnPack Forum


 
Subject: 不用Gif控件,尽量实现动画(大家有没有更好的办法)
guoqingaa
新警察
Rank: 1



UID 17107
Digest Posts 0
Credits 45
Posts 10
点点分 45
Reading Access 10
Registered 2007-6-10
Status Offline
Post at 2007-11-17 20:38  Profile | Blog | P.M. 
不用Gif控件,尽量实现动画(大家有没有更好的办法)

翻了翻书,想写个小动画,让自己的程序更生动,贴点给大家看看,看看大家有没有更好的办法,我个人觉得暂时理想吧
核心代码
//imgSource 保存16张连续图(自己用画图加工的),imgRuning 使用Canvas.CopyRect()的方法显示
begin
  imgRuning.Canvas.CopyRect(Rect(0,0,220,64), imgSource.Canvas, Rect(Tag*220, 0, Tag*220+220, 64));
  if tag=16 then {动作状态编号从零开始,一共有16个状态}
  tag := 0
  else
  tag := tag+1; {用表单的tag属性表示动作状态,初始值为0}
  imgRuning.refresh; {刷新图像}
end;

去除抖动

  imgRuning.parent.doublebuffered := true;

效果



顺便贴个图,跟个附加...这样发稿可以吧...


Attachment: [例子] demo.rar (2007-11-17 20:38, 201.81 K)
Download count 530
Top
skyjacker
版主
Rank: 7Rank: 7Rank: 7
茶农


UID 2239
Digest Posts 9
Credits 617
Posts 269
点点分 617
Reading Access 100
Registered 2006-6-8
Status Offline
Post at 2007-11-20 10:30  Profile | Blog | P.M.  | QQ
动画效果不错.
为了方便懒得下载的弟兄们, 我把你的代码贴出来吧


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    imgSource: TImage;
    btnStart: TButton;
    imgRuning: TImage;
    imgStop: TImage;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnStartClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.Timer1Timer(Sender: TObject);
begin

  imgRuning.Canvas.CopyRect(Rect(0,0,220,64), imgSource.Canvas, Rect(Tag*220, 0, Tag*220+220, 64));

  if tag=16 then {动作状态编号从零开始,一共有16个状态}
  tag := 0
  else
  tag := tag+1; {用表单的tag属性表示动作状态,初始值为0}

  imgRuning.refresh; {刷新图像}
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  imgRuning.parent.doublebuffered := true;
//  就不闪了 那是刷屏率,
end;

procedure TForm1.btnStartClick(Sender: TObject);
begin
  if Timer1.Enabled then
    begin
      Timer1.Enabled := False;
      imgStop.Visible          := True;
      imgRuning.Visible  := False;
      btnStart.Caption := '继续...';
    end
  else
    begin
      Timer1.Enabled := True;
      imgRuning.Visible  := True;
      imgStop.Visible := False;
      btnStart.Caption := '暂  停';
    end;
end;

end.




一壶清茶煮青春.
Top
skyjacker
版主
Rank: 7Rank: 7Rank: 7
茶农


UID 2239
Digest Posts 9
Credits 617
Posts 269
点点分 617
Reading Access 100
Registered 2006-6-8
Status Offline
Post at 2007-11-20 10:59  Profile | Blog | P.M.  | QQ
procedure TForm1.Timer1Timer(Sender: TObject);
var
  Delta: Integer;
begin
  // Rect(Tag*220, 0, Tag*220+220, 64)); 动画
  // Rect(Tag*(220 div 16), 0, 220, 64) 拉伸效果
  // Rect(Tag*13, 0, Tag*13+220, 64) 滚动效果

  Delta := 230;
  imgRuning.Canvas.CopyRect(Rect(0,0,220,64), imgSource.Canvas, Rect(Tag*Delta, 0, Tag*Delta+220, 64));


想 所想即所得真不容易啊




一壶清茶煮青春.
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2007-11-20 12:36  Profile | Blog | P.M. 
这种法子用来播放图片倒是可以,但图片岂不还得一帧一帧的去做?准备素材就比较麻烦。
Top
kendling (小冬)
高级版主
Rank: 8Rank: 8
MyvNet


Medal No.1  
UID 703
Digest Posts 5
Credits 978
Posts 580
点点分 978
Reading Access 101
Registered 2005-2-18
Location 广东
Status Offline
Post at 2007-11-21 16:16  Profile | Site | Blog | P.M.  | QQ | Yahoo!
对哇,如果换作是gif图片的话,你还得分解出来呢。




小冬
http://MyvNet.com
Top
zzzl (早安的空气)
版主
Rank: 7Rank: 7Rank: 7



UID 590
Digest Posts 0
Credits 399
Posts 199
点点分 399
Reading Access 100
Registered 2004-11-29
Status Offline
Post at 2007-11-21 22:24  Profile | Blog | P.M.  | QQ
这方法我也用过
Top
 




All times are GMT++8, the time now is 2024-11-22 09:07

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.014246 second(s), 10 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP