Post by Jake on Apr 20, 2005 18:16:56 GMT
Ok, I'll try to explain the whole thing. Maybe I manage to get the thing out of the fog for you:
Before describing what SpriteCandy does, let's talk about 3D and how BlitzBasic handle it.
Take a simple cube created with CreateCube() in Blitz. CreateCube does the following for you (you can create a cube for yourself, if you want. Try it!):
1.) Creating an entity/Mesh (see Createmesh)
2.) Creating a surface for this entity (see CreateSurface).
3.) Defining points on this surface to form corners for the cube. A point is called a Vertex (multiple: Vertices). (see AddVertex)
4.) To let DirectX render a cube, sets of 3 Vertices are bundled and form a triangle (see AddTriangle()). For example, each face of your cube exists of 2 Triangles formed by 4 Vertices.
Blitz stores everything in "worldspace", so when you call RenderWorld every triangle you've created got drawn. (to anyone: not very technically, but you can say so).
AddVertex and AddTriangle need a surface as parameter, to know on which surface they should create a vertex or triangle. If you delete a surface, all triangles and vertices on this surface are deleted from worldspace, so they disappear on your next call of RenderWorld.
If you want to remove a single vertex/triangle later WITHOUT removing everything on a surface, you need to tell Blitz WHAT Vertex/Triangle to remove. You do so by telling Blitz the handle returned with each AddVertex/AddTriangle.
Ok, I hope you understand this so far. If not, please play with the basic 3D-examples shipped with Blitz and get familiar with 3D rendering and the mentioned Blitz functions.
Remember: You don't have to care what to blit/draw on screen, you just define geometry and let DirectX display it for you. All you do is define some objects (Entities/Meshs) and say where they are in your virtual world. You can rotate and move them, or you can rotate a camera around an object. You really don't care how DirectX bring this to your screen - just let it happen.
======================================
Now, I asume you get the clue about Entities, Surfaces, Vertices and Triangles. If not, have a 2nd look at the Blitz examples or find some other tutorials on the web (i.e. at blitzcoder.com).
Let's talk about SpriteCandy:
What is a HUD? It's an entity, nothing more.
What is a Layer? Just a surface....
What is a Sprite?
So to speak a face of a cube. 4 Vertices, 2 Triangles - that's it. Just geometry - no pictures, no need to draw everything by yourself. This is called a "Quad". A Quad is flat on an given (3D-)axis and usually used to display 2D in 3D. The tricky part is to create the Vertices at the correct world-coordinates to let you think it's 2D. But no problem, SpriteCandy does this for you.
"Ok, but how can my sprite display my alien?"
Textures!
A texture is an image. It's called texture cause it wraps around geometry. You "snap" a texture to a surface (we know so far that a HUD_Layer is a surface). Take the cube-example above: Use EntityTexture to wrap an image around your cube. I'll skip the part about how an image is wrapped around geometry, see UV-Mapping (that's the keyword!)-Tutorials if you like. It's not really necessary to know about this, allthough you can do a lot cool things by fiddling with UV-coordinates.
In SpriteCandy, you attach a Texture to a Layer with HUD_CreateLayer by passing a previously loaded texture-handle to it.
So, you've created a HUD-Layer and attached a texture-image to it. With HUD_CreateImage you tell SpriteCandy to:
* create a Quad (=4 vertices/2 triangles) on a surface AND
* tell the rendering-engine which part of your image to display on this quad.
Again, no blitting or drawing. The texture is already loaded to your graphics-card. It's all about telling DirectX what part of texture you want to see on the geometry (that's the thing called UV-Mapping).
When you wan't to change your alien-sprite to a dead alien-sprite, you don't recreate geometry - you just tell DirectX to display a new part of your texture on your Quad. In SpriteCandy you do this with HUD_SetImageClip. This is also the way SpriteCandy does animation.
Remember: In 3D (and SpriteCandy is 3D) everything stays in your virtual world until you remove it. So there's no need to recreate something every frame. Technically, you have to blit it on the backbuffer every frame. But this is done by RenderWorld.
I think I can't explain this any better and I hope, you get your head around this. Play with simple 3D stuff in Blitz and learn from this. Once you know how this works, you'll know how SpriteCandy works.
Best regards
Jake
Before describing what SpriteCandy does, let's talk about 3D and how BlitzBasic handle it.
Take a simple cube created with CreateCube() in Blitz. CreateCube does the following for you (you can create a cube for yourself, if you want. Try it!):
1.) Creating an entity/Mesh (see Createmesh)
2.) Creating a surface for this entity (see CreateSurface).
3.) Defining points on this surface to form corners for the cube. A point is called a Vertex (multiple: Vertices). (see AddVertex)
4.) To let DirectX render a cube, sets of 3 Vertices are bundled and form a triangle (see AddTriangle()). For example, each face of your cube exists of 2 Triangles formed by 4 Vertices.
Blitz stores everything in "worldspace", so when you call RenderWorld every triangle you've created got drawn. (to anyone: not very technically, but you can say so).
AddVertex and AddTriangle need a surface as parameter, to know on which surface they should create a vertex or triangle. If you delete a surface, all triangles and vertices on this surface are deleted from worldspace, so they disappear on your next call of RenderWorld.
If you want to remove a single vertex/triangle later WITHOUT removing everything on a surface, you need to tell Blitz WHAT Vertex/Triangle to remove. You do so by telling Blitz the handle returned with each AddVertex/AddTriangle.
Ok, I hope you understand this so far. If not, please play with the basic 3D-examples shipped with Blitz and get familiar with 3D rendering and the mentioned Blitz functions.
Remember: You don't have to care what to blit/draw on screen, you just define geometry and let DirectX display it for you. All you do is define some objects (Entities/Meshs) and say where they are in your virtual world. You can rotate and move them, or you can rotate a camera around an object. You really don't care how DirectX bring this to your screen - just let it happen.
======================================
Now, I asume you get the clue about Entities, Surfaces, Vertices and Triangles. If not, have a 2nd look at the Blitz examples or find some other tutorials on the web (i.e. at blitzcoder.com).
Let's talk about SpriteCandy:
What is a HUD? It's an entity, nothing more.
What is a Layer? Just a surface....
What is a Sprite?
So to speak a face of a cube. 4 Vertices, 2 Triangles - that's it. Just geometry - no pictures, no need to draw everything by yourself. This is called a "Quad". A Quad is flat on an given (3D-)axis and usually used to display 2D in 3D. The tricky part is to create the Vertices at the correct world-coordinates to let you think it's 2D. But no problem, SpriteCandy does this for you.
"Ok, but how can my sprite display my alien?"
Textures!
A texture is an image. It's called texture cause it wraps around geometry. You "snap" a texture to a surface (we know so far that a HUD_Layer is a surface). Take the cube-example above: Use EntityTexture to wrap an image around your cube. I'll skip the part about how an image is wrapped around geometry, see UV-Mapping (that's the keyword!)-Tutorials if you like. It's not really necessary to know about this, allthough you can do a lot cool things by fiddling with UV-coordinates.
In SpriteCandy, you attach a Texture to a Layer with HUD_CreateLayer by passing a previously loaded texture-handle to it.
So, you've created a HUD-Layer and attached a texture-image to it. With HUD_CreateImage you tell SpriteCandy to:
* create a Quad (=4 vertices/2 triangles) on a surface AND
* tell the rendering-engine which part of your image to display on this quad.
Again, no blitting or drawing. The texture is already loaded to your graphics-card. It's all about telling DirectX what part of texture you want to see on the geometry (that's the thing called UV-Mapping).
When you wan't to change your alien-sprite to a dead alien-sprite, you don't recreate geometry - you just tell DirectX to display a new part of your texture on your Quad. In SpriteCandy you do this with HUD_SetImageClip. This is also the way SpriteCandy does animation.
Remember: In 3D (and SpriteCandy is 3D) everything stays in your virtual world until you remove it. So there's no need to recreate something every frame. Technically, you have to blit it on the backbuffer every frame. But this is done by RenderWorld.
I think I can't explain this any better and I hope, you get your head around this. Play with simple 3D stuff in Blitz and learn from this. Once you know how this works, you'll know how SpriteCandy works.
Best regards
Jake