"sprSheets[]" are an array of advanced types.
using...
LOCAL ss AS TSprSheet
DIMPUSH self.sprSheets[], ss
self.sprSheets[-1].create("sprites1.png") // .Create
causes...
precompiling:
GPC - GLBasic Precompiler V.7.861 SN:114ddfeb - 3D, NET
"..\LIBS\sprites_lib.gbas"(528) error : call to undefined function : TSprSheet
Changing...
self.sprSheets[-1].create("sprites1.png")
to...
self.sprSheets[LEN(self.sprSheets[])-1].create("sprites1.png")
produces the same error.
but removing the "-1"(self.sprSheets[LEN(self.sprSheets[])].create("sprites1.png")), it compiles fine but is of no use.
Using...
LOCAL L = LEN(self.sprSheets[])-1
self.sprSheets[L].create("sprites1.png")
...works, but is not as neat. Oh, and BOUNDS does not work either(When the LEN is swapped for it).
Cheers,
Ian
Full lib, as it is...
// Spr Sheet Type
TYPE TSprSheet
name$ // Filename
sprnum% // GLB Sprnum holding texture
w% // Width
h% // Height
tw% // Tile Width
th% // Tile Height
trn% // Has alpha layer
FUNCTION create: filename$, tileW%=0, tileH%=0
LOCAL s% = GENSPRITE()
LOADSPRITE filename$, s%
self.name$ = filename$
self.sprnum% = s%
GETSPRITESIZE s%, self.w%, self.h%
ASSERT ((self.w% = 0) OR (self.w% = 0)) // File not open!
self.tw% = tileW%
self.th% = tileH%
ENDFUNCTION
ENDTYPE
TYPE TSprBank
sprSheets[] AS TSprSheet
FUNCTION blah:
LOCAL ss AS TSprSheet
DIMPUSH self.sprSheets[], ss
self.sprSheets[-1].create("sprites1.png") // .Create
///... stopped coding here.
ENDFUNCTION
ENDTYPE
Poor GPC compiler. Feed with stuff he can't digest. Pre-chew it, please:
ALIAS lastsheet AS self.sprSheets[-1]
lastsheet.create("sprites1.png") // .Create
The GPC sometimes has a hard time with complex expressions to find the resulting type. If you ALIAS a part of of, usually it gets the grip and works.
Thanks for that culinary suggestion there Gernot! ;)
I'm not sure I want to use ALIAS as the final Type will have lots of methods within it and it could get a bit messy if I have to ALIAS a lot in the parent code.
I'll have a rethink, thanks any ways.
Ian
This works...
global lastOne% = -1
...
self.sprSheets[lastOne].create("sprites1.png") // .Create
Hehe, looks a little weird but feels better.
Cheers,
Ian
GPC must have taken offense to literal integers:)
try constant instead of global. a tad faster.
It is? Nice tip, thanks!
Cheers,
Ian