Game programming

Moderators: None (Apply to moderate this forum)
Number of threads: 2070
Number of posts: 5361

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Flicker free animation for Game Posted by noname01 on 12 Jul 2001 at 12:34 PM
I am trying to make a dartboard game with a moving dartboard. I have animated the dartboard but it flickers like hell. I have been facing this problem from the day i started to animate objects. Can someone please suggest a solution for minimising the flickering without going overboard in Assembly and VGA programming(cos I am still learning Assembly).

Check out the following code in Turbo C++ to animate the dartboard(which flickers)

#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<dos.h>

void driver()
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
errorcode = graphresult();
if (errorcode != grOk) exit(1);
}

void DrawBoard(int x,int y)
{
setfillstyle(1,14);
bar(x,y-5,x+5,y+5);
setfillstyle(1,13);
bar(x+5,y-10,x+15,y+10);
setfillstyle(1,12);
bar(x+15,y-20,x+25,y+20);
setfillstyle(1,7);
bar(x+25,y-30,x+35,y+30);
}

void EraseBoard(int x,int y)
{
setfillstyle(1,0);
bar(x,y-30,x+40,y+30);
}

void MoveBoard()
{
int y=240;
DrawBoard(450,y);
getch();
EraseBoard(450,y);
while(!kbhit())
{
static flag=1;
DrawBoard(450,y);
EraseBoard(450,y);
delay(10);
y+=flag;
if(y==400) flag*=-1;
if(y==100) flag*=-1;
}
}

void main()
{
driver();
//setcolor(10);
MoveBoard();
getch();
}


Report
Re: Flicker free animation for Game Posted by 9725644 on 12 Jul 2001 at 4:22 PM
The secret to removing flickering from amimation is to use virtual screens. Instead of writing directly to the screen, write to a buffer, the copy this to the screen

declare buffers as follows

// declare a pointer to the offset of VGA memory
unsigned char *vga = (unsigned char *) MK_FP(0xA000, 0);
// declare a pointer to the offset of virtual screen.
unsigned char *vscreen = (unsigned char *) MK_FP(0x6000 , 0);


Now in the drawing functions, write to the vscreen

eg.
void ghline(int x1,int x2,int y,unsigned char colour)
{
memset (vscreen+(y*320)+x1, colour, x2-x1+1);
}

instead of

void ghline(int x1,int x2,int y,unsigned char colour)
{
memset (vga+(y*320)+x1, colour, x2-x1+1);
}

When you have all the drawing of one frame complete, copy this to the screen

void memtoscreen()
{
memcpy(vga,vscreen,size_t(6400*10));
}

Hope this helps. If not just ask again.

Ciaran

Report
Re: Flicker free animation for Game Posted by gautam on 13 Jul 2001 at 11:15 AM
Make use << & >> for * and /, they are faster. With BGI, assembly's vertical blanking doesn't work I think.

: The secret to removing flickering from amimation is to use virtual screens. Instead of writing directly to the screen, write to a buffer, the copy this to the screen
:
: declare buffers as follows
:
: // declare a pointer to the offset of VGA memory
: unsigned char *vga = (unsigned char *) MK_FP(0xA000, 0);
: // declare a pointer to the offset of virtual screen.
: unsigned char *vscreen = (unsigned char *) MK_FP(0x6000 , 0);
:
:
: Now in the drawing functions, write to the vscreen
:
: eg.
: void ghline(int x1,int x2,int y,unsigned char colour)
: {
: memset (vscreen+(y*320)+x1, colour, x2-x1+1);
: }
:
: instead of
:
: void ghline(int x1,int x2,int y,unsigned char colour)
: {
: memset (vga+(y*320)+x1, colour, x2-x1+1);
: }
:
: When you have all the drawing of one frame complete, copy this to the screen
:
: void memtoscreen()
: {
: memcpy(vga,vscreen,size_t(6400*10));
: }
:
: Hope this helps. If not just ask again.
:
: Ciaran
:





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.