IonicWind Software

IWBasic => Games and Graphics => Topic started by: aurelCB on January 05, 2012, 03:41:51 PM

Title: LoadSprite problem...
Post by: aurelCB on January 05, 2012, 03:41:51 PM
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?
Title: Re: LoadSprite problem...
Post by: LarryMc on January 05, 2012, 06:32:35 PM
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
Title: Re: LoadSprite problem...
Post by: aurelCB on January 06, 2012, 04:54:57 AM
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