Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Sprite problem?

Author
Message
Hangar18
18
Years of Service
User Offline
Joined: 13th Mar 2007
Location:
Posted: 23rd May 2009 14:46
Hi All, I'm so nearly finished my first game but cannot seem to work out whats going wrong with this sprite code. The problem manisfests itself in two ways. Either when I exit the inventory screen, the game freezes (white screen) or if this doesnt happen then the third time (and its always the third), I enter the inventory sub I get the error message "bob does not exist" which I know relates to sprites.

The full code is too large to reproduce here in its entirity so I'm hoping someone might be able to see something obvious thats wrong with these sprites.

Thanks in advance

The Code...

MAIN LOOP
Landsize=5000
set camera range 10,Landsize*2
"If click on backpack icon then gosub Inventory"
END MAIN LOOP

Inventory:
set camera range 1,3000
backdrop on

while...
....
..
if Mouseclick()=0 then ObjectRelease=0
for i = 1 to 16
If ValidSlot=0: Rem ie not a backpack spot availabel only for big backpacks
if MX>HandItem(i,4)-sprite width(HandItem(i,1))/2 and MX<HandItem(i,4)+sprite width(HandItem(i,1))/2
if MY>HandItem(i,5)-sprite height(HandItem(i,1))/2 and MY<HandItem(i,5)+sprite height(HandItem(i,1))/2
if objectpickup(1)=0 or objectpickup(1)<>Handitem(i,1)
type=HandItem(i,2)
No=HandItem(i,3)
gosub handweapons
text 810,380,name$
for z = 1 to 7
gosub yellow:if val(Attr$(z,2))>0 then gosub red
text 810,380+z*20,Attr$(z,1)
next z
endif
if mouseclick()=1 and ObjectRelease=0
ObjectRelease=1
if ObjectPickUp(1)=0
if HandItem(i,2)<>0
for z = 1 to 28
ObjectPickup(z) = HandItem(i,z)
next z
endif
else
ValidDrop=0
if ObjectPickUp(11)>0 and ObjectPickUp(11)=HandItem(i,2) then ValidDrop=1
if HandItem(i,11)>0 and HandItem(i,11)=ObjectPickUp(2) then ValidDrop=1
if ObjectPickUp(1)>6110
if Handitem(i,6)>Dex then Validdrop=0
if Handitem(i,7)>Int then Validdrop=0
if Handitem(i,8)>Cha then Validdrop=0
if Handitem(i,9)>Ant then Validdrop=0
if Handitem(i,10)>Str then Validdrop=0
endif
if Handitem(i,1)>6110
if ObjectPickUp(6)>Dex then Validdrop=0
if ObjectPickUp(7)>Int then Validdrop=0
if ObjectPickUp(8)>Cha then Validdrop=0
if ObjectPickUp(9)>Ant then Validdrop=0
if ObjectPickUp(10)>Str then Validdrop=0
endif
if ObjectPickUp(1)<6111 and i<11 then ValidDrop=1
if ObjectPickUp(1)-6100=i then ValidDrop=1
If ValidDrop=1
OldObj=ObjectPickUp(1)-6100
ObjectPickUp(1)=0
for z = 2 to 28
if z<>4 and z<>5
HandItem(OldObj,z)=HandItem(i,z)
HandItem(i,z)=ObjectPickUp(z)
ObjectPickUp(z)=0
endif
next z
sprite HandItem(i,1),HandItem(i,4),HandItem(i,5),HandItem(i,12)
sprite HandItem(OldObj,1),HandItem(OldObj,4),HandItem(OldObj,5),HandItem(OldObj,12)
endif
endif
endif
endif
endif
endif
next i
if objectpickup(1)>0
Sprite objectpickup(1),MX,MY,objectpickup(12)
type=ObjectPickUp(2)
No=ObjectPickUp(3)
gosub handweapons
Gosub Green
text 810,520,name$
for z = 1 to 7
gosub yellow:if val(Attr$(z,2))>0 then gosub red
text 810,520+z*20,Attr$(z,1)
next z
endif
Endif
sync
endwhile
backdrop off
set camera range 10,Landsize*2
Return
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 23rd May 2009 15:29
man in the post forum message box there a button called code

copy-paste the entire code in, highlight it and hit that button to put it into a box like this:



There are only 10 kinds of people in the world, those who understand binary and those who dont
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 23rd May 2009 18:34
@Hangar

What does handweapons: do? Maybe there is code in that routine that changes some of the sprite attributes.

If you delete an image before deleting a sprite, you can run into problems

If you use memblocks to manipulate images you may inadvertantly overwrite beyond the memblocks size.

There are some clitches I remeber with sprites that caused system crashes... had something to do with images not being presents or changed/deleted before delting the sprite and then calling the sprite...

Enjoy your day.
Hangar18
18
Years of Service
User Offline
Joined: 13th Mar 2007
Location:
Posted: 24th May 2009 16:11
@That1smartguy: thanks I wondered how people did that but was too lazy to ask

@latch: thanks, i've checked and its not because i delete images before the sprites - nor is it down to the handweapons routine (which is fairly harmless and doesnt deal with sprites at all). Also I dont use memblocks, simply load the images before hand and then use in the sprite.

