Rotating images and max() function
Blitz3D Forums/Blitz3D Beginners Area/Rotating images and max() function
| ||
hi folks, i am writing a 2d top down game and am having trouble rotation my main sprite. i know most people make, say 36 frames with the sprite rotaed by 10 degreees each time, then they just play the frame closest to the sprites orientation, but, the sprite i have made is a man, and has 20 frames for walking. So the only way i could do this is to make a frame for each walk step at each rotation, and this would give me 36 * 20 frames! Whenever i the rotateImage functon, it kills the framerate. Is there a fast, clean way to do this? I have posted the code below for clarity: Global player Global rootx Global rooty Global frame Global rotate Graphics 600,800,0 rootx = 400 rooty = 300 rotate = 0 While KeyDown(1) = False If KeyDown(17) = True frame = frame + 1 rooty = rooty + 7 If frame > 19 Then frame = 0 EndIf Else If KeyDown(31) = True Then frame = frame - 1 rooty = rooty - 7 If frame < 0 Then frame = 19 EndIf Else frame = 0 EndIf SetBuffer BackBuffer() Cls draw_player() Flip Wend End Function draw_player() player = LoadAnimImage("basicWalk.bmp",100,80,0,20) MaskImage player,0,255,0 RotateImage player,rotate DrawImage player,rootx,rooty,frame End Function i know there is no code in there for incrementing 'rotate' in accordance with the key's pressed, but the rest should work. Also, in VB, there is a max() function. IE: you put in max(a,b) and it will retur the larger value. What is the equivelent code in blitz as i cant seem to find one. I know it would be easy to write a function to do it, but i was wondering if there is a built-in command. Thanks for any help folks. ~V~ |
| ||
I haven't tried it yet but I think the Extended Blitz 2D dll allows real-time rotation of sprites. Unfortunately Blitzcoder is down right now and that's the place to download the plugin. As for using RotateImage, use it once BEFORE you start your game (ie. while loading resources at the beginning) to generate all the rotated animation frames and then use those pre-rendered images in your game. For the most part you shouldn't even be using LoadAnimImage during your game; load the image and use RotateImage before you start your main game loop (ie. before "While etc.") |
| ||
ah, good idea! i'll give it a go now and let u know how it goes....thanks |
| ||
hmm.. rotateimage does anti aliasing for angles that aren't 0,90,180 or 270, right? Once I made a small army truck (only 32x32 pixels orso) rotate in a topview game.. I didn't like the change between original and antialiased while rotating.. |
| ||
You can turn off the antialising. I forget the command but somebody will come up with it in a post or two. |
| ||
I forget the command but somebody will come up with it in a post or two. TFormFilter().In addition to what Mr. Joe Hocking said, I would like to add that when generating these rotated images, you should always do so from the original. You know how it goes with a copy of a copy and all that. I generally agree that it would be better to pre-render your graphics, rotated (no big deal if using a 3D package, might not be worth the trouble if using a 2D tool). The graphics will use up the same ammount of RAM anyway, and the pre-rendered graphics will look better. Or you could use some variant of the "2D in 3D". I hear Mr. John Pickford has some particularilly nice code to acheive this easily, and it's fast too! |