Get FrameCount?

BlitzPlus Forums/BlitzPlus Programming/Get FrameCount?

WillKoh(Posted 2003) [#1]
Is there a way to know how many frames are in a loaded image (when passed to a function)?


Andy_A(Posted 2003) [#2]
Const numFrames = 7 (could also be: Global numFrames = 7)
Global imgName = LoadAnimImage("Img.jpg", 64, 64, 0, numFrames)

Now when you use the 'imgName' handle in a function just be sure to pass 'numFrames' associated with that image as a parameter.


semar(Posted 2003) [#3]
@WillKoh,
there's no way to know how many frames are there in a loaded image, unless you keep track of it manually, as Andy_A has spotted.

You could even use a type structure (or an array, if you will load always a fixed number of images), and keep track of image informations in the structure itself.

So, for example, you can use a type like:
type t_info
field img ;will contain the image pointer
field frames ;the info you will use later
end type
Global info_img.t_info ;the type pointer



;when you load an animated image, you can create a new type instance, and store the related info in the fields:
global myimage = loadanimimage("myimg.jpg",64,64,0,10)
create_info(myimage,10)

;=================================
function create_info(img,frames)
;=================================
info.t_info = new t_info
info\img = img ;the pointer to the image
info\frames = frames
end function


;later, you could use this method to retrieve the frames of a loaded image:

frames = info_frames(myimage)

;=================================
function info_frames(img)
;=================================
for info.t_info = each t_info
if info\img = img then
return info\frames
endif
next
return 0
end function


Hope this has sense for you,
Sergio.