如何让多个人同时出现?
easyx吧
全部回复
仅看楼主
level 7
白芦花 楼主
if (间隔()) {
cleardevice();
putimage(x, 100, &mm[n++]);
}
2024年12月08日 01点12分 1
level 7
白芦花 楼主
资源
2024年12月08日 01点12分 2
level 7
你这问题也太模糊了
2024年12月08日 06点12分 3
level 7
如果你是想要同时绘制多个人,你可以把帧动画封装起来,有几个人就创建几个
2024年12月08日 06点12分 4
对对,同时绘制多个人,象字符雨哪样,有不同速度的人出现
2024年12月08日 10点12分
对对,同时绘制多个人,象字符雨哪样,有不同速度的人出现
2024年12月08日 10点12分
@白芦花 你可以写个结构或者类,里面要有移动速度,坐标,和每一帧的图片指针,还有用于绘制当前图片的下标
2024年12月08日 10点12分
@白芦花 图片资源可以另外用一个资源管理器存储,传递指针给上面那个类就行
2024年12月08日 10点12分
level 7
白芦花 楼主
int main(int argc, char *argv[])
{
Init();
loadResource();
BeginBatchDraw();
printf("行走:\n");
int n = 0, x = 0;
int n1 = 0, x1 = 0;
C间隔 ct0(.2); C间隔 ct1(.3);
while (1)
{
cleardevice();
//1
putimage(x, 100, &mb[n], NOTSRCERASE);
putimage(x, 100, &mm[n], SRCINVERT);
if (ct0.间隔()) {
x += 30; if (x > 400)x = 0;
n++; if (n == 8)n = 0;
}
//2
putimage(x1, 100, &mb[n1], NOTSRCERASE);
putimage(x1, 100, &mm[n1], SRCINVERT);
if (ct1.间隔()) {
x1 += 30; if (x1 > 400)x1 = 0;
n1++; if (n1 == 8)n1 = 0;
}
FlushBatchDraw();
}
EndBatchDraw();
return 0;
}
2024年12月08日 23点12分 5
level 7
你可以创建一个结构体
struct {
int delta_ms;//每帧的间隔时间
int time_ms;//当前过去的时间
int frameIndex;//当前帧下表
int frameCount;//帧总数
IMAGE *frames;//帧数组
}
2024年12月09日 02点12分 6
根据以上的结构体,你需要几个就创建几个这样的结构体并初始化好,在主循环更新的时候,把时间加上去,判断一下是否切换下一帧。渲染的时候就通过那个下标和帧动画数组来获取当前绘制的帧图片,另外,你可以通过AlphaBlend,来实现只用一张带有透明通道的图片绘制透明通道
2024年12月09日 02点12分
可以把这个结构体命名成Animation,在需要以下几个函数 void animation_init(); void animation_update(int ms); IMAGE* animation_get_frame();
2024年12月09日 02点12分
@内个小谁 这三个函数完成上面这个结构体的实例的初始化,切换帧动画逻辑,和获取当前应该渲染的图片
2024年12月09日 02点12分
按你说的做了,在9楼
2024年12月09日 11点12分
level 7
白芦花 楼主
int main(int argc, char *argv[])
{
Init();
loadResource();
BeginBatchDraw();
printf("行走:\n");
int n = 0, x = 0;
int n1 = 0, x1 = 0;
int n2 = 0, x2 = 0;
C间隔 ct0(.5); C间隔 ct1(.3); C间隔 ct2(.7);
while (1)
{
cleardevice();
//1
putAlphaImage(x, 100, &mm[n], 0);
if (ct0.间隔()) {
x += 30; if (x > WIDTH)x = 0;
n++; if (n == 7)n = 0;
}
//2
putAlphaImage(x1, 200, &mm[n1], 0);
if (ct1.间隔()) {
x1 += 30; if (x1 > WIDTH)x1 = 0;
n1++; if (n1 == 6)n1 = 0;
}
//3
putAlphaImage(x2, 300, &mm[n1], 0);
if (ct2.间隔()) {
x2 += 30; if (x2 > WIDTH)x2 = 0;
n2++; if (n2 == 6)n2 = 0;
}
FlushBatchDraw();
Sleep(1);
}
EndBatchDraw();
return 0;
}
2024年12月09日 08点12分 7
level 7
白芦花 楼主
换了一个图
2024年12月09日 09点12分 8
level 7
白芦花 楼主
struct Animation
{
//int delta_ms;//每帧的间隔时间
double delta;
//int time_ms;//当前过去的时间
clock_t time;//上一帧开始时间
int frameIndex;//当前帧下标
int frameCount;//帧总数
IMAGE *frames;//帧数组
Animation(IMAGE *im,int n)
{
frames = im; frameCount = n;
}
void animation_init(double delt)
{
delta = delt;
time= clock();
frameIndex = 0;
}
//void animation_update();
IMAGE* animation_get_frame(bool &next)
{
double dt = (double)(clock() - time) / CLOCKS_PER_SEC;
if (dt > delta)
{
frameIndex++;
if (frameIndex == frameCount - 1)frameIndex = 0;
time = clock();
next = true;
}
else
next = false;
return frames + frameIndex;
}
};
int main(int argc, char *argv[])
{
Init();
loadResource();
BeginBatchDraw();
printf("行走:\n");
Animation a0(&mm[0], 6);Animation a1(&mm[0], 6);
a0.animation_init(0.2);a1.animation_init(.3);
XY xy0(0, 0, 20, 0, WIDTH, HEIGHT);
XY xy1(200, 200, 0, 30, WIDTH, HEIGHT);
point xyo0(1,1); point xyo1(1, 1);
while (1)
{
cleardevice();
//1
bool next = false;
IMAGE *im = a0.animation_get_frame(next);
if (next)
{
xy0.update();
point xy = xy0.getxy();
xyo0 = xy;
}
putAlphaImage(xyo0.x, xyo0.y, im, 0);
//2
im = a1.animation_get_frame(next);
if (next)
{
xy1.update();
point xy = xy1.getxy();
xyo1 = xy;
}
putAlphaImage(xyo1.x, xyo1.y, im, 0);
FlushBatchDraw();
Sleep(1);
}
EndBatchDraw();
return 0;
}
2024年12月09日 11点12分 9
看来你已经理解面向对象了
2024年12月09日 14点12分
level 7
2024年12月09日 15点12分 11
你还可以添加一个是否可以循环的布尔变量,如果不可以循环,帧动画达到末尾时帧下表不会再改变,会一直处于最后一帧的状态
2024年12月09日 15点12分
再者,你还可以给一个对象创建多个Animation,通过一个状态机来切换Animation
2024年12月09日 15点12分
@内个小谁 是不是这样?看下一楼
2024年12月10日 00点12分
level 7
白芦花 楼主
int main(int argc, char *argv[])
{
Init();
loadResource();
BeginBatchDraw();
printf("行走:\n");
Animation a0(&mm[0], 6);Animation a1(&mm[0], 6);
a0.animation_init(0.2);
XY xy0(0, 0, 20, 0, WIDTH, HEIGHT);
XY xy1(200, 200, 0, 30, WIDTH, HEIGHT);
point xyo0(1, 1); point xyo1(1, 1);
while (1)
{
cleardevice();
//1
bool next = false;
IMAGE *im = a0.animation_get_frame(next);
if (next)
{
xy0.update();
point xy = xy0.getxy();
xyo0 = xy;
}
//一个对象创建多个Animation,通过一个状态机来切换Animation
for (int i = 0; i < 5; i++)
{
putAlphaImage(xyo0.x, i*125, im, 0);
}
if (next)
{
xy1.update();
point xy = xy1.getxy();
xyo1 = xy;
}
for (int i = 0; i < 5; i++)
{
putAlphaImage(i * 125, xyo1.y, im, 0);
}
FlushBatchDraw();
Sleep(1);
}
EndBatchDraw();
return 0;
}
2024年12月10日 00点12分 12
切换的时候要调用初始化
2024年12月10日 00点12分
@内个小谁 感谢你的指导
2024年12月10日 05点12分
level 7
白芦花 楼主
for (int i = 0; i < 5; i++)
{
putAlphaImage(i * 125, xyo1.y - 125, im, 0);
putAlphaImage(i * 125, xyo1.y, im, 0);
putAlphaImage(i * 125, xyo1.y + 125, im, 0);
}
2024年12月10日 00点12分 13
1