123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|518|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Concept/Design -> CLS

Mon, 08 Nov 2010, 01:09
Jayenkai


The mentality is such.
You take the screen, you draw objects onto it, like a blank piece of paper.



You're teaching kids the basics, and they need to understand the logic of it.




By using Clear Screen, you're telling the kid "Every frame, we get a blank sheet of paper to draw on"



You're trying to get them to understand WHY it's important to clear the screen, so that they don't end up with layer upon layer upon layer of their sprites moving in a really odd manner.

In animation terms, it's taking all the cells away, and starting again with the background layer.
In doodle terms, it's a plain piece of paper.

.. If on the other hand you teach them to fling a rectangle over things, here's what happens....




It's all tallied up, with layer upon layer upon layer getting bigger and bigger.
The animation cells below the camera have reached the camera, and the video is ruined.
The tip-ex on the sheet of paper is 17 meters high, and you're struggling to doodle about the lumpy mess.

It's a big horrible chaotic scene!

CLS : Clear the screen. That's why it's been there this whole time.
It might not do anything that isn't elsewhere, but it's important in the mindset of the first time user.

-=-=-
''Load, Next List!''
Mon, 08 Nov 2010, 09:09
JL235
Still not convinced. I don't see how having a second colour just for clearing is needed.
Mon, 08 Nov 2010, 10:48
spinal
second color?
Mon, 08 Nov 2010, 11:21
JL235
By second colour I mean a clearing colour.

Without a clear colour I don't even see a point in using clear since I'll just be redrawing over it with the colour I want.
Mon, 08 Nov 2010, 12:14
bram32
In education, I noticed a lot of people nowadays have trouble understanding this cls-drawimage-flip principle.
They seem to assume that each image that is drawn onto the screen consumes memory. The logic behind this is 'I see an object, so the object is there'. A bit like as if drawimage=createsprite.
The comparisation with a piece of paper that gets redrawn over and over again doesn't seem to come naturally.
As a result, they think that clearing the screen clears memory (as in release/freeimage). I'm not sure if either a Cls or DrawRect will help.
I think these folks are ready for a sprite engine, where objects are loaded once, and redrawn automatically, until they are freed.
It is a good think though, to be able to change the background color. Loading a sprite as a background isn't the first thing people think off.
Mon, 08 Nov 2010, 12:32
JL235
I think the current mainloop system is too archaic, but in the sprite based systems I've used I usually find them too limiting (but much faster and easier to do the common tasks).

If anything though Bram's argument supports my claim about CLS being pointless. CLS is not clearing away the memory of old drawn images, it's just updating the data on the screen. So keeping it is a misnomer and so using a fill function is just more honest to the user: 'it fills the screen'.

|edit| I also want to keep the API I'm writing as simple and low as possible. There is a saying I saw on Channel 9 by Anders Hejlsberg (the lead developer on C#) that it's better to add layers of abstraction then to raise the layers of abstraction. So I'd rather build a sprite based system on top later. |edit|
Mon, 08 Nov 2010, 13:33
spinal
would cls not be faster to clear the screen that creating a solid rect? surely cls would just clear one memory block, whereas a rect would have to do math to draw the rect line by line...

-=-=-
Check out my excellent homepage!
Mon, 08 Nov 2010, 15:51
JL235
I'm personally only really interested in discussing this from a conceptual point of view.

But implementation wise it would be trivial to optimize filling a rectangle the size of the screen to be as fast as just cls().

Currently I'm providing a 'fill()' function in the library I'm writing which is the same as clear only it uses the current colour.

My main question that started all this is simply that there just doesn't seem to be any point in having two functions (one for setting clear colour and one for clearing) when these can be simply done using the rest of the library. It's defining specialist functions for 1 specific case.
Mon, 08 Nov 2010, 15:55
Jayenkai
You're not doing Sprites, and Objects and things in your language. Instead you're drawing to the buffer.

If you want to go, then go ahead and do the rect thing, it doesn't really matter from the user's standpoint, since it's the same end result.


Write two things in your next post.
1. Explain to a new user how to clear the screen if you use CLS.
2. Explain to a new user how to clear the screen if you don't use CLS.

Whichever you feel most comfortable to have in your how-to, that's the one you should use.

-=-=-
''Load, Next List!''
Mon, 08 Nov 2010, 16:06
JL235
I wasn't fully convinced about my argument until I wrote this. I am now.

Without CLS

At the start of each frame we need to fill the screen with a background colour. This is to appear behind everything we draw later. To do this just use 'setColor' (which we used earlier) and then fill with the 'fill' function.

Fill works the same as fillRect however it fills the whole screen.



With CLS

At the start of each frame we need to clear everything that is on the screen so that it's empty. But we need to clear it to a background colour, the colour that we want to appear behind everything else that we draw later.

To set the colour we need to use a new function: 'setClearColor', which works the same as setColor but only affect the 'cls' function. Then we clear using the 'cls' function (this stands for 'clear screen').

Cls works the same as fillRect only it applies to the whole screen. Again it also uses the clear colour rather then the standard colour.


Mon, 08 Nov 2010, 16:21
Jayenkai
Job Done