zsh669 2021-12-26 12:08 采纳率: 87.5%
浏览 75
已结题

vs c语言绘制图像不断闪烁


#include <stdio.h>
#include <Windows.h>
#include <easyx.h>
#include <conio.h>
#include <time.h>
#include <graphics.h>
#include <stdlib.h>
#include <iostream>
#include<mmsystem.h>
#include<math.h>
IMAGE img_player;
IMAGE img_player1;
IMAGE img_monster1;
IMAGE img_monster2;
IMAGE img_food1;
IMAGE img_food2;
IMAGE img_food3;
IMAGE img_food4;
IMAGE img_food5;
IMAGE img_map;
struct Player {
    int x;
    int y;    //位置
    int dirx;
    int diry;     //移动方向
    unsigned long t1, t2, dt;       //控制速度
};
struct Player player, player1;

//定义敌人
struct Enemy {
    int x;
    int y;
    int dirx;
    int diry;
    unsigned long t1, t2, dt;
};
struct Enemy monster1, monster2;

//定义豆子
struct Food {
    int x;
    int y;
    bool isexist;
    //用于判断豆子是否被吃
};
struct Food food1, food2, food3, food4, food5;
void wanjia()
{
    BeginBatchDraw();
    loadimage(&img_player, _T("D:\\wanjia1.png"), 50, 50); //关键
    putimage(player.x, player.y, &img_player);
    loadimage(&img_player1, _T("D:\\wanjia1.png"), 50, 50); //关键
    putimage(player1.x, player1.y, &img_player1);
    EndBatchDraw();
}

void diren()
{
    BeginBatchDraw();
    loadimage(&img_monster1, _T("D:\\5.png"), 50, 50); //关键
    putimage(monster1.x, monster1.y, &img_monster1);
    loadimage(&img_monster2, _T("D:\\5.png"), 50, 50); //关键
    putimage(monster2.x, monster2.y, &img_monster2);
    EndBatchDraw();
}

void douzi1()
{
    BeginBatchDraw();
    loadimage(&img_food1, _T("D:\\food.png"), 30, 30); //关键
    putimage(800, 50, &img_food1);
    EndBatchDraw();
}

void douzi2() {
    BeginBatchDraw();
    loadimage(&img_food2, _T("D:\\food.png"), 30, 30); //关键
    putimage(270, 250, &img_food2);
    EndBatchDraw();
}

void douzi3() {
    BeginBatchDraw();
    loadimage(&img_food3, _T("D:\\food.png"), 30, 30); //关键
    putimage(285, 400, &img_food3);
    EndBatchDraw();
}

void douzi4() {
    BeginBatchDraw();
    loadimage(&img_food4, _T("D:\\food.png"), 30, 30); //关键
    putimage(750, 550, &img_food4);
    EndBatchDraw();
}

void douzi5() {
    BeginBatchDraw();
    loadimage(&img_food5, _T("D:\\food.png"), 30, 30); //关键
    putimage(700, 400, &img_food5);
    EndBatchDraw();
}
//3.显示程序
void GameDraw()
{
    //开始绘制
    BeginBatchDraw();

    wanjia();

    //绘制敌人
    diren();
    //绘制豆子
    douzi1();
    douzi2();
    douzi3();
    douzi4();
    douzi5();

    //结束绘制
    EndBatchDraw();
}
int  main() {        //显示菜单,并且获取用户输入的命令选项

    initgraph(900, 600);
    void GameInit();

    
    cleardevice();
    while (1) {     //游戏的每一个画面都在不断绘制,用循环
        BeginBatchDraw();
        loadimage(&img_map, _T("D:\\map2.jpg"), 900, 600); //关键
        putimage(0, 0, &img_map);
        GameDraw();
        FlushBatchDraw();
        EndBatchDraw();
    }
    closegraph();
}


使用vs C语言绘制图片,并加入了
BeginBatchDraw();
FlushBatchDraw();
EndBatchDraw();但仍然无法解决图像不断闪烁的问题。请问怎么办?(除了采用双缓冲的技术)

  • 写回答

2条回答 默认 最新

  • CSDN专家-link 2021-12-26 13:17
    关注

    你不断地重画背景图,再画新内容,每次画两遍不同内容,肯定闪啊。就得用双缓存,先在内存DC里画好再帖出来

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 1月5日
  • 已采纳回答 12月28日
  • 创建了问题 12月26日

悬赏问题

  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测