March 29, 2024, 12:37:41 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


LoadSprite problem...

Started by aurelCB, January 05, 2012, 03:41:51 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aurelCB

I have weird problem with function LoadSprite.
I try to create minimum code to load and show sprite and
next code work:
WINDOW win
pointer sprite
run = 1


OPENWINDOW win,0,0,400,400,@NOAUTODRAW,0,"Caption",&handler


ATTACHSCREEN(win,400,400)


'BACKPEN BackBuffer,RGB(0,0,255)
'FRONTPEN BackBuffer,RGB(255,255,255)
sprite = LoadSprite(GETSTARTPATH+"mouth.bmp")
IF sprite = NULL then MESSAGEBOX 0,"Sprite not loaded","Error"
frame=0

'DO
FILLSCREEN RGB(0,0,255)
'WriteText 180,0,"PRESS ESC TO CLOSE, FPS: " + str$(speed)
'play with the sprites
'SpriteFrame sprite,frame
DrawSpriteXY sprite,200,200



FLIP


waitUNTIL run = 0
FREESPRITE sprite

CLOSESCREEN
CLOSEWINDOW win
END

SUB handler
SELECT @message
CASE @IDCLOSEWINDOW
IF MESSAGEBOX(win,"Quit Demo?","Quit",@IDOK) = @IDOK
run = 0
ENDIF
CASE @IDCREATE
CENTERWINDOW win
CASE @IDMENUPICK
IF @MENUNUM = 1 THEN run = 0
ENDSELECT
RETURN
ENDSUB


But when i'm try to load sprite inside subrutine then sprite pointer stay
empty  ???
like this:
SUB exec_DXLoadSprite
STRING spriteName
spriteName=GetStrValue(GW2)
MESSAGEBOX 0,"Name:"+spriteName,"OK"
spPointer = LoadSprite(Getstartpath + "mouth.bmp")
IF spPointer = NULL then MESSAGEBOX 0,"Sprite not loaded","Error"
RETURN
ENDSUB


spPointer is global..i don't get it why don't work on this way?
Any idea what might be wrong?

LarryMc

This works for me.
All I did really is name the pointer in the subroutine the smae as the global name.
WINDOW win
pointer sprite
run = 1


OPENWINDOW win,0,0,400,400,@NOAUTODRAW,0,"Caption",&handler


ATTACHSCREEN(win,400,400)


'BACKPEN BackBuffer,RGB(0,0,255)
'FRONTPEN BackBuffer,RGB(255,255,255)
'sprite = LoadSprite(GETSTARTPATH+"mouth.bmp")
exec_DXLoadSprite()
IF sprite = NULL then MESSAGEBOX 0,"Sprite not loaded","Error"
frame=0

'DO
FILLSCREEN RGB(0,0,255)
'WriteText 180,0,"PRESS ESC TO CLOSE, FPS: " + str$(speed)
'play with the sprites
'SpriteFrame sprite,frame
DrawSpriteXY sprite,200,200



FLIP


waitUNTIL run = 0
FREESPRITE sprite

CLOSESCREEN
CLOSEWINDOW win
END

SUB handler
SELECT @message
CASE @IDCLOSEWINDOW
IF MESSAGEBOX(win,"Quit Demo?","Quit",@IDOK) = @IDOK
run = 0
ENDIF
CASE @IDCREATE
CENTERWINDOW win
CASE @IDMENUPICK
IF @MENUNUM = 1 THEN run = 0
ENDSELECT
RETURN
ENDSUB

SUB exec_DXLoadSprite
STRING spriteName
'spriteName=GetStrValue(GW2)
'MESSAGEBOX 0,"Name:"+spriteName,"OK"
sprite = LoadSprite(GETSTARTPATH+"mouth.bmp")
IF sprite = NULL then MESSAGEBOX 0,"Sprite not loaded","Error"
RETURN
ENDSUB


LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

January 06, 2012, 04:54:57 AM #2 Last Edit: January 06, 2012, 04:59:09 AM by aurelCB
Ufff...
problem is in bitmap mouth.bmp...
This bitmap is in another folder then i place bitmap in same folder and work ;)
Thanks Larry...!

One thing is weird ...
If pointer is NULL so sprite is not loaded then after closing window
i recive some sort of program crush...
Why one empty pointer crush program or probably stuck in memory...

Ahh i found what couse crush FREESPRITE...so to preven exit crush i
add this:
WAITUNTIL run = 0
IF sprite <> NULL then FREESPRITE sprite