象打游戏那样,鼠标到达屏幕右边上,图往坐移动,到上往下移动(50分)

  • 主题发起人 主题发起人 dyxhy2003
  • 开始时间 开始时间
D

dyxhy2003

Unregistered / Unconfirmed
GUEST, unregistred user!
顺便给注释,谢谢各位
 
不太明白意思,自己判断鼠标的位置然后操作就可以了
 
在的move中根据X、Y设置图片的top,left阿
 
我知道判断,要代码啊
 
你也可以把图像放在TBitmap中,再放TImage控件显示图.移动鼠标时你只要用Image1.Canvas.BrushCopy重画TBitmap的一部份图就好了.
 
代码啊,!
 
难道没有人会,还是分少啊?我是新手,czcn你说的我不太懂,给代码啊
 
给你举个例子:
比如有一张很大的图,就10000*10000的吧
你的窗口大小1024*768
首先:首先建立一个内存的canvas,窗口的canvas为canvas
MemoryCanvas:=TCanvas.Create;
MemoryCanvas.Handle:=CreateCompatibleDC(Canvas.Handle);
MapBitmap:=TBitmap.Create;//你的地图
//加载图片到mapbitmap中,游戏的背景地图
......................自己完成
//绘制其他的东西,比如人物,树木等游戏中的东西到内存canvas中
......................自己完成
//将地图选中到你的内存canvas中
OldBitmapHDC:=SelectObject(MemoryCanvas.Handle,MemoryBitmap.Handle);

下一步:拷贝内存canvas到窗口的canvas中
BitBlt(Canvas.Handle,0,0,
1024,768,
MemoryCanvas.Handle,MapX,MapY,SRCCOPY);
MapX,MapY为地图左上角在屏幕上的坐标

最后:一定要释放资源,还原设备上下文
..................自己完成
 
分的确是少了一些,呵呵
 
OldBitmapHDC:=SelectObject(MemoryCanvas.Handle,MemoryBitmap.Handle);
更正为
OldBitmapHDC:=SelectObject(MemoryCanvas.Handle,MapBitmap.Handle);
 
在网上看了这个,是用鼠标按下来移动的!我是想想打游戏那样,比如在MOUSEMOVE下面当Y《=9 的时候,图往下移动[而不是用鼠标来拖动],另三个方向也一样


unit Unit1;

interface

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

type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Image1: TImage;
Label1: TLabel;
Button1: TButton;
procedure Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Label1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
origin:Tpoint;
image_left:integer;
image_top:integer;
visa1:Tpoint; {鼠标当前位置相对图像右下角的坐标}
visa2:Tpoint; {鼠标当前位置相对图像左上角的坐标}
canmove:boolean;
implementation

{$R *.DFM}



procedure TForm1.Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if canmove then
begin
if X< visa1.x then X:=visa1.x;
if X>visa2.x then X:=visa2.x;
if Y< visa1.y then Y:=visa1.y;
if Y>visa2.y then Y:=visa2.y;
image1.left:=image_left+(X-origin.x);
image1.top:=image_top+(Y-origin.y);
end;
end;


procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button=mbLeft then
begin
origin.x:=X;
origin.y:=Y;
image_left:=image1.left;
image_top:=image1.top;
visa1.x:=X-(image1.width-panel2.width+image1.left);
visa1.y:=Y-(image1.height-panel2.height+image1.top);
visa2.x:=X-image1.left;
visa2.y:=Y-image1.top;
canmove:=true;
end;
end;

procedure TForm1.Label1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
canmove:=false;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;

end.
 
后退
顶部