Real Time 2D Rotating
Blitz3D Forums/Blitz3D Beginners Area/Real Time 2D Rotating
| ||
Is it possible to quickly rotate images in B3D? |
| ||
This was taken from game programming for teensGraphics 800,600 ;Set up AutoMidHandle and BackBuffer() AutoMidHadle True Setbuffer backbuffer() ;Images ;Load yourimage that will be rotated yourimage=loadimage("yourimage.bmp") ;CONSTANTS ;How many rotations do you want total Const rotations = 16 ;Create the rotation array Dim imagearray(rotations) ;For all of the rotations you want, copy the spaceship image and routate it the correct amount of degrees For frame=0 to rotations-1 imagearray(frame) = copyimage(yourimage) rotateimage imagearray(frame), frame*360/rotations Next Print "Press Left to rotate conter-clockwise and right to rotate clockwise," print "Press Esc to exit." ;Begin at frame 0 (facing upward) frame=0 ;MAIN LOOP while not keydown(1) ;Clear the screen cls ;Rotate the ship left if use presses left If Keydown(203) ;Decrement frame by 1 (thus rotating it left frame=frame-1 ;If the frame count is less the 0,put it back at the max value of the array if frame<0 frame=rotations - 1 endif ;Rotate the ship right if user presses right elseif keydown(205) ;Increment frame by 1 (thus rotating it right) frame=frame+1 ;If the frame gets to big, set it to the first frame (0) If frame >= rotations frame=0 endif endif drawimage imagearray(frame),400,300 flip ;Wait for a while Delay 50 Wend |
| ||
- |
| ||
Since your using b3d, maybe you could use a texture instead: |
| ||
Thanks guys, I'll try your ideas... |
| ||
@Cyberspy I've been testing your method and I got it to work without functions in my code. @Everyone How can I define arrays and constants as global so I can use them in functions? |
| ||
I think you can use Constants in functions just like globals, not sure about arrays though. |
| ||
Okay, thanks for the tip. I'm almost positive that arrays don't work in functions (unless they're somehow defined as global). In my program, the compiler ignores rotating the image--but still draws it in the default position. |
| ||
Arrays are global (see below). Dim array(9) For i=0 To 9 array(i)=i Next printArray(0,9) WaitKey Function printArray(iFrom,iTo) Print array(iFrom) iFrom=iFrom+1 If iFrom<(iTo+1) Then printArray(iFrom,iTo) End Function |
| ||
B3D does actually support local arrays. Just use square brackets, a la array[10]. However, this type of array can only be one dimensional. |
| ||
B3D does actually support local arrays... Man, I'm glad you posted - I'd gotten it into my head that 'blitz arrays' could only be used in types. RTFM, Sledge! |
| ||
Okay, I'll report back if I have more problems. |
| ||
Man, I'm glad you posted - I'd gotten it into my head that 'blitz arrays' could only be used in types. RTFM, Sledge! Heh - to be fair, I dont think blitz arrays are even in the manual. :) I also forgot to mention you need to use the Local keyword when defining blitz arrays, so it should actually be 'Local array[10]'. :) |