nSprite does not draw anything...

Blitz3D Forums/Blitz3D Userlibs/nSprite does not draw anything...

I am using nSprite (Free version but I plan to upgrade as soon as I get my net paycheck!) ANYWAY I am using it to see what kind of a cardgame I can make. I have a PNG like this:

And my code is:
; JUST to see if the card thing works... RWD
Graphics3D 800,600,16,2

SetBuffer BackBuffer()
Include "nSprite.bb"
SeedRnd MilliSecs()
reseed = Rand(1,1000) ;this compensates for known Random bug (just ask 'Morduun' 8)
reseed = Rand(1,1000) 

camera=CreateCamera()
PositionEntity camera,0,0,0
light=CreateLight()
RotateEntity light,45,0,0

nS_Initialize() ; initialize nSprite
card = nS_LoadAnimImage("cards.png",71,96,1,51)

Dim cards%(52)

.reshuffle

shuffle()

While Not KeyHit(1)

;x% = 10
If y% < 13 And x% < 610 Then
	For i% = 1 To 13
		For x% = 10 To 610 Step 200
			y% = y% + 15
				nS_DrawImage(card,x%,y%,cards(i))
			nub = nub+1
		Next
	Next
EndIf

If KeyHit (57) = True Then
	Goto reshuffle
EndIf

;UpdateWorld()
RenderWorld()

Text 0,0,"Sprites: "+nub
Flip

Wend

End

Function shuffle%()
	;Load the cards() array with 52 unique numbers
	;(they just happen to be sequential for now)
	For i% = 1 To 52
		cards(i) = i
	Next

	;Simulate shuffling deck 7 times	
	For i = 1 To 7*52
		;Use indices swap1 and swap2 to scramble deck
		swap1% = Rand(1,52)
		swap2% = Rand(1,52)
		
		;Ensure indices don't point to same element
		While swap1 = swap2
			swap2 = Rand(1,52)
		Wend
		
		;OK, two different elements, perform swap
		temp% = cards(swap1)
		cards(swap1) = cards(swap2)
		cards(swap2) = temp
	Next
End Function

Function getSuit$( integer%)
	;1-13 is a spade,  14-26 is a heart,  27-39 is a club,  40-52 is diamond
	If integer < 14 Then suit$ = "Spades"
	If integer > 13 And integer < 27 Then suit$ = "Hearts"
	If integer > 26 And integer < 40 Then suit$ = "Clubs"
	If integer > 39 Then suit$ = "Diamonds"
	;now we know the suit, make 'integer' a number between 0 and 12
	integer = integer Mod 13
	
	Select integer
		Case  1: value$ = "Ace"
		Case 11: value$ = "Jack"
		Case 12: value$ = "Queen"
		Case  0: value$ = "King"
		Default: value$ = Str(integer)
	End Select
	
	Return value$ + " of " + suit$
End Function
But it draws NADA!!! I know it did a turn through the for/next loop but???

ALSO what is nS_SpriteCount it isn't documented???

RZ

Well, if ns_LoadAnimImage() works like the regular blitz LoadAnimImage (never used nSprite, myself), then I think you need to change this line:
card = nS_LoadAnimImage("cards.png",71,96,1,51)

to this:
card = nS_LoadAnimImage("cards.png",71,96,0,52)


Basically, I don't think your card image is getting loaded, due to the incorrect params.

Nope... still dark...

Stick your RenderWorld and Flip just after the nS_DrawImage line to see what is going wrong... it looks as if you are looping the placement of the cards right off the bottom of the screen before you get a chance to see them !!

I did the same without nsprite and it worls really well... but I wanted a handle on all the cards... Let me try again Blackjumper...

I see what you mean... it is only drawing 1 card, but it really draws three cards soooo fast that it draws 1 sprite with three different faces...

Hmmm... Can I create a deck then using nSprite and manipulate it... Let me try something.

RZ

Still doesn't draw more than 1 sprite though the sprite conter says there is 3... CONFUSED!!!

; JUST to see if the card thing works... RWD
Graphics3D 800,600,16,2

SetBuffer BackBuffer()
Include "nSprite.bb"

SeedRnd MilliSecs()
reseed = Rand(1,1000) ;this compensates for known Random bug (just ask 'Morduun' 8)
reseed = Rand(1,1000) 

camera=CreateCamera()
PositionEntity camera,0,0,0
light=CreateLight()
RotateEntity light,45,0,0

nS_Initialize() ; initialize nSprite

card = nS_LoadAnimImage("cards.png",71,96,0,51)

Dim cards%(52)

.reshuffle

shuffle()

xx% = 10
yy% = 200

For i% = 1 To 13
	y% = y% + 15

	Text  10, y, getSuit$(cards(i))
	Text 210, y, getSuit$(cards(i+13))
	Text 410, y, getSuit$(cards(i+26))
	Text 610, y, getSuit$(cards(i+39))
	Text 320, 570, "( Press any key to exit )"
Next

Input


Flip

a=nS_DrawImage(card,50,50,cards(1)-1) ; have to subtract 1 to show the real card for some reason
b=nS_DrawImage(card,150,150,cards(2)-1)
c=nS_DrawImage(card,200,200,cards(3)-1) ; but it still won't draw more than 1 sprite

