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.

Dark GDK / Sprite afterimage appears

Author
Message
Justin AnyhowStep
13
Years of Service
User Offline
Joined: 17th Jul 2011
Location: Use of uninitialized variable
Posted: 8th Sep 2011 14:43
I made a little camera panning system for this game I'm making and when I tested it out, I noticed this.. afterimage issue.

Is there a way to fix it?
My code is basically:

Figure out which tiles to show
Calculate screen offset of tiles
Set the image of some sprites to the tiles to show
Set the sprite's position to the calculated screen offset

I have 16 X 21 (rox x column) sprites that make up the game world at any given time.

Even if the world is 100x100 tiles big, I only have 16 x 21 and the images these sprites represent changes based on some simple calculations.

The only Image function I use is "dbLoadImage" and the only Sprite function I use is "dbSprite"

First year student of a game-programming course

Attachments

Login to view attachments
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 8th Sep 2011 17:46
Are you using dbCLS() to clear your scene each frame? It looks like you turned off the background and the "after images" are just sitting on the background.

The fastest code is the code never written.
Justin AnyhowStep
13
Years of Service
User Offline
Joined: 17th Jul 2011
Location: Use of uninitialized variable
Posted: 8th Sep 2011 21:54
Yeah, I am.


First year student of a game-programming course
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 9th Sep 2011 04:08
Show the entire code (render loop) and I might be able to help.

The fastest code is the code never written.
Justin AnyhowStep
13
Years of Service
User Offline
Joined: 17th Jul 2011
Location: Use of uninitialized variable
Posted: 9th Sep 2011 07:40
Erm..
I'll try.

*Goes off to comment bits of code*



And the loop:


First year student of a game-programming course
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 9th Sep 2011 23:37 Edited at: 9th Sep 2011 23:41

I noticed you are not clearing the tile_val_map[][]. If you get to the edge of the map and not clear the value, you will not set the value to anything. Therefore it will be whatever it was before you got to the edge. I hope that makes sense.....
EDIT:
Here is an updated code I think will work for you:

You MAY want/need to make a condition to draw a blank spot when the image number is '0'.

The fastest code is the code never written.
Justin AnyhowStep
13
Years of Service
User Offline
Joined: 17th Jul 2011
Location: Use of uninitialized variable
Posted: 10th Sep 2011 01:47
Oh my-
That worked like a charm and I understood after seeing it in action =)

Thanks for the help.
I've got another, unrelated, question.

Can I draw primitives over sprites?
Like:
dbBox(0, 0, 32,32);
dbSprite(1, 0, 0, 1);

The sprite seems to always be above the box no matter what =/
Oh, and same goes for text.

Can I use dbPrint and have the words appear above the sprites?

First year student of a game-programming course
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 10th Sep 2011 03:08 Edited at: 10th Sep 2011 03:09
for text, you can do this:
make the sprite (dbSprite)
hide the sprite (dbHideSprite)
paste it as image (dbPasteImage)

then text will appear on top of it, though, can't remember if text had to be before this, or after, or if that even matters, experiment and figure it out

as for drawing commands, i'm not sure, but they might also behave as the text would

Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 10th Sep 2011 04:32
Yes. You have to manually place the sprites. You can also get rid of duplicate sprites that way (the way Hassan was saying). I think he mistyped, though.

make the sprite (dbSprite)
hide the sprite (dbHideSprite)
*use dbPasteSprite(sp,x,y);

This will, of course, completely change the way you do it, but I think it's better. Considering the level of detail you understand about classes, I think you can manage the change.

One more thing, any time you use a "paste" like dbPasteSprite(..) or dbBox(..) you have to do it inside (or call a function) your render loop. This will make it render in the order in which you paste them. If you want a box on top, paste the sprite first and then draw the box (and vice-versa).

The fastest code is the code never written.
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 10th Sep 2011 15:00
oh yes thanks for correction

Justin AnyhowStep
13
Years of Service
User Offline
Joined: 17th Jul 2011
Location: Use of uninitialized variable
Posted: 10th Sep 2011 15:55
Thanks, guys =)

First year student of a game-programming course
Justin AnyhowStep
13
Years of Service
User Offline
Joined: 17th Jul 2011
Location: Use of uninitialized variable
Posted: 10th Sep 2011 19:25
Weird, I can't get it to work for animagted sprites.
It only works for non-animated sprites.



Am I doing something wrong?

First year student of a game-programming course
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 11th Sep 2011 00:06
You need to manually set the frame of the animated sprite and then dbPasteSprite(..) after the scene sprites are rendered (I assume the animated sprite is your character).

The fastest code is the code never written.

Login to post a reply

Server time is: 2024-10-02 19:16:41
Your offset time is: 2024-10-02 19:16:41