2D in 3D. No, the other 2D in 3D.

Blitz3D Forums/Blitz3D Programming/2D in 3D. No, the other 2D in 3D.

Uber Lieutenant(Posted 2004) [#1]
I'm working on a game (ad who isn't) and I'm trying to have a 2D sprite character run around in a 3D environment (side-scroller, not a la Jet Set Radio). I know its rather simple to do. I mean, position a 2D sprite in a 3D mesh.

Where the problem resides is that sprite control is limited and slow nativly in Blitz3D. I've been giving sprite libraries a go, but all of them (that I tried) spawn a seperate camera over the primary viewport to be of use to those who need a HUD, so the sprite is always drawn over the 3D mesh.

How can I put a 2D sprite in a 3D mesh and still have all the control of a sprite library?


rsbrowndog(Posted 2004) [#2]
You'd probably be better off using a quad instead of a sprite, that would give you a lot more control and access to all the mesh-related functions.

Cheers,

Ryan


jhocking(Posted 2004) [#3]
What's slow about sprite control? For a large number of sprites they could be slow because of the large number of surfaces, but for a single sprite (or small number at any rate) it's no big deal.

As for wanting the control of a sprite, what sort of control are you after exactly? I'm not clear on why using a sprite in the 3D environment won't work.


Uber Lieutenant(Posted 2004) [#4]
By control I mean there are less commands available for sprites than there are for 2D images, so it lacks the amount of aspects I can change about them. Usually sprite libraries are very fast in performance, are easy to learn, and offer a wide variety of commands to control sprites with.

Just not really happening with the native Blitz syntax.


podperson(Posted 2004) [#5]
By control I mean there are less commands available for sprites than there are for 2D images


A sprite in Blitz3D is a 3D object not a 2D object, so it has an ENORMOUS number of commands relevant to it... you need to remember it's an entity and anything you can do to an entity, you can do to a sprite. (Note that by default sprites face the camera, but you can change override that).

If you're looking for a bunch of sprite-specific commands that eliminate the third dimension (which is what HUD libraries do) then you're basically missing the point.


Vorderman(Posted 2004) [#6]
I've just posted this code on the other Army men thread, but maybe it's suitable for here also -

www.jameskett.dsl.pipex.com/splatterfest.zip

it siumlates sprites with a single surface system, allowing you to animate them by moving the UVs of each quad. They clip correctly as they are just another 3d poly, and it seems to be able to cope with quite a lot before slowing down.


WillKoh(Posted 2004) [#7]
I have no speed issues but another sprite issue. I've been giving SpriteControl a go and modified the ImageToSprite function tro write other values than $FF to the alpha byte of the texture (see the for..next x,y) in that function. It seems that transparancy becomes either full or none. I have used the alpha flag on the texture in case you wonder. Mine, and I believe many others's reason for using 2d-in-3d sprite libs is to have fast alpha. While the 'mixing 2d & 3d' example that comes with SprteControl surely demonstrates alpha on the sprite (the logo) it does this by setting one EntityAlpha for the whole sprite. I'm not very familiar with 3d programming, but I expected writing the alpha byte would set a value for that particular pixel

Is it fundamentally impossible or is it just me that's made a bug in the for..next x/y loop? For example (in spritecontrol.bb ImageToSprite function, if we use a 256x256 image):

	For x=0 To iw-1
		For y=0 To ih-1
			rgbc=ReadPixelFast(x,y,ib) And $00ffffff
			If rgbc=((r Shl 16)+(g Shl 8)+b)
				WritePixelFast x,y,($00000000),tb
			Else
				WritePixelFast x,y,(x Shl 24 Or rgbc),tb ; changed from $ff alpha byte
			EndIf
		Next
	Next



WillKoh(Posted 2004) [#8]
Hrm.. i solved it. The important thing is to set 'force high color' flag, but it cannot be masked..


jhocking(Posted 2004) [#9]
As podperson said, there are considerably MORE commands you can use on a 3D sprite than on a 2D image. Perhaps you should give use specific examples of image commands you would like to use on a sprite but which you don't know how, and we'll either a) explain how to do it, or b) realize that's a limitation of 3D sprites.