BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"Simple Sprite Tutorial"
, by nawitus
Learn how to set up randomly colored sprites rotating trough ur screen.
Code
;=================================================== ;= SIMPLE SPRITE TUTORIAL = ;=================================================== ;= WRITTEN BY NAWITUS = ;= FOR BLITZCODER.COM = ;=================================================== ;No files needed! ;Constants: Const Wait=5 ;Wait every n milliseconds before creating a new sprite ;3D graphics mode Graphics3D 800,600,16,2 ;Set our buffer SetBuffer BackBuffer() ;SeedRnd to get more random numbers SeedRnd MilliSecs() ;Create our camera Cam=CreateCamera() ;Our timer for sprite creation Global Timer=MilliSecs() ;Heres our sprite type Type Sprite ;this is where im gonna store the sprite Field sp ;and here the sprites angle Field ang End Type ;main loop While Not KeyHit(1) ;Create a sprite If MilliSecs() > Timer + Wait Then ;Reset our timer Timer = MilliSecs() ;Lets begin creating our sprite :) s.Sprite = New Sprite ;Now lets create the texture for our sprite first txt=CreateTexture(1,1) ;Set texture buffer, remeber to set backbuffer 'back' afterwards SetBuffer TextureBuffer(txt) ;Set random color Color Rnd(255),Rnd(255),Rnd(255) Plot 0,0 ;Set our backbuffer back! SetBuffer BackBuffer() ;Create our sprite s\sp = CreateSprite() ;Texture it EntityTexture s\sp,txt ;Position it PositionEntity s\sp,-20+Rnd#(40),-20+Rnd#(40),50 ;Now we have a randomly colored sprite EndIf ;Turn, move and secure our sprites ;Loop trough every single sprite For s.Sprite = Each Sprite ;Increase ang var by 2 s\ang=s\ang+2 ;Rotate our sprite to the correct ang RotateSprite s\sp,s\ang ;Move our sprite closer to camera MoveEntity s\sp,0,0,-0.25 ;If our sprite is behind our camera then delete it If EntityZ(s\sp) < 0 Then FreeEntity s\sp : Delete s.Sprite ;Now we have sprites rotating and moving :) Next ;update world UpdateWorld ;render the screen RenderWorld ;flip the buffers Flip Wend
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations