Tutorial: create and show sprite ================================ Create a sprite with a sunnyboy, which zoomes in and out, and show it. step 1 At first we have to initialize VgaGames and open a window or switch to graphical screen. ==>
int main(int argc, char ** argv) { char * arg0; // for the name of the program bitmap * sunboy; // for the sunnyboy sprite * sunsprite; // sunnyboy sprite double d1; /* initialize vgagames, always pass argv[0] */ if (vg_init_vgagames(argv[0],0,NULL) < 0) {exit(1);} /* open window */ if ((arg0=strrchr(argv[0],'/'))==NULL) {arg0=argv[0];} else {arg0++;} if (vg_window_open(arg0,0,0) < 0) {exit(1);} |
/* create a yellow sunnyboy */ sunboy=create_sunnyboy(vg_color_index(CL_YELLOW,100)); if (sunboy==NULL) { // error vg_window_close(); exit(1); } |
/* create a new new sprite */ sunsprite=vg_sprite_createnew(); if (sunsprite==NULL) { // error vg_window_close(); exit(1); } |
/* add zoomed sunnyboys to sprite */ vg_sprite_add(sunsprite,vg_bitmap_zoom(sunboy,1.0,1.0),18,NULL,0); for (d1=1.1; d1<2.0; d1+=0.1) { /* becoming larger */ vg_sprite_add(sunsprite,vg_bitmap_zoom(sunboy,d1,d1),3,NULL,0); } vg_sprite_add(sunsprite,vg_bitmap_zoom(sunboy,d1,d1),18,NULL,0); for (; d1>1.0; d1-=0.1) { /* becoming smaller */ vg_sprite_add(sunsprite,vg_bitmap_zoom(sunboy,d1,d1),3,NULL,0); } vg_sprite_add(sunsprite,vg_bitmap_zoom(sunboy,1.0,1.0),18,NULL,0); /* free sunnyboy */ vg_bitmap_free(sunboy); |
/* give out sprite one time */ while ((sunboy=vg_sprite_getnext(sunsprite))!=NULL) { vg_bitmap_clear(NULL,RGB_BLACK); vg_bitmap_copyto(NULL,SC_WIDTH/2,SC_HEIGHT/2,sunboy,0,0,0,0,RGB_FULL); vg_window_flush(); vg_wait_time(50); } |
/* free sprite */ vg_sprite_free(sunsprite); /* close window */ vg_window_close(); exit(0); } |
[SPRITE] sunboy.vga LOOP=18 sunboy.vga LOOP=3 ZOOM=1.1,1.1 sunboy.vga LOOP=3 ZOOM=1.2,1.2 sunboy.vga LOOP=3 ZOOM=1.3,1.3 sunboy.vga LOOP=3 ZOOM=1.4,1.4 sunboy.vga LOOP=3 ZOOM=1.5,1.5 sunboy.vga LOOP=3 ZOOM=1.6,1.6 sunboy.vga LOOP=3 ZOOM=1.7,1.7 sunboy.vga LOOP=3 ZOOM=1.8,1.8 sunboy.vga LOOP=3 ZOOM=1.9,1.9 sunboy.vga LOOP=18 ZOOM=2.0,2.0 sunboy.vga LOOP=3 ZOOM=1.9,1.9 sunboy.vga LOOP=3 ZOOM=1.8,1.8 sunboy.vga LOOP=3 ZOOM=1.7,1.7 sunboy.vga LOOP=3 ZOOM=1.6,1.6 sunboy.vga LOOP=3 ZOOM=1.5,1.5 sunboy.vga LOOP=3 ZOOM=1.4,1.4 sunboy.vga LOOP=3 ZOOM=1.3,1.3 sunboy.vga LOOP=3 ZOOM=1.2,1.2 sunboy.vga LOOP=3 ZOOM=1.1,1.1 sunboy.vga LOOP=18 |