Changing Sprite Arrays

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!
Post Reply
User avatar
ThirtyNitesOfMX
Coder
Posts: 18
Joined: Sun Nov 28, 2010 6:58 pm
Location: seattle, wa

Changing Sprite Arrays

Post by ThirtyNitesOfMX »

I have my game set up like this:

dim shared character sprite arrays

then i set Char1Name$ = whoever i want to be the 1st character

and it will load their sprites as follows:

DEF SEG = VARSEG(Char1Right(0))
BLOAD path$ + "\Characters\" + CHAR1Name$ + "\rightTIL.til", Varprt(Char1Right(0))
DEF SEG = VARSEG(Char1RightMsk(0))
BLOAD path$ + "\Characters\" + CHAR1Name$ + "\rightMSK.msk", Varprt(Char1RightMsk(0))

the first character is the one i want walking around on the field map.
this all works fine.

when i want to switch out characters, i need to replace all the sprite arrays for char1 with different .til and .msk images so it will show someone else walking around on the map.

i thought i would be able to do this by changing Char1Name$ and then importing images again with the same def seg statements but it says "out of range" when i try and do this.

any help would be greatly appriciated.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Did you use DEF SEG AFTER each PUT for the next BLOAD. You need to reset the pointer to the Default.

I assume each character folder has the same names and the array is big enough.

PS: I sent you an email...
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
ThirtyNitesOfMX
Coder
Posts: 18
Joined: Sun Nov 28, 2010 6:58 pm
Location: seattle, wa

Post by ThirtyNitesOfMX »

def seg after each put command?? thats crazy. how come i can PUT over and over. shouldnt i just need to def seg before i load a different image into it?
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

This SUB uses one SHARED Image Integer Array. The sprite is indexed after the mask. Just enter the file names and PUT position. Continue PUTs from Image(0) and Image(10000).

Code: Select all

SUB LoadImage (Mask$, Sprite$, Col, Row)
DEF SEG = VARSEG(Image(0)
   BLOAD Mask$, VARPTR(Image(0))
   PUT (Col, Row), Image(0), AND 
   BLOAD Sprite$, VARPTR(Image(10000))
   PUT (Col, Row), Image(10000) 
DEF SEG   ' Restore default BASIC segment.
END SUB
Size the array for what you need.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Post Reply