Archived

This topic is now archived and is closed to further replies.

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

This topic is 5979 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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[i] / 10 * 64 + 480; rcRect.right = currentFrame[i] % 10 * 64 + 64; rcRect.bottom = currentFrame[i] / 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

Share this post


Link to post
Share on other sites
  
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.

Share this post


Link to post
Share on other sites
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[ 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;


Duh. This is one reason why code should use constants instead of literal numbers.

Firstly, the top 4 lines are totally pointless, so remove them.

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.)

Edited by - Kylotan on August 1, 2001 8:15:19 PM

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites