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 Professional Discussion / Background sprite "jittery" when scrolling. Need help! Code inside

Author
Message
Jamez0r
13
Years of Service
User Offline
Joined: 30th Jan 2013
Location:
Posted: 30th Jan 2013 19:39
Posted about this an hour ago (still getting processed/approved by moderator so I can't delete/edit the old one), but now I have the actual code to show the problem.

Extremely basic code - press W,A,S,D to move the (background) sprite around. Hold down one of the directions for a couple seconds and notice that it doesn't move smoothly 100% of the time. Every couple of seconds it jitters/lags/something. What am I doing wrong that is producing this jitter effect at a seemingly random interval?

The attached file (testMap.bmp) is the sprite I am using in the code.

zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 30th Jan 2013 21:34 Edited at: 30th Jan 2013 21:57
The first thing I noticed was the bitmap size... 28MBs!?

I cancelled the download for it. I did use a 512x512 jpg in it's place, and it seemed to work fine. If the image is the issue, you might try changing formats from .bmp to .jpg or (i prefer) .png or .dds

If it is too large, you might try chopping it up into smaller manageable chunks? Best of luck!

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
Jamez0r
13
Years of Service
User Offline
Joined: 30th Jan 2013
Location:
Posted: 30th Jan 2013 21:59
Quote: "The first thing I noticed was the bitmap size... 28MBs!?

I cancelled the download for it. I did uses a 512x512 jpg in it's place, and it seemed to work fine. If the image is the issue, you might try changing formats from .bmp to .jpg or (i prefer) .png

If it is too large, you might try chopping it up into smaller manageable chunks? Best of luck!
"


Thanks for the response. The size is not the issue as I have tried with a 400x400 sprite as well as a 40,000x4000 sprite and had the same amount of laggy/jitteryness.

I'll test with a .jpg or .png. Thanks!
Jamez0r
13
Years of Service
User Offline
Joined: 30th Jan 2013
Location:
Posted: 30th Jan 2013 22:09
Ok, I just changed the format to .png and the size of the testMap file went down to 1.2MB (thanks). Attaching the new file to this comment (you'll have to change the extension in the code to test)

This however did not fix the jitter/lag problem.

I have:

1)tested on multiple computers
2)tested with sprite sizes from 400x400 to 40,000x4,000 with the same amount of jitteryness
3)tried offset sprite instead of rotate/move/un-rotate

If someone would verify that it is acting the same way on their computer, I'd really appreciate it. Just pick a flower on the background sprite and follow it with your eyes - hold a direction down for 5+ seconds and you'll see what I mean. It isn't smooth.

Thanks to anyone that could help me with this!!
Jamez0r
13
Years of Service
User Offline
Joined: 30th Jan 2013
Location:
Posted: 30th Jan 2013 22:15
A bit more info - zeroSlave I appreciate you looking at this for me.

Two things:

I tested with 512x512 sprite and it is possible for it to scroll off-screen before you notice the jitter. The .png version of testMap that I attached to my last comment is 2+ screens wide, so it will 100% lag/jitter by the time you get to the top right corner of the sprite.

Also if you are using a solid-color sprite then you won't notice it... it is subtle but very noticeable with the image I attached because you can focus on one of the flowers and see that it goes from smooth to choppy for a moment.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 31st Jan 2013 09:17 Edited at: 31st Jan 2013 09:22
Though unrelated to the issue, why do you have such a large image made up of a small tileable image? Seems like a huge waste of memory.


I thought your movement code was the culprit. Your rotating the sprite to point in the direction you want to move, moving 'forward', then rotating back..... why? Especially for a background. So I changed the code like this: (much simpler movement code)



But that didn't help. I've tried different images, large and small. I still see it. And I don't recall seeing this on my own 2D projects.

But as was discussed in yet another one of your threads about this issue, I've changed the code above to add the vertical sync flag to the set display mode command and that seems to have resolved the issue.

"You're not going crazy. You're going sane in a crazy world!" ~Tick
Jamez0r
13
Years of Service
User Offline
Joined: 30th Jan 2013
Location:
Posted: 31st Jan 2013 14:17
Phaelax, thanks again.

The code was in that funky-format because I had stripped it from my project and deleted the irrelevant lines of code.

Also that background was just a test that I had made quickly. In reality it will be custom-made and not from a tileable image.

Concerning the "rotate + move + rotate back" code - I'm thinking the paste sprite command would indeed be faster. Thanks for the tip!

GLORIOUS, now I can get back to coding (and never be seen in public again!)

Login to post a reply

Server time is: 2026-07-07 00:32:28
Your offset time is: 2026-07-07 00:32:28