Page 1 of 2

RealTime LIghting Demo!

PostPosted: Tue Mar 20, 2012 7:17 pm
by Hblade
I hope someone can explain how to make this into a circle :P That'd be cool! :D
s.png


Lighting.zip
(424.46 KiB) Downloaded 684 times


HOW IT WORKS:
It uses a canvas, set the canvas to your color, then use the command "SetLight(x, y, width, height);"

But because of an unknown bug, when setting the y, make sure you set +half of height, like this:
Code: Select all
SetLight(xmouse, ymouse+32, 64, 64);

Otherwise, your light is gonna end up above the Y position you told it to.

Re: RealTime LIghting Demo!

PostPosted: Tue Mar 20, 2012 7:36 pm
by skydereign
I wouldn't use a canvas to make circles (at least how I think you are going about it). To do that you need to use putpixel, and it is slow. Nothing realtime about it. Anyway, take a look at the new ged (note you made it rather hard to use with the + and - adjustments based off of width). Also, just to teach you something, you were wasting a lot of loops doing the lineto method. The pen (from setpen) is a square. So you set its width or height, and just put the pixel at the position X, Y.

Re: RealTime LIghting Demo!

PostPosted: Tue Mar 20, 2012 7:40 pm
by Hblade
Oh wow :oops: tahnks sky.

This is fantastic!

Re: RealTime LIghting Demo!

PostPosted: Sun Jul 08, 2012 9:21 pm
by bat78
I make the circle decently for flashlight and add sequence.
Do u allow me to add the lighting into the one of my games hblade?

Re: RealTime LIghting Demo!

PostPosted: Sat Jul 14, 2012 11:56 pm
by Hblade
Thats up to you lol :)

Re: RealTime LIghting Demo!

PostPosted: Wed Sep 26, 2012 1:50 am
by 247wkman
I MADE A BETTER LIGHT BASE ON THE PREVIOUS EXAMPLE ABOVE! I ATTACHED THE RE-TWEEKED GED BELOW

Still messing around with geds to figure the what-can-do's of g.e (and still finding it sainer to navigate than game maker..)
I just got a reply from lclMetal on youtube when i mentioned how to use draw functions to make a filled circle to create canvas lamp circles that can intersect each other and it helped me re-aprouch using images instead of pen funtions agian. And this time i got it right!

Basically use a non alpherd image of a filled circle- g.e will ignore the border color leaving you with just the circle.
However, even if you set the transparency to nothing, canvas erase won't draw over it.
So what you get is a clean circle image that can rub out the blackness of your dark room and merge with other instances of itself drawn around other actors.
The only remaining problem is how do you control draw order to overide how it was originally written in the script, so that dimmer lights or lights that are dimming (like if the battery was running low) will be drawn over by any brighter lights you approuch.

(canvas light circle/ lantern circle / tourch light tourchlight / draw circle)

Re: RealTime LIghting Demo!

PostPosted: Sun Jun 17, 2018 2:03 am
by ZeldaFan
it is possible to do for actors that will be created?

Re: RealTime LIghting Demo!

PostPosted: Sun Jun 17, 2018 5:12 am
by lcl
ZeldaFan wrote:it is possible to do for actors that will be created?

Hello ZeldaFan. I don't quite understand your question, could you explain it a bit more precisely. I would like to help you.

Re: RealTime LIghting Demo!

PostPosted: Sun Jun 17, 2018 8:40 pm
by ZeldaFan

Re: RealTime LIghting Demo!

PostPosted: Mon Jun 18, 2018 8:34 pm
by lcl
ZeldaFan wrote:https://youtu.be/vVP74TJsEvY

Ah, I understand. Yes, it is possible to add the light to actors created during the runtime of the game. All you have to do is to use getclone() and a for-loop to iterate through the actors, and call the SetLight() function for each of them.
I would advise you to not use the original function by Hblade, but instead use the version skydereign made, because, as skydereign pointed out, Hblade's version can easily cause performance problems. If you want the light to be a rectangle instead of a circle, just change the animation of the "white" actor to a rectangle.

Re: RealTime LIghting Demo!

PostPosted: Mon Jun 18, 2018 10:00 pm
by ZeldaFan
can you give me an example?
I've never used getclone!
SetLight is used by the canvas, not by the actor. Even so, will it work?

Re: RealTime LIghting Demo!

PostPosted: Tue Jun 19, 2018 12:23 pm
by lcl
Here's what the GE Script Reference says about getclone().

http://game-editor.com/docs/script_refe ... m#getclone
GE Script Reference wrote:getclone: Get Actor with name cloneName.
Actor *getclone(char *cloneName)

cloneName: nameactor.cloneindex
(Example: ship.1, ship.2, ...)
Return Actor if successful, invalid Actor (with cloneindex = -1 and name = "") on error.


So, it is a function that returns an Actor pointer (Actor *) to the given actor.

Here's an example code that makes all the clones of the actor "myActor" red by setting their g (=green) and b (=blue) attributes to 0. For this code to work, there has to be a global integer variable called "highestCloneindex" that contains the cloneindex of the newest clone of "myActor" i.e. the clone that has the highest cloneindex.
Code: Select all
int i; // Iterator variable
char tempName[50]; // Temporary string for the name of the clone to be handled
Actor *actorPointer = NULL; // Pointer to the clone to be handled

for (i = 0; i <= highestCloneindex; i ++) // Iterate through all the clones of the actor
{
    sprintf(tempName, "myActor.%i", i); // Build the clonename for the clone of cloneindex i
                                        // Example: if i is 3, tempName will be: "myActor.3"

    actorPointer = getclone(tempName); // Get a pointer to the clone

    actorPointer->g = 0; // Set the green value of the clone to 0 via the pointer
    actorPointer->b = 0; // Set the blue value of the clone to 0 via the pointer
}

You can use a similar code to add lights to the positions of the clones.

ZeldaFan wrote:SetLight is used by the canvas, not by the actor. Even so, will it work?

Yes, what I meant is that in the code of the canvas actor, you call the function for drawing lights to the positions of the clones. As SetLight() is a drawing function it can only be used on a canvas actor.

Re: RealTime LIghting Demo!

PostPosted: Thu Jun 21, 2018 11:28 pm
by ZeldaFan
https://youtu.be/TIMOpNaaNyY

done is done!
:lol:

thaks guys!

Re: RealTime LIghting Demo!

PostPosted: Fri Jun 22, 2018 1:13 pm
by lcl
Nice!

Remember, if your game starts slowing down because of the lights, I'd advise you to use skydereign's version instead of Hblade's. His version also supports having lights of other shapes than a square.

Re: RealTime LIghting Demo!

PostPosted: Sat Jun 23, 2018 9:25 pm
by ZeldaFan
in my fan game, I used a drawfrom code!
allows you to animate the light.

:D
https://youtu.be/8g1hddIcoS0