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 / Slow scrolling issue on Starfield

Author
Message
mmouse
8
Years of Service
User Offline
Joined: 6th Nov 2015
Location:
Posted: 6th Nov 2015 22:13
Hi,

I have copied some code from https://www.youtube.com/watch?v=VwMm_tG79zE to create a vertical scrolling starfield.

The video shows 2000 stars flying across the screen but I can only create this effect with a few[img]null[/img] dozen.

Whilst I'm not using the most powerful gamign PC (i3, 4gb, Win10 - on board graphics) I was hoping that it would be able to do this......

My code is here

staramount = 100
xres = 800
yres = 600

Type StarField
x as integer
y as integer
s as integer
endtype

dim stars(staramount) as StarField

set display mode xres,yres,32
sync on
sync rate 60

for x = 0 to staramount
stars(x).x = rnd(xres)
stars(x).y = rnd(yres)
stars(x).s = rnd(5)+1
next x


do
cls
for x = 0 to staramount
inc stars(x).y, stars(x).s

if stars(x).y > yres
stars(x).x = rnd(xres)
stars(x).y = 0
endif

ink rgb(stars(x).s*50,stars(x).s*50,stars(x).s*50),0
Dot stars(x).x,stars(x).y
Next x
Sync
Loop
LBFN
16
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 7th Nov 2015 16:56 Edited at: 7th Nov 2015 17:01
Hi, I'm not sure why this got moved to the DarkBasic Classic board, as it clearly is DB Pro code.

Anyway, the program runs fine on my rig, but it is a tad faster than what you have (I7 quad core at 3.2 per core). To make it run faster, you can use the LOCK PIXELS along with UNLOCK PIXELS commands. I ran it at SYNC RATE 0 using the following code. It ran at 1800 FPS without locking/unlocking the pixels and 3600 with it, so literally a double speed increase. Check it out:



EDIT: I forgot to mention that using the DOT command is not the most efficient way to do this, and there are other options available to you, but if you are new to DBP, it should work for you. An advanced option would be using MEMBLOCKS to accomplish what you want. Do a forum search for them and you should be able to find some decent examples.
So many games to code.....so little time.
mmouse
8
Years of Service
User Offline
Joined: 6th Nov 2015
Location:
Posted: 7th Nov 2015 21:26
Many thanks - the lock pixels thing worked!!! I also moved the print fps just before the sync too.

Thanks for you help

Login to post a reply

Server time is: 2024-03-28 14:54:41
Your offset time is: 2024-03-28 14:54:41