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! / 2d terrain question --- I need a "paint bucket" routine

Author
Message
Jeku
Moderator
22
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Vancouver, British Columbia, Canada
Posted: 7th Oct 2004 12:47 Edited at: 7th Oct 2004 12:48
Hey everyone,

I'm working on my 2D Scorched Earth remake, and I have a large problem with my terrain. The way I have the terrain drawn I've just plotted the top layer of the dirt. Basically I have an array for the Y height for 1-800 X values (800x600).

My problem is I have no idea how to quickly draw in a solid colour beneath the top layer. I have tried using 800 line commands from each point to the bottom of the screen, but that makes the game run slooooowww...

I wouldn't mind either being able to fill it in with a solid colour or maybe have a graphic image that I can tile across.

Anyone have any ideas? I'll put your name in the credits of the game if I use your idea.

Thanks

Here's a screenie:




--[Gang Wars of New Canada]-- TGC Compo Game --
Agent
21
Years of Service
User Offline
Joined: 7th Sep 2004
Location: Sydney, Australia
Posted: 7th Oct 2004 16:58
Just an interim solution, not efficient but more efficient than yours:

Calculate the lowest point using a simple for next loop through the array and setting the lowest value you find to a variable. Then, plot a line from each point only to that lowest index rather than the absolute bottom of the screen. Then use the BOX command to fill in the lowest, now square, portion of the terrain.

It'll probably be, on average, about twice as quick as the routines you're using now.

Still not a really efficient solution, though. I guess you'd need a DLL with a paint routine in it.
Peter H
22
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 7th Oct 2004 23:30
try using "lock pixels" BEFORE your line commands

and then "unlock pixels" after them(and before you sync)

it speeds it up a whole lot...and maybe you'll just be able to use lines

"We make the worst games in the universe."

the_winch
23
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 8th Oct 2004 01:04 Edited at: 8th Oct 2004 01:05
Need more info really, does it scroll and if so how big is the terrain, is it destructable?

One way would be to build an image in a memblock and just paste it to the screen. If it doesn't scroll and isn't destructable it would work well as you would only need to build the image once and will be a lot faster than lines.

Shrink dbpro exes with upx
can i scream?
Jeku
Moderator
22
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Vancouver, British Columbia, Canada
Posted: 8th Oct 2004 03:27 Edited at: 8th Oct 2004 03:28
@Agent - I was thinking of using one large box for the region from the lowest point to the bottom of the screen, and then using the lines for the top. I think, like you said, it would still be too slow. For one thing, and you can correct me if I'm wrong, the interpreter would still be outputting 800 lines, and it doesn't matter how long the lines are--- it would still run just as slow.

@Peter X - Thanks for the lock/unlock tip--- I'll try that when I get home tonight I have zero experience using those types of commands (get pixels pointer, etc.) because the manual is so scarce with information about them. I'll let you know what happens.

@the winch - Sorry about being a bit vague--- my terrain is truly 800 pixels wide. The only scrolling my game does is on the Y-axis when a player fires a shot. The terrain will be destructable and deformable. By building an image into a memblock, do you mean one large landscape image? My goal is to use random landscapes ala Scorched--- right now it builds the landscape randomly using a cosine wave.


--[Gang Wars of New Canada]-- TGC Compo Game --
the_winch
23
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 8th Oct 2004 04:20 Edited at: 8th Oct 2004 04:22
Yes one big image that you will just paste to the screen.
It's pretty easy to write you own functions that replicate the 2d commands (dot, point, line etc.) but work on memblocks instead. Then instead of drawing the terrain to the screen you would draw to the memblock instead. Then make an image from the memblock and paste it to the screen.

Generating an image from the memblock is pretty quick. It will be fast enough if you are just removing chunks from the terrain. You can also get rid of the array and use the memblock data for collision.

Shrink dbpro exes with upx
can i scream?
spooky
23
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 8th Oct 2004 05:37
Another tip. Never use line or dot in a completely 2D game environment. They are too damn slow. BOX is hundreds of times quicker.

Try this for size:

It draws 800 lines every frame and still runs at over 400fps!!



Boo!
Jeku
Moderator
22
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Vancouver, British Columbia, Canada
Posted: 8th Oct 2004 06:47
Spooky! Thanks, man! That code runs at a smooth 335fps for me, which is well enough as much as I need! I had no idea that box was so much quicker than line.

Thanks all again for your help


--[Gang Wars of New Canada]-- TGC Compo Game --

Login to post a reply

Server time is: 2026-06-11 21:22:11
Your offset time is: 2026-06-11 21:22:11