UpdateWorld()
RenderWorld()

Text 0,0,"CARD: "+getsuit$(cards(1))+" + "+getsuit$(cards(2))+" + "+getsuit$(cards(3))
Text 0,20,"RAW #: "+cards(1)
Text 0,40,"SPRITES: "+nS_SpriteCount

Flip
Input 
End

Function shuffle%()
	;Load the cards() array with 52 unique numbers
	;(they just happen to be sequential for now)
	For i% = 0 To 51
		cards(i) = i
	Next

	;Simulate shuffling deck 7 times	
	For i = 1 To 7*51
		;Use indices swap1 and swap2 to scramble deck
		swap1% = Rand(0,51)
		swap2% = Rand(0,51)
		
		;Ensure indices don't point to same element
		While swap1 = swap2
			swap2 = Rand(0,51)
		Wend
		
		;OK, two different elements, perform swap
		temp% = cards(swap1)
		cards(swap1) = cards(swap2)
		cards(swap2) = temp
	Next
End Function

Function getSuit$( integer%)
	;1-13 is a spade,  14-26 is a heart,  27-39 is a club,  40-52 is diamond
	If integer < 14 Then suit$ = "Spades"
	If integer > 13 And integer < 27 Then suit$ = "Hearts"
	If integer > 26 And integer < 40 Then suit$ = "Clubs"
	If integer > 39 Then suit$ = "Diamonds"
	;now we know the suit, make 'integer' a number between 0 and 12
	integer = integer Mod 13
	
	Select integer
		Case  1: value$ = "Ace"
		Case 11: value$ = "Jack"
		Case 12: value$ = "Queen"
		Case  0: value$ = "King"
		Default: value$ = Str(integer)
	End Select
	
	Return value$ + " of " + suit$
End Function
But look at this with blitz using regular blitz3d...
; JUST to see if the card thing works... RWD
Graphics3D 800,600,16,2

SetBuffer BackBuffer()
;Include "nSprite.bb"
SeedRnd MilliSecs()
reseed = Rand(1,1000) ;this compensates for known Random bug (just ask 'Morduun' 8)
reseed = Rand(1,1000) 

camera=CreateCamera()
PositionEntity camera,0,0,0
light=CreateLight()
RotateEntity light,45,0,0

;nS_Initialize() ; initialize nSprite

;card = nS_LoadAnimImage("cards.png",71,96,0,51)
card = LoadAnimImage("cards.png",71,96,0,51)

Dim cards%(51)

;For car = 1 To 52
;cardpic[car] = nS_DrawImage(card,Rand(100),Rand(200),car)
;Next

.reshuffle
Cls

shuffle()


For i% = 0 To 12
	y% = y% + 15

	Text  10, y, getSuit$(cards(i))
	
	DrawImage card,yy,230,cards(i)-1 
									
	Text 210, y, getSuit$(cards(i+13))

	Text 410, y, getSuit$(cards(i+26))

	Text 610, y, getSuit$(cards(i+39))

	Text 320, 570, "( Press any key to exit )"
	yy = yy + 72
Next



WaitKey()

End




Function shuffle%()
	;Load the cards() array with 52 unique numbers
	;(they just happen to be sequential for now)
	For i% = 0 To 51
		cards(i) = i
	Next

	;Simulate shuffling deck 7 times	
	For i = 1 To 7*52
		;Use indices swap1 and swap2 to scramble deck
		swap1% = Rand(0,51)
		swap2% = Rand(0,51)
		
		;Ensure indices don't point to same element
		While swap1 = swap2
			swap2 = Rand(0,51)
		Wend
		
		;OK, two different elements, perform swap
		temp% = cards(swap1)
		cards(swap1) = cards(swap2)
		cards(swap2) = temp
	Next
End Function

Function getSuit$( integer%)
	;1-13 is a spade,  14-26 is a heart,  27-39 is a club,  40-52 is diamond
	If integer < 14 Then suit$ = "Spades"
	If integer > 13 And integer < 27 Then suit$ = "Hearts"
	If integer > 26 And integer < 40 Then suit$ = "Clubs"
	If integer > 39 Then suit$ = "Diamonds"
	;now we know the suit, make 'integer' a number between 0 and 12
	integer = integer Mod 13
	
	Select integer
		Case  1: value$ = "Ace"
		Case 11: value$ = "Jack"
		Case 12: value$ = "Queen"
		Case  0: value$ = "King"
		Default: value$ = Str(integer)
	End Select
	
	Return value$ + " of " + suit$
End Function
What am I doing wrong... I know I am missing something simple but important...

I think you are misunderstanding what nSprite does.

In your Blitz only version you are using DrawImage to put pixels onto the BackBuffer and then flipping it to the screen.

In the nSprite version you are using nS_DrawImage but only have a single sprite surface to draw to !!! So every call to nS_DrawImage overwrites the previous one. You will need to nS_CopyImage or nS_CreateImage to get more than one sprite (i.e. card) to play with.

... at least I think that is what is happening

Yeah I am thinking that as well... I recoded it a bit and tried to create a bunch of single images based on the cards images and then plop them... still plugging at it...

But you are right... only 1 sprite to work with unless a createimage with a new handle... If I called the new image by the card number then I could just drawimage by card number and solve most of my probs... let me code on that!