好友
阅读权限30
听众
最后登录1970-1-1
|
用C++写的,原理就是一张一张的图,动态的贴,形成动画,判断移动方向,切换不同的动画,原图在贴子上有出现过,贴图时需要计算图片的坐标,最后窗体透明,就可以了,跟着鼠标跑就简单了,得到鼠标的坐标,然后移动时改变窗口的坐标就可以了
图的大小:上下64X86左右106X82
部分代码:
//cat.c
#include <vcl.h>
#include "Cat.h"
#include "Unit1.h"
_CatControl::_CatControl()
{
frame.UP =0;
frame.DOWN =0;
frame.LEFT=0;
frame.RIGHT =0;
frame.maxUPDOWN =6;
frame.maxLEFTRIGHT =5;
moveSpeed=25;
}
_CatControl::~_CatControl()
{
}
void _CatControl::Cat_Move(int direction)
{
catfrm->imgcat->Canvas->FillRect(catfrm->imgcat->ClientRect);
switch(direction)
{
//向上移动
case 0:
{
BitBlt(catfrm->imgcat->Canvas->Handle,0,0,64,86,catfrm->imgpic->Canvas->Handle,frame.UP*64,0,SRCCOPY);
frame.UP++;
if (frame.UP >=6)
{
frame.UP=0;
}
catfrm->Top-=moveSpeed;
break;
}
//向下移动
case 1:
{
BitBlt(catfrm->imgcat->Canvas->Handle,0,0,64,86,catfrm->imgpic->Canvas->Handle,frame.DOWN*64,86,SRCCOPY);
frame.DOWN++;
if (frame.DOWN >=6)
{
frame.DOWN=0;
}
catfrm->Top+=moveSpeed;
break;
}
//向左移动
case 2:
{
BitBlt(catfrm->imgcat->Canvas->Handle,0,0,106,82,catfrm->imgpic->Canvas->Handle,frame.LEFT*106,86*2,SRCCOPY);
frame.LEFT++;
if (frame.LEFT >=5)
{
frame.LEFT=0;
}
catfrm->Left-=moveSpeed;
break;
}
//向右移动
case 3:
{
BitBlt(catfrm->imgcat->Canvas->Handle,0,0,106,82,catfrm->imgpic->Canvas->Handle,frame.RIGHT*106,86*2+82,SRCCOPY);
frame.RIGHT++;
if (frame.RIGHT >=5)
{
frame.RIGHT=0;
}
catfrm->Left+=moveSpeed;
break;
}
}
}
//cat.h
#ifndef CATCONTROL_H_
#define CATCONTROL_H_
struct _Frame
{
int UP; //动画到第几帧
int DOWN;
int LEFT;
int RIGHT;
int maxUPDOWN;//上下,最大帧数
int maxLEFTRIGHT;
};
class _CatControl
{
public:
_CatControl();
~_CatControl();
_Frame frame;
void Cat_Move(int direction);//移动,只有一个参数,移动方向 0:上,1:下,2:左,3:右
private:
int moveSpeed;//移动速度
};
#endif //CATCONTROL_H_
贴图类都在这里了
|
免费评分
-
查看全部评分
|