清除精灵而不是使用clear()

清除精灵而不是使用clear(),c,graphics,C,Graphics,我正在写一个游戏,我需要移动一个精灵。我正在绘制精灵,更新新位置,重新绘制它,并清除精灵的最后一次迭代,从而使它看起来像是在移动 不幸的是,我无法从屏幕上清除精灵的上一次迭代 void move_sprite() {//this is used in a while loop within the main get_direction();//just checks to see which direction the dx/dy should move in

我正在写一个游戏,我需要移动一个精灵。我正在绘制精灵,更新新位置,重新绘制它,并清除精灵的最后一次迭代,从而使它看起来像是在移动

不幸的是,我无法从屏幕上清除精灵的上一次迭代

void move_sprite() {//this is used in a while loop within the main

        get_direction();//just checks to see which direction the dx/dy should move in
        clear_sprite(sprite.x, sprite.y, width, height);//should clear the previous iteration of the sprite
        update_sprite(&sprite);//modifies the x/y dx/dy of the sprite, moving it
        draw_sprite(&sprite);//this just draws the sprite at whatever coordinate update_sprite tells it to move to, it is moving one pixel at a time.
        refresh();
        _delay_ms( 200 );

}

void clear_sprite(unsigned char x, unsigned char y, const int width, const int height) {
    for (int i = 0; i < width; i++) {
        for (int ii = 0; ii < height; ii++){
            set_pixel(x + i, y + ii, 0);
        }
    }   
}
void move_sprite(){//这在主目录中的while循环中使用
get_direction();//只需检查dx/dy应该向哪个方向移动
clear_sprite(sprite.x,sprite.y,width,height);//应该清除sprite的上一次迭代
更新_sprite(&sprite);//修改sprite的x/y dx/dy,并移动它
draw_sprite(&sprite);//这只是在更新_sprite告诉它移动到的任何坐标处绘制sprite,它一次移动一个像素。
刷新();
_延时μms(200);
}
无效清除精灵(无符号字符x、无符号字符y、常量整数宽度、常量整数高度){
对于(int i=0;i

它通过3 x 3精灵的x和y,将每个像素值设置为0,从而在LCD屏幕上清除它。但是,绘制的精灵的上一次迭代将保持不变,从而产生不必要的“拖尾”效果。

您使用的是特定的框架吗?这是什么站台?你的问题太模糊了,我们无法回答。请添加更多信息。看起来sprite是全局的,可能在ClearPrite()运行之前正在事件处理程序中更新。或者可能在getdirection()中