5 anim_image_dblbuf.pir - animate an image in a doublebuffered Parrot SDL window
9 To run this file, run the following command from the Parrot root directory:
11 $ ./parrot examples/sdl/anim_image_dblbuf.pir
12 Drew 540 frames in 2.200484 seconds (245.400580 fps)
18 load_bytecode "SDL/App.pir"
19 load_bytecode "SDL/Color.pir"
20 load_bytecode "SDL/Rect.pir"
21 load_bytecode "SDL/Image.pir"
22 load_bytecode "SDL/Sprite.pir"
25 app = new ['SDL'; 'App']
26 app.'init'( 'height' => 480, 'width' => 640, 'bpp' => 0, 'flags' => 1073741825 )
28 .local pmc main_screen
29 main_screen = app.'surface'()
32 dest_rect = new ['SDL'; 'Rect']
33 dest_rect.'init'( 'height' => 100, 'width' => 100, 'x' => 0, 'y' => 190 )
36 prev_rect = new ['SDL'; 'Rect']
37 prev_rect.'init'( 'height' => 100, 'width' => 101, 'x' => 0, 'y' => 190 )
39 .local pmc source_rect
40 source_rect = new ['SDL'; 'Rect']
41 source_rect.'init'( 'height' => 56, 'width' => 100, 'x' => 0, 'y' => 0 )
44 black = new ['SDL'; 'Color']
45 black.'init'( 'r' => 0, 'g' => 0, 'b' => 0 )
48 image = new ['SDL'; 'Image']
49 image.'init'( 'examples/sdl/parrot_small.png' )
52 sprite = new ['SDL'; 'Sprite']
53 sprite.'init'( 'surface' => image, 'source_x' => 0, 'source_y' => 0, 'dest_x' => 0, 'dest_y' => 190, 'bgcolor' => black )
58 _animate_on_x_axis( main_screen, sprite, 0, 540, 2)
60 _animate_on_x_axis( main_screen, sprite, 540, 0, -2)
66 total_time = end_time - start_time
70 fps = 540 / total_time
72 print "Drew 540 frames in "
84 .sub _animate_on_x_axis
91 # destination SDL::Surface and SDL::Sprite to animate
93 # starting and x coordinates and number of pixels to move at a time
101 sprite.'draw'( screen )
103 if x_pos != end_pos goto _loop
108 chromatic, E<lt>chromatic at wgz dot orgE<gt>.
112 Copyright (C) 2004-2008, Parrot Foundation.
120 # vim: expandtab shiftwidth=4 ft=pir: