Cls with alpha ?

Monkey Forums/Monkey Programming/Cls with alpha ?

Paul - Taiphoz(Posted 2012) [#1]
can it be done ?

I was messing with a sweet app on the ipad called codea, lua engine for making little games, its cool as hell, something it does is allow cls to work with alpha, which allows for some cool effects like setting cls 0,0,0,150 would alpha the last screen and not fully clear it, giving an automatic trailer effect over all drawn objects.

any ideas?


dawlane(Posted 2012) [#2]
can it be done ?
Maybe if your prepared to modify mojo. But I think it helps if you know OpenGL like the back of your hand. And then it would be a question of whether you could do it across all targets.

I was wondering if it was possible to use the stencil buffer to do some sort of pixel collision detection, but as I said it would be a question of whether you could do it across all targets and would it be fast enough.


dmaz(Posted 2012) [#3]
easy... instead of cls
setalpha .59
drawrect 0,0,DeviceWidth,DeviceHeight


benmc(Posted 2012) [#4]
I just create a solid color PNG at 240x160 and scale it up to my screen resolution and set its alpha, then draw it over the top of everything when I need to do something like this.

Of course you can't alter its color on the fly, but you could probably create 3 PNGs of primary colors and alpha blend them with SetAlpha()


Paul - Taiphoz(Posted 2012) [#5]
which is slower drawrect every frame or scaling up an image every frame.


bruZard(Posted 2012) [#6]
try it out man....


Paul - Taiphoz(Posted 2012) [#7]
I will of course, but always good to ask in case some one else has already tried and got an answer.

dmax that didnt work, cos setalpha sets the drawing alpha for everything, so it just all looked a bit lighter, no motion trail as expected.


bruZard(Posted 2012) [#8]
of course, you have to reset alpha to 1.0 after drawing the rect.


muddy_shoes(Posted 2012) [#9]
You can't rely on consistent results across targets with this method. Some targets are single buffered, some aren't. Some targets clear the render buffer every frame whether you ask for it or not.


Samah(Posted 2012) [#10]
which is slower drawrect every frame or scaling up an image every frame.

Depends on your target. OpenGL targets will just draw without binding a texture (faster, I would assume).


matty(Posted 2012) [#11]
If I understand your goal, you want to draw the current screen over the previous screen which has been faded with alpha. While monkey doesn't seem to allow the old blitz style method of copying from the backbuffer maybe you could just draw everything twice, in the first pass with alpha set to 'x' then the second pass but you would need to record the position rotation and scale of the previous frames sprite/images. Not too hard really if you have a class that handles drawing operations for each frame.


Paul - Taiphoz(Posted 2012) [#12]
Nah thats all to much work for the effect I want as well as creating a lot more overhead which I want to avoid, but the most important thing is that I want the game to look play and feel the same on as many devices as possible.

So if something will not work well on one device then it's not gona make it into the game.

Thanks for all the feedback peeps, it really helps.


Dima(Posted 2012) [#13]
as muddy said - not all targets will work with omitted cls, and will clear the screen anyway or have visual artifacts. I don't remember which ones, but either html or flash has problems with not using cls.


matty(Posted 2012) [#14]
Actually I don't think its much overhead at all.. pretty basic really..