@@ -24,6 +24,8 @@ const screenHeight = 450
2424r . InitWindow ( screenWidth , screenHeight , 'raylib [textures] example - bunnymark' )
2525
2626const texBunny = r . LoadTexture ( join ( __dirname , '..' , 'textures' , 'resources' , 'wabbit_alpha.png' ) )
27+ const hWidth = texBunny . width / 2
28+ const hHeight = texBunny . height / 2
2729
2830while ( ! r . WindowShouldClose ( ) ) {
2931 if ( r . GetFPS ( ) > 60 ) {
@@ -34,21 +36,21 @@ while (!r.WindowShouldClose()) {
3436 }
3537 }
3638
37- for ( const i in bunnies ) {
38- bunnies [ i ] . position . x += bunnies [ i ] . speed . x
39- bunnies [ i ] . position . y += bunnies [ i ] . speed . y
39+ r . BeginDrawing ( )
40+ r . ClearBackground ( r . RAYWHITE )
4041
41- if ( ( ( bunnies [ i ] . position . x + texBunny . width / 2 ) > r . GetScreenWidth ( ) ) ||
42- ( ( bunnies [ i ] . position . x + texBunny . width / 2 ) < 0 ) ) bunnies [ i ] . speed . x *= - 1
43- if ( ( ( bunnies [ i ] . position . y + texBunny . height / 2 ) > r . GetScreenHeight ( ) ) ||
44- ( ( bunnies [ i ] . position . y + texBunny . height / 2 - 40 ) < 0 ) ) bunnies [ i ] . speed . y *= - 1
45- }
42+ for ( const bun of bunnies ) {
43+ bun . position . x += bun . speed . x
44+ bun . position . y += bun . speed . y
4645
47- r . BeginDrawing ( )
48- r . ClearBackground ( r . RAYWHITE )
49- for ( const bunny of bunnies ) {
50- r . DrawTexture ( texBunny , bunny . position . x , bunny . position . y , bunny . color )
46+ if ( ( ( bun . position . x + hWidth ) > r . GetScreenWidth ( ) ) ||
47+ ( ( bun . position . x + hWidth ) < 0 ) ) bun . speed . x *= - 1
48+ if ( ( ( bun . position . y + hHeight ) > r . GetScreenHeight ( ) ) ||
49+ ( ( bun . position . y + hHeight - 40 ) < 0 ) ) bun . speed . y *= - 1
50+
51+ r . DrawTexture ( texBunny , bun . position . x , bun . position . y , bun . color )
5152 }
53+
5254 r . DrawRectangle ( 0 , 0 , screenWidth , 40 , r . BLACK )
5355 r . DrawText ( 'bunnies: ' + bunnies . length , 120 , 10 , 20 , r . GREEN )
5456 r . DrawText ( 'batched draw calls: ' + ( 1 + bunnies . length / MAX_BATCH_ELEMENTS ) , 320 , 10 , 20 , r . MAROON )
0 commit comments