Help! Please take a look at this snippet...

Started by
3 comments, last by webmunkey 22 years, 8 months ago
Hey, Take a look at this code: // Blit the stuff for the next frame rcRect.left = 0; rcRect.top = 0; rcRect.right = 640; rcRect.bottom = 480; rcRect.left = currentFrame % 10 * 64; rcRect.top = currentFrame / 10 * 64 + 480; rcRect.right = currentFrame % 10 * 64 + 64; rcRect.bottom = currentFrame / 10 * 64 + 64 + 480; I realize that this code sections off a chunk of the bitmap file, but exactly how does it work? And how could I modify the section that it "blits" (i guess thats the right word) so that i could make it say 20 pixels bigger? Thanks </i>
Advertisement
  rcRect.left = currentFrame[ i ] % 10 * 64;rcRect.top = currentFrame[ i ] / 10 * 64 + 480;rcRect.right = currentFrame[ i ] % 10 * 64 + 64;rcRect.bottom = currentFrame[ i ] / 10 * 64 + 64 + 480;  


This code doesnt actually blit anything, it just sets up a source rectangle to blit from. Fiddle with the numbers and you get a different size, but since this code has hardcoded values to work with specific bitmaps and specific sprite sizes (this one seems to use 64x64 sprites) fiddling with the numbers is going to give you weird results and/or crash your computer.
quote:Original post by webmunkey
// Blit the stuff for the next frame
rcRect.left = 0;
rcRect.top = 0;
rcRect.right = 640;
rcRect.bottom = 480;

rcRect.left = currentFrame % 10 * 64;<br>rcRect.top = currentFrame / 10 * 64 + 480;<br>rcRect.right = currentFrame % 10 * 64 + 64;<br>rcRect.bottom = currentFrame / 10 * 64 + 64 + 480;<br> <hr height=1 noshade></SPAN></BLOCKQUOTE> <br>Duh. This is one reason why code should use constants instead of literal numbers.<br><br>Firstly, the top 4 lines are totally pointless, so remove them.<br><br>Secondly, I'm guessing that the '10' means that it's drawing from a graphic with 10 tiles in a row. However, since I don't know all my operator precedence enough to work out quite what each of those expressions produces, I have no idea for sure. Use explicit parentheses, people! The 640 and 480 are probably the screen dimensions and the 64 is the tile size. The division by 10 picks a row, and the modulus by 10 picks a number from 0 to 9 (a tile from within that row). So currentFrame[23] would yield 23/10 == 2 for the row, and 23%10 == 3 for the column (tile within that row of 10.)<br><br>Edited by - Kylotan on August 1, 2001 8:15:19 PM
Wow! Thanks guys, I understand how it works now... Also, I didn't write that...Microsoft did, thats why I didn't know how it worked. Thanks again...

Edited by - webmunkey on August 1, 2001 8:40:03 PM
Hey,
is that from the Donut Sample?
I can remember that code. LOL

--::[Madhed]::-

This topic is closed to new replies.

Advertisement