Subject:
不用Gif控件,尽量实现动画(大家有没有更好的办法)
[Print This Page]
Author:
guoqingaa
Time:
2007-11-17 20:38
Subject:
不用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
http://bbs.cnpack.org/attachment.php?aid=358
Author:
skyjacker
Time:
2007-11-20 10:30
动画效果不错.
为了方便懒得下载的弟兄们, 我把你的代码贴出来吧
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.
Author:
skyjacker
Time:
2007-11-20 10:59
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));
想 所想即所得真不容易啊
Author:
Passion
Time:
2007-11-20 12:36
这种法子用来播放图片倒是可以,但图片岂不还得一帧一帧的去做?准备素材就比较麻烦。
Author:
kendling
Time:
2007-11-21 16:16
对哇,如果换作是gif图片的话,你还得分解出来呢。
Author:
zzzl
Time:
2007-11-21 22:24
这方法我也用过
Welcome to CnPack Forum (http://bbs.cnpack.org/)
Powered by Discuz! 5.0.0