I wondered if it maybe had something to do with the changing of "set camera range". If worst comes to worst I can redo this bit of code and use images on plains but thats a bit of a pain because sprites are so easy to move with mouse commands.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 24th May 2009 18:58
If you are running your program with SYNC ON : SYN RATE something,
make sure after using GET IMAGE that you are calling SYNC.

For bob does not exist, that is an error in response to doing something to a sprite that has been created. So, look at the code where you are moving, scaling, sizing, mirroring ,etc a sprite. Where ever the manipulation of a supposedly existing sprite is, that's where the problem might be. Could be trying to move a sprite that was deleted in a previous call.

And what about this line:
OldObj=ObjectPickUp(1)-6100

Is the value still valid here?
sprite HandItem(OldObj,1),HandItem(OldObj,4),HandItem(OldObj,5),HandItem(OldObj,12)

Enjoy your day.
Hangar18
18
Years of Service
User Offline
Joined: 13th Mar 2007
Location:
Posted: 26th May 2009 06:25 Edited at: 26th May 2009 06:28
Thanks Latch. I tried placing a sync after every load image or sprite command but it didnt work. However, the problem seems to have gone away now I've moved the "delete sprite" for/next loop at the end of the code (I didnt put it in the copied code above but it does exist just before the last line "return").



I moved it to a much later point - basically when the player reenters the space ship instead of just returning to the ground FPS mode. This seems to have worked without any memory loss problems happening.

One thing I dont get with sprites is why you have to keep "creating them". I.e. typing in sprite NO,X,Y,Image every time you go through a loop or move them. Why not just type "position sprite No,X,Y"?
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 26th May 2009 09:16 Edited at: 26th May 2009 22:27
Don't know if it was the case or not, but always delete the sprite before deleting an image or you can run into trouble.

Quote: "One thing I dont get with sprites is why you have to keep "creating them". I.e. typing in sprite NO,X,Y,Image every time you go through a loop or move them. Why not just type "position sprite No,X,Y"? "


If I were to guess, it's because they aren't real sprites. A sprite in this case being a MOB (movable object block) or a BOB/BLOB (blitable object block). They are probably closer to BOBS (that's what they were originally called in DB). BLiT basically means block transfer or copy a chunk of memory and write it to a new place, usually to the display area. While I think sprites are blitted in DB, they are only images and "not their own thing" so to speak. When an image is associated with a sprite in DB, the engine just continually rewrites (i.e. blits) that image to the display. The act of spriting tells DB to do this and the sprite itself relies on the memory address of the image; and the sprite as an entity only identifies if the image data should be blitted. This way you could use the image as a texture and a sprite and an image, if you like. The sprite won't take up any additional memory by storing it's own image.

So every time you call sprite,x,y,image , it sets up the continual blitting of the image to the display. That's why in DBC sprites slow things down so much because they have to have their own process to redraw them and clear what's behind them (unless you turn backsave state off). The sprite is never really an entity (like it was on older computers or perhaps how the newer version of directx handle them by making them 2d-3d planes) but an indicator of whether or not to continually redraw an image. But I'm only guessing based on observation.

Enjoy your day.
Hangar18
18
Years of Service
User Offline
Joined: 13th Mar 2007
Location:
Posted: 26th May 2009 13:43
Ah ok, that makes lots of sense. Just one thing though - when you say sprites slow things down I presume you mean just when using them in an operation/sub routine. Once deleted DBC should resume to normal speed? (what ever normal speed was pre-sprite creation) This seems to be the case for me and because I'm not doing anything too fancy with them (simply moving equiqpment from one slot to another) when I do actually use them I havent really noticed a slow down. Presumably if I used heaps of them at one time and/or used lots of mathmatics, it might create a slow down.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 26th May 2009 22:25 Edited at: 26th May 2009 22:29
Deleting them when done pretty much turns them off so things should return to normal. A few don't do too much damage anyway. However , a single sprite that's as large as the screen can eat a lot of resources. But that can be tempered with turning off the backsave and the transparency or even hiding the sprite and using paste sprite instead. The sprite collision can still be used when the sprite is hidden so usually the best way to go if you want to use sprites (for collision, scaling, etc.) is to hide them, and paste them using paste sprite. And turning off backsave and using your own screen management to clear the sprite (like cls or pasting a new image on the screen).

Enjoy your day.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 26th May 2009 22:30 Edited at: 26th May 2009 22:38
theres a cool extras program that came with DBC that ran like 1000 sprites at once with 0 fps drop, Ill track it down and show you

this isnt it but under the Dark BASIC folder theres a folder called extras, in that is a folder called Richard Davey, in that is a folder called 3d_sprites, in there is a .dba file, run it

There are only 10 kinds of people in the world, those who understand binary and those who dont
Hangar18
18
Years of Service
User Offline
Joined: 13th Mar 2007
Location:
Posted: 28th May 2009 05:50
Thanks guys!

Login to post a reply

Server time is: 2025-06-08 11:01:29
Your offset time is: 2025-06-08 11:01:29