Author Topic: LoadSprite problem...  (Read 1325 times)

0 Members and 1 Guest are viewing this topic.

Offline aurelCB

  • Hero Member
  • *****
  • Posts: 1008
LoadSprite problem...
« 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:
Code: [Select]
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:
Code: [Select]
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?
forum for hobby programming:
http://basicpro.mipropia.com/smf/index.php

Offline LarryMc

  • Administrator
  • Hero Member
  • *****
  • Posts: 5964
  • 'All I like is finishing'
Re: LoadSprite problem...
« Reply #1 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.
Code: [Select]
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

Offline aurelCB

  • Hero Member
  • *****
  • Posts: 1008
Re: LoadSprite problem...
« Reply #2 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:
Code: [Select]
WAITUNTIL run = 0
IF sprite <> NULL then FREESPRITE sprite
« Last Edit: January 06, 2012, 04:59:09 AM by aurelCB »
forum for hobby programming:
http://basicpro.mipropia.com/smf/index.php