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.

2D All the way! / sprites temporarily vanishing when new ones are created

Author
Message
glint
22
Years of Service
User Offline
Joined: 9th Feb 2004
Location: the Synth
Posted: 25th Jun 2004 07:39
I've already got my main character sprite, my tile-loading bitmap world, and some wall sprites that create and delete themselves and move themselves around.

Now I've added projectiles. When I did this, I made sure that the projectiles would not cannibalize the sprite numbers of my character and the walls.

Yet for some reason my main character and wall sprites keep vanishing whenever I create projectiles. Sometimes they flicker out of existence and reappear instantly (irritates the eyes); sometimes they will vanish for several seconds, even after all the projectile sprites have deleted themselves.

I have absolutely no idea what is going on. As I said before, I've ensured that the projectile sprites do not steal the numbers of my other sprites, so that is not the problem.

Can someone help me?
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 25th Jun 2004 11:20
It's probably your code.

glint
22
Years of Service
User Offline
Joined: 9th Feb 2004
Location: the Synth
Posted: 25th Jun 2004 20:15
Could my sprites be disappearing because I am assigning them numbers out of order with the order in which they are created?
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 25th Jun 2004 20:51
Nope...... You must be assigning them twice somehow. Try posting the code.

glint
22
Years of Service
User Offline
Joined: 9th Feb 2004
Location: the Synth
Posted: 25th Jun 2004 22:09
I am right now trying to isolate this problem from my program. When I figure out what is going on, I will write a small version and post it here. I can't put the entire thing here; there is way too much irrelevant stuff in it.

I had one idea, though. Could my disappearing sprites be a result of gaps between numbers?

I basically have a sprite number one (which is always refreshed in the main loop), some wall sprites (numbers 2 to 10) which are also refreshed every step. Then I add projectiles, whose numbers go from 80 up.

When I create the projectiles, my main character sprite and my walls sometimes vanish. The period of time that expires before my main character reappears differs from the time before the walls reappear. When I add more projectiles, the flickering becomes faster and faster. Sometimes the very first projectile will make my sprite number one vanish for up to ten seconds.

By experimentation, I have concluded that my walls and main character are not being deleted, and they are not being hidden (though I can't see them on the screen). And like I said before, I know the projectile sprites aren't stealing their sprite numbers.

At this point, my only clue to this bizarre sprite behavior is the gap between the number of my last wall and the number of my first projectile. But I have a feeling that this is not what is causing my problems.

I'll be back soon with code.
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 25th Jun 2004 22:44 Edited at: 25th Jun 2004 22:48
glint,

Without seeing any of your code, my best guess is that you have loop(s) inside your 'main game-loop'. You are probably updating the projectile code and incrementing more than one frame of animation before returning to your main loop. This is preventing your main loop from reaching the sync command at the end and redrawing your sprites.

If this is the case, you need to implement a method to make sure you are not syncing in a loop, that is nested inside your 'main game-loop'. To do this, write your code so that each object only updates one frame of animation for each iteration of the loop. And then 1 sync at the end should refresh the screen for that frame of animation.

This is the reason why 'game-loop logic' needs to be in-time with the refresh rate. It is quite possible that if the above is not the case, then it could be a problem of the loop-logic iterating through more times then the screen can refresh. So you must implement some timer code to make sure your 'main game-loop logic' is only processed once per screen refresh. Then if you need specific animations to run faster or slower than others you will need to write specific timing code for each animated sprite. If the sprite frames follow a set order and don't skip frames; you may be able to use the play sprite animation command.

~Zen


glint
22
Years of Service
User Offline
Joined: 9th Feb 2004
Location: the Synth
Posted: 26th Jun 2004 03:08
I have finally found out what is going on here. This is very interesting; I've never heard of anything like this before.

I've isolated the problem in the code below.



"Image" should be a 100X100 image, and the bitmap should be at least that size. The set sprite diffuse command is used here so you can tell the difference between sprite number one and the "test sprites".

When you run the program like this, things should work fine. Sprite number one should be visible. No matter how high "walls" is set, nothing odd will befall sprite 1.

Then set variable "imagenumber" to 2. When you run the program again, sprite number one will constantly vanish and reappear briefly. In fact, if "walls" is set to anything above 2, you probably won't see sprite 1 at all.

It seems that all along my problem was coming from making sprites out of images which I had cut from bitmaps.

If anyone knows the technicalities behind this phenomenom, or how to remedy it, please tell me.

Note : You should find that "Sprite exist(1)" will return 1 and "Sprite hidden(1)" will return 0, even when sprite 1 seems to have disappeared.
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 26th Jun 2004 03:36 Edited at: 26th Jun 2004 03:45
First, I may be confused but you are using the command sprite which requires the syntax
sprite spritenum,xpos,ypos,imgnum

where spritenum, xpos, ypos, imgnum should be integers
In your game-loop:
The last three paramaters you are using something like sprite x(a).

[edit] I understand that these commands return integers but I'm not sure what the results from having them in the sprite command itself. I would probably have xpos=sprite x(a) ypos=sprite y(a) first and then use xpos & ypos in the sprite command. But Then again I'm just overly paranoid.

--------------------------------------------------------------------
I'm not sure if this is the case here, But whenever I use the load image command, if follow it with a paste image command, and then I get the image just like using load bitmap. for example:

load image "filename",tempimgnum,1
paste image tempimgnum,0,0,xsize,ysize
get image 1,0,0,xsize,ysize
delete tempimgnum

I can't remember the exact reason I started doing this, but I believe it could have been from a problem like you are describing.

when loading media I reserve a few image numbers and bitmap numbers to hold the temporary image. usually 1000-1005 or so.

If you could, please try that and let me know what the results are.


zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 26th Jun 2004 03:53
I'm still a bit confused as to what effect you are going for here. But is it possibel that the sprites that are being diffused wind up being on-top of your other sprite. (your using a rnd number to position the diffused sprites)

try setting the sprite priority of the sprite you always want to see at 1 and set the other sprites to a higher priority number.

Forgive me for stabbing at thin air here. It's possible that my brain is just fried today and I'm not thinking clearly right now.


glint
22
Years of Service
User Offline
Joined: 9th Feb 2004
Location: the Synth
Posted: 26th Jun 2004 09:10
First of all, the rnd() statements are just a quick way to get some test sprites into the program. They work fine.

The point here is that sprite 1 will not behave the same way if "imagenumber" is set to 2 instead of one. As I said before, I believe this is because the diffused sprites are then using an image cut from another bitmap - I guess the program ends up trying to handle bitmaps 0 and 1 at once, which would explain the way sprite one will sporadically vanish and reappear (or vanish completely) if "imagenumber" is set to 2.

I need to be able to use the get image command for getting sprites from bitmaps. It would allow me to greatly compress the game's file size (or lightly compress it - this isn't my area of expertise).

