This code doesn't work, Why?

Blitz3D Forums/Blitz3D Beginners Area/This code doesn't work, Why?

Apollonius(Posted 2003) [#1]
Ive been looking at it for half an hour and I still cant find whats wrong with it, it says bad image handler, whats wrong?
AppTitle "Met"
Graphics 640,480,16

Global SamusSprites=LoadAnimImage("images\SAMUS2.png",85,85,0,24)

MaskImage SamusSprites,255,255,255

SetBuffer BackBuffer()

Repeat

Cls
DrawImage SamusSprites,0,0,0
Flip

Until KeyHit(1)



GfK(Posted 2003) [#2]
Probably "samus2.png" isn't big enough to contain 24 85x85-pixel images/frames.

Throw in a "Stop" command after LoadAnimImage and see if SamusSprites = 0.


Apollonius(Posted 2003) [#3]
it can whole a bit more then 24 85x85 i check it

Anyway I dunno how to do what u just told me to do :|


---edited
If SamusSprites=0 Then
Notify "ERROR!!!"
EndIf
???



i get the error message :| "ERROR!!!"


Apollonius(Posted 2003) [#4]
I got this below to work...

for next is a dangerous command! its hard to make it quit the game i had to press ESC a few times before it would quit the animation :|

Graphics 640,480,16,2

Global SamusSprites=LoadAnimImage("images\SAMUS2.png",85,85,0,22)

If SamusSprites=0 Then
Notify "ERROR!!!"
EndIf

MaskImage SamusSprites,255,255,255
SetBuffer BackBuffer()

Repeat

Cls
For IMG = 0 To 20
Delay 200
DrawImage SamusSprites,30,30,IMG
Flip
Cls
Next

Until KeyHit(1)



MSW(Posted 2003) [#5]

for next is a dangerous command! its hard to make it quit the game i had to press ESC a few times before it would quit the animation :|




well this is obvious

Repeat

Cls
For IMG = 0 To 20
Delay 200
DrawImage SamusSprites,30,30,IMG
Flip
Cls
Next

Until KeyHit(1)


you are doing the whole animation...all 21 frames (For 0 to 20) AND setting a delay of 200 with each frame....lets see...thats 21 X 200millsec = 4200millisec or just over four seconds before your program checks the keyboard buffer...that a bit over four sections between each time the program checks the keyboard buffer...it takes less time for the computer to clear the keyboard buffer...try this instead:

Graphics 640,480,16,2

Global SamusSprites=LoadAnimImage("images\SAMUS2.png",85,85,0,22)

If SamusSprites=0 Then
Notify "ERROR!!!"
EndIf

MaskImage SamusSprites,255,255,255
SetBuffer BackBuffer()
IMG%=20

Repeat


IMG=IMG+1

IF IMG > 20 THEN IMG = 0

Cls

Delay 200
 
 DrawImage SamusSprites,30,30,IMG

Flip


Until KeyHit(1)


should fix the stopping problem


WolRon(Posted 2003) [#6]
I always use this method to load files:
imgWins = LoadImage("graphics\wins.png")
If Not imgWins Then RuntimeError("Error: Can't load graphic: wins.png. Reinstall program.")



semar(Posted 2003) [#7]
@Kaisuo,
if you are using B+, then check that the image you provide is really a .png image.

From what I have experienced, a .bmp image saved as a .png, but still a .bmp image, does not cause any problem in B3D, if loaded as a .png; but if you do so in B+, then the image is not loaded properly, hence the error.

Sergio.


CS_TBL(Posted 2003) [#8]
why not make a little more advanced funtion, like:

CLoadImage(file$,flags)

and put this command in a decl. file so that it highlights..?
Function CLoadImage(file$,flags=1)
	img=LoadImage(file$,flags)
	If Not img
		Notify file$+" not found!",True
		End
	Else
		Return img
	EndIf
End Function


..where the C in CLoadImage could be like 'Confirm' ..


rdodson41(Posted 2003) [#9]
Kaisuo, I see you posted this same question twice. First you should checck to see that you have saved the .bb file. LoadImage/LoadAnimImage don't work when you haven't saved the program! If that is the probelem, then your fine now. If not, then you should check that the path you put in is valid. If it is incorrect then you should see your error. I also see you're using "images\SAMUS2.png" and not "C:\BlitzBasic...images\SAMUS2.png". You should make sure that the saved file is in the parent directory of "images", if it isn't then it won't beable to find the "images\SAMUS2.png".

I hope it helps!


Apollonius(Posted 2003) [#10]
Rich I had checked that before using the "Anim" command the DrawImage command worked. And I always save my project before I starts and I always put my images in the images directory so thats no problem, the problem was there wasnt 24 frame... it was 22.