Setlucent doesn't cooperate.
Displaying 1-8 of 8 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Keast

So there's a party. Everybody's dancing to the tune of What Is Love by Haddaway. Just what is missing?

Oh yes, the party lights. I tried putting this in there:

void mango()
{
	setLucent(20);
    hookretrace("flidance");
}

void flidance()
{
	if ((timer - zeit) = 27)
	{
		c1 = Random(0,255);
		c2 = Random(0,255);
		c3 = Random(0,255);
		zeit = timer;
	}
		RectFill(0, 0, ImageWidth(screen), ImageWidth(screen), RGB(c1,c2,c3), screen);	
}


But of course, the lucency does nothing and the rectangle is fully opaque. My next shot was at rectangling into a semi-translucent layer, but how exactly do I do that?

PS: This is actual gameplay.

Posted on 2011-06-06 17:34:31 (last edited on 2011-06-06 17:36:43)

mcgrue

Two things:

1.
The "if ((timer - zeit) = 27)" line looks very suspicious. What's timer set to, and what do you expect it to be? What's zeit (apart from the german word for Time) set to and what do you expect it to be? Why 27? Don't you want == instead of =?

2.
I _think you want to do this:
void mango()
{
    setLucent(20);
    hookretrace("flidance");
    setLucent(0);
}

Posted on 2011-06-06 18:14:08

Keast

At mapcall, I set timer = zeit. Every 27/100 sec the rect is supposed to change its color. So if timer - zeit equals 27, the colors are randomly changed. But THAT part seems to work alright.

...what's the difference between = and == ? Both seem to do the same.

Also, your solution doesn't give me any other result. I think that is because setlucent is just changed once and then set back to 0, rather than rendering only the rectangle at 20% and the map underneath fully opaque.

Posted on 2011-06-07 06:17:02

mcgrue

Okay, I'm going to need to try this myself to work through it.

Unfortunately you have to wait until I get done with m y work day.

I'll try to get Ustor or Overkill to answer this first.

Posted on 2011-06-07 12:20:35

ustor

Okay, let's start with your most recent question: the difference between = and ==:

== is equality (e.g. a == 10 means "a is equal to 10", which may or may not be true)

= is assignment (e.g. a = 10 means "assign the value of 10 to a") and is the only way to assign a value to a variable. However, in VC, = can also be used to check for equality, based on context. For example if (a = 10) will check to see if a has a value of 10. This can also be presented with a more confusing example: a = b = c. What this will actually do is check to see whether b is equal to c and assign the resulting boolean value to a.

I would personally recommend that you always use == to check for equality and = for assignment. In many other C-like languages, that is exactly how = and == work and following this convention can make your code easier to read and can help you transition to other languages more easily in the future.

In this particular case, though, you should actually be using >= operator. The reason is this: flidance() has been hooked to retrace, so it gets called once per render loop, but you're checking for equality with the logic loop (timer). These two are *not* in lockstep with each other. So on one render pass, timer - zeit may be 26, but the next render it may be 28 and you'll have skipped 27 completely, meaning that your event (the color change) will *never* occur.

The second thing that stands out (which is what you're actually asking about) is where you're calling setLucent() from. Your assumption that it's only getting called once and then reset is correct. What you want to do is set the lucent every draw (by calling flidance(), in this case), not when you hookretrace it (which doesn't actually call flidance at all, it just sets it up to be called on each retrace thereafter). Moreover, McGrue is correct that you'll want to "reset" the lucent after drawing with lucency, otherwise everything drawn afterward will be drawn with that same lucency (unless / until it gets set by something else).

One other (very) small suggestion is that you can subtract 1 from the width and height of the RectFill() call. Because the screen coordinates start at 0 instead of 1, using screen's width and height as coordinates will actually go 1 pixel past the right and bottom of the screen. It's likely that the clipping region for the screen helps mitigate the cost from drawing outside the screen, but because lucent drawing is more expensive and you're drawing something screen-sized, it's worth the trouble to add two little "- 1"s.
Edit: according to Overkill, this does not actually help since the clipping rectangle is applied regardless, so you might as well let it do its thing. The code has been updated to reflect this.


All of these suggestions are represented and commented in the code block below:

void mango()
{
	hookretrace("flidance");
}

void flidance()
{	
	if ((timer - zeit) >= 27) // Use >= here because timer and the retrace loop may not ever sync up the way you want
	{
		c1 = Random(0,255);
		c2 = Random(0,255);
		c3 = Random(0,255);
		zeit = timer;
	}

	setLucent(20); // Set to desired lucent
	RectFill(0, 0, ImageWidth(screen), ImageWidth(screen), RGB(c1,c2,c3), screen);
	setLucent(0); // Reset lucent to prevent it "trickling through" the rest of your drawing
}


Edit: Fixed some stuff that Overkill noticed was incorrect. What a jerk swell guy.

Posted on 2011-06-07 13:16:16 (last edited on 2011-06-07 13:51:43)

Keast

Thanks and uhh I feel stupid. Though you are right, this really kills the framerate... :(

Posted on 2011-06-07 14:49:23 (last edited on 2011-06-07 14:51:06)

ustor

It's been a while, but I'm pretty sure that some of the lucent values are optimized since the multiplication can be made faster internally. I think it was multiples of 25 (0, 25, 50, 75, 100), so try using those. In your example you're using 20, which is not going to be significantly different looking from 25, but switching to 25 should give you a substantial performance boost.

I don't know what resolution your game's screen is set to, but this will also have a bigger impact as the size increases. At 320x240 you can throw all kinds of stuff at it before it starts to chug, but drawing something across the whole screen at a larger size (e.g. 640x480) is going to eat a lot of performance, especially if you're using lucent drawing.

If you're using a larger resolution right now and plan to use lots of visual effects, particularly those that use big art or irregular / dynamic translucency, consider going with a lower resolution if it's not already too late.

Posted on 2011-06-07 15:08:17

Keast

Yep, you pretty much nailed it with 640x480. Setting it to a multiple of 25 does not appear to make any difference, however.
But then again, my notebook seems to have some kind of problem with Verge's rendering: As soon as I start literally anything Verge-related, the fan hits the... I mean, 50% CPU usage is quite normal, which it shouldn't be, I think.

Posted on 2011-06-07 16:59:29


Displaying 1-8 of 8 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.