At any rate, I'm dying to know what is causing this problem. If any of you out there have spare time, please cut my code snippet and paste it into the interface to see what happens.
the_winch
23
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 26th Jun 2004 12:04
After you have used GET IMAGE on a bitmap you can delete the bitmap if you no longer use it.

Your snippit works fine for me.
If you are running in 16bit try changing to 32bit, dbpro can behave odd in 16bit. Perhaps check you have latest graphics drivers as well.

can i scream
glint
22
Years of Service
User Offline
Joined: 9th Feb 2004
Location: the Synth
Posted: 26th Jun 2004 23:49
I tried switching to 32-bit, but sprite 1 was still only randomly visible when "imagenumber" was set to 2. Could this problem be because I have multiple bitmaps loaded at once?

My video card is very up to date; I don't think it's the source of the problem.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 26th Jun 2004 23:54
Multiple bitmaps could cause the problem if you are grabbing sprites off the wrong screen, but again that is hard to say without the seeing the code that you use with multiple bitmaps. If your code works on other computers then it is something to do with your computer.

glint
22
Years of Service
User Offline
Joined: 9th Feb 2004
Location: the Synth
Posted: 27th Jun 2004 00:04
I have finally figured it out. The reason was that image 1 had a "1" flag at then end, while image 2 did not. When I added a "1" to the end of the get image statement, things worked fine.

If you're going to use sprites, make sure that their images all have the same mipmapping flag.
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 27th Jun 2004 01:53
Glint,

Nice Job in staying with it! I wouldn't have guessed that.

I am writing it into my notes for future reference, and will be adding it to my 2D Princinples thread/tutorial. Of course youll be mentioned as the discoverer.

Thanks for posting back and letting us know the resolution.

~zen


ToXic
23
Years of Service
User Offline
Joined: 8th Sep 2002
Location: Australia
Posted: 27th Jun 2004 09:14
Glint, Your code works ok here also, just curious what is your video card. Perhaps someone else with the same card can test it.


ToXic.

Login to post a reply

Server time is: 2026-06-09 19:41:16
Your offset time is: 2026-06-09 19:41:16