Jump to content


Photo
* * * * * 9 votes

Light (Fake!) For Beginner.


  • Please log in to reply
136 replies to this topic

#1 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 17 September 2013 - 03:51 AM

  • Title: Fake light
  • Description: Create simple, fake light
  • GM Version: Studio and 8.1
  • Registered: 8.1 yes, studio? Probably, need confirmation please.
  • File Type: GMZ & GM81
  • File Size: 1.3mo
  • File Link: tuto_fake_light_studio.zip (Studio)
  • File Link:tuto_fake_light.gm8.zip (8.1)
  • Required Extension: None
  • Required DLL: None

You may be interested by my asset on Marketplace: Fake light II

 

 

Hi guys!

 

First: this tutorial is a basic one and it DOES NOT HANDLE SHADOWS!!!

I often see people(beginner) requesting light tutorial...like me when I first start with GM.

Game Maker looks like : "Hey, that's look easy to make a game with that!".

And yeah, thats right. Everyone with basics computer knowledges can actually make a 'game' with GM.

And newcomers want classic feature like lights!

There is a lot of light tutorial but many of them are complicated because they are made to create a 'realistic' light.
They are good! Some damn good! But let's keep it simple for the newcomers.

 

Sometimes, advanced users seems to forget what it is for a newbie to gather informations about something completely unknown.

Every day I read new topics about:

How can I: inventory, healthbar, move, bounce and lights. (and many other things, I know!)

You cannot throw hundreds of lines to a newbie and tel him: "That's easy!".

It's not! ;)

 

So, here is a very simple way to do a FAKE light. Really easy to copy/paste and understand.

What I wanted (back in 2011) is to put all my screen black (well not pitch black, but really dark) and

simply substract a hole in it where the player stand. Like on NES' Dragon Warrior or SNES's famous Zelda:

 

tutofl0.jpg

 

Ok. How it work? With a surface. We will create a surface, paint it in black, draw a hole in it and then

draw that surface.

My downloadable example has 5 rooms. I'll show you 5 simple way to make  fake lights.

 

/////////////////////

First one:Room0

 

tutofl1.jpg

 

I've got 2 objects.

obj_player_0 stand still. No code (except for moving).

 

obj_ctrl_0's code:

Spoiler

Easy huh!? No? Maybe some functions look unfamiliar...but the important line is the draw_circle part. You can draw a square, rectangle, triangle...sprites! (on room2...)

 

///////////

Second one:Room1

tutofl2.jpg

 

obj_ctrl_light_1's code:

Spoiler

Easy huh?...Yeah more complex if you're not familiar with 'for loops'. The thing here is that we draw many circles (bbb): A large one then a smaller, and a smaller and a smaller and a smaller, etc.... Each circle apply a small alpha value on each other.

Let's change the value of bbb to 5:

 

tutofl2a.jpg

You can see the 5 circles!

 

///////////////////////////

Third one:Room2

Now let's draw(well, substract!) a sprite instead of a circle. We use draw_sprite_ext and ajust the angle to follow the player's image_angle.

Looks like a flashlight:

tutofl3.jpg

 

obj_ctrl_light_2's code:

Spoiler

Thats it! This is how I understood how surface works for that simple light....I mean fake light.

 

Edit January 07-2014.

2 more rooms.

 

Room3: If you are using views. (Same picture as room0)

obj_ctrl_light_3's code:

Spoiler

 

Room4: Multiple lights.

2 objects create light here. Normal player and a static player. Both objects substract a circle on the surface.

tutofl4.jpg

 

obj_ctrl_light_4's code:

Spoiler

Edited by NazGhuL, 11 November 2014 - 01:18 PM.

  • 16

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#2 stevie67

stevie67

    GMC Member

  • GMC Member
  • 25 posts
  • Version:GM:Studio

Posted 21 September 2013 - 08:57 PM

NazGhuL

hi mate that is link fixed now thanks again


  • 0

 Remember the little green button if i helped in any way>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> :GM106: 


#3 markhansaven

markhansaven

    GMC Member

  • GMC Member
  • 62 posts
  • Version:GM:Studio

Posted 22 September 2013 - 08:28 PM

I'm probably going to try this out soon and tell you how it goes. Thanks. : )


  • 0

#4 Otyugra

Otyugra

    Artist & Writer

  • GMC Member
  • 618 posts
  • Version:GM:Studio

Posted 23 September 2013 - 07:57 PM

I like tutorials on small things like this, you never know when you might need them or when they'll come in handy. In the post, you shouldn't write each sentence separated with an enter though. I like the traditional paragraph form, people will take you more serious if you write in proper English.


  • 0

r7sNbRa.png  (Nitemare38 = Otyugra)

 

Two and a half years of game development taught me the joy of making something unique and unconventional. It is not good enough to make a game fun when there are way too many other freeware games that make fun their selling point.


#5 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 23 September 2013 - 08:12 PM

people will take you more serious if you write in proper English.

 

They will take me more seriously! I'm taking english courses now to tweak that. :thumbsup: 
I take note of that. Thank you.


  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#6 NotWhoYouThink

NotWhoYouThink

    GMC Member

  • GMC Member
  • 1061 posts
  • Version:Unknown

Posted 28 September 2013 - 12:55 PM

Something as informative as this only with one rep! Shame on you guys! *plusrep*

And Nitemare38:

people will take you more serious if you write in proper English.

You say that, but it's actually people will take you more seriously if you write in proper english. :D


Edited by IceMaster, 28 September 2013 - 12:57 PM.

  • 2

This forum is archived. The above may not reflect my current opinion, or may be irrelevant now.


#7 Otyugra

Otyugra

    Artist & Writer

  • GMC Member
  • 618 posts
  • Version:GM:Studio

Posted 01 October 2013 - 12:09 AM

Funny you mention that, I was going to fix that spelling error but I was only about 40% sure it was incorrect so I decided to leave it the way it is. You get my point though.


  • 0

r7sNbRa.png  (Nitemare38 = Otyugra)

 

Two and a half years of game development taught me the joy of making something unique and unconventional. It is not good enough to make a game fun when there are way too many other freeware games that make fun their selling point.


#8 MathieuG89

MathieuG89

    GMC Member

  • GMC Member
  • 149 posts
  • Version:GM:Studio

Posted 01 October 2013 - 10:28 PM

Hi this is exactly what I was looking for but I can't seem to adapt it to my needs. As soon as I click on ''Enable use of views'' the screen becomes all black. I modified the events as you wrote down in the comments but can't seem to get it to work. Help would be greatly appreciated. Thank you!


  • 0

#9 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 01 October 2013 - 11:05 PM

Have you download one of the examples? Views need some setting to works well.

(port size, view in room, etc...)


  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#10 MathieuG89

MathieuG89

    GMC Member

  • GMC Member
  • 149 posts
  • Version:GM:Studio

Posted 01 October 2013 - 11:21 PM

Have you download one of the examples? Views need some setting to works well.

(port size, view in room, etc...)

 

J'ai télécharger ton exemple pour Game Maker: Studio et dans ''Room1'' j'ai cliquer sur ''Enable use of views''. Dans Obj_ctrl_light_1 j'ai apporté les modifications suivantes: 

 

Create: global.light=surface_create(view_wview[0],view_hview[0])

Draw: draw_surface(global.light,view_xview[0],view_yview[0])

 

Chaque fois j'ai un écran complètement noir. J'ai beau regarder à gauche et à droite je n'arrive pas à le faire fonctionner!


  • 0

#11 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 01 October 2013 - 11:39 PM

I'll PM you. :thumbsup:


  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#12 BelleyStar

BelleyStar

    GMC Member

  • GMC Member
  • 80 posts
  • Version:GM8

Posted 05 October 2013 - 05:29 PM

Ty.


  • 0

#13 BelleyStar

BelleyStar

    GMC Member

  • GMC Member
  • 80 posts
  • Version:GM8

Posted 06 October 2013 - 01:28 PM

How can you make multilight for different objects ?


  • 0

#14 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 06 October 2013 - 08:22 PM

I'm not sure HOW another object can interact with that surface. But you can specify it on that same object. If you change the step event to that:

surface_set_target(global.light)
                                
draw_clear_alpha(c_black,0.85)
draw_set_blend_mode(bm_subtract)

draw_circle(obj_player.x, obj_player.y, 64, false) 
draw_circle(enemy..x, enemy.y, 64, false) 

draw_set_blend_mode(bm_normal)
surface_reset_target()

You will draw a circle on the player and on enemy.


  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#15 Brainiac98

Brainiac98

    GMC Member

  • GMC Member
  • 30 posts
  • Version:GM:Studio

Posted 06 October 2013 - 08:38 PM

It looks like this method would be more efficient, but I use a lighting system like this...

 

2lsw9e0.png

 

what this one does, is basically creates a grid map of black squares, and changes the opacity depending on the distance to a light source, in this case, a character's lantern. in my Minecraft-like 2D game, I use it to have light follow the player, and emit light from placed torches. I like this method, because it gives a blocky feel to the game, and in some cases, it's exactly what you want. it's pretty simple, but PM me if you want to know how it was done.


  • 0

My old finished games, made with a couple friends, can be found here: http://sandbox.yoyog...ReflectionGames


#16 BelleyStar

BelleyStar

    GMC Member

  • GMC Member
  • 80 posts
  • Version:GM8

Posted 07 October 2013 - 05:30 PM

I'm not sure HOW another object can interact with that surface. But you can specify it on that same object. If you change the step event to that:

surface_set_target(global.light)
                                
draw_clear_alpha(c_black,0.85)
draw_set_blend_mode(bm_subtract)

draw_circle(obj_player.x, obj_player.y, 64, false) 
draw_circle(enemy..x, enemy.y, 64, false) 

draw_set_blend_mode(bm_normal)
surface_reset_target()

You will draw a circle on the player and on enemy.

Doesnt work. I see no light. My GML Code:

 

// Belley (obj_player)

var aaa, bbb, i;
aaa=100//Radius in pixel
bbb=50//Precision. The higher the number, the more circles will be drawn(inside the radius) to make the gradient more fluid.


surface_set_target(global.light)/*With this function you set all further drawing to
                                the target surface rather than the screen and in this
                                way you can tell GameMaker:Studio to only draw
                                specific things to the specified surface.*/

draw_clear_alpha(c_black,0.97)//That line make the screen black with an alpha at 0.85
draw_set_blend_mode(bm_subtract) //We're starting to substract here

draw_set_alpha(1/bbb)// The alpha value of 1 i simply divide by the number of circles.

for (i=0; i<=bbb; i+=1)//Now we're looping through all our circles. From the larger to the smaller.
{
draw_circle(obj_player.x, obj_player.y, 64, false)
draw_circle(obj_player2.x, obj_player2, 64, false)
}
draw_set_alpha(1)//Important line to reset the alpha back to 1.
draw_set_blend_mode(bm_normal)//Important thing here! Stop to substract.
surface_reset_target()//With this function you reset all further drawing from the target surface back to the screen.

surface_set_target(global.light)
                                
draw_clear_alpha(c_black,0.85)
draw_set_blend_mode(bm_subtract)

 


  • 0

#17 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 07 October 2013 - 06:28 PM

draw_circle(obj_player2.x, obj_player2, 64, false)
 

should be

draw_circle(obj_player2.x, obj_player2.y, 64, false)

 

You forgot the .y
 


  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#18 Loganvz

Loganvz

    GMC Member

  • GMC Member
  • 317 posts
  • Version:GM:Studio

Posted 11 October 2013 - 08:27 AM

Thanks NazGhuL! Works perfectly for Top-Down Shooters.
Spoiler

But there's just one major problem. It seems you can't change view mode(fullscreen/windowed), which is quite a big problem for me right now. Can you try fix this? Thanks.

Edited by Loganvz, 11 October 2013 - 08:49 AM.

  • 1

#19 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 11 October 2013 - 12:12 PM

I didn't realize that GMS handle surfaces a different way than GM8.

I honestly have to tell you that I'm not yet familiar with drawing a surface on a fullscreen.

 

Nocturne seems to talk about it here: http://gmc.yoyogames...howtopic=552006

 

I'll check on that later and as soon as I understand how I'll update this tutorial. (unless someone can point a good solution.)

(Full screen works on GM8 though.)

 

==edit==

From the manual:

 

  • First, you should realise that surfaces are "volatile". This means that if the device or window loses focus or is minimised (good examples are when a screensaver comes up in Windows, or on an Android device when the app loses focus due to a call) then the surface may be destroyed. This is because it is stored in the vRam and may be overwritten when the target platform needs that memory for something else which means that you should always have some type of fail-safe code in place, usually with the surface_exists function.

 

So I think that the draw part should be:

if surface_exists(global.light)
{
draw_surface(global.light,0,0)
}
else
{
global.light=surface_create(room_width,room_height)
}

I'll try it tonight.

 

==edit==

It's fixed.

GMZ and GM81 uploaded.

Code change on draw event:

if surface_exists(global.light)
{
draw_surface(global.light,0,0)
}

else
{
global.light=surface_create(room_width,room_height)
}
/*Again, if you are using views you chould use:

draw_surface(global.light, view_xview[0...7], view_yview[0...7])
to draw the surface at the 0,0 of the view (and not the room)

Topic edited. Thank you to have pointed me that.


Edited by NazGhuL, 12 October 2013 - 01:26 AM.

  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#20 Tacomaster325

Tacomaster325

    GMC Member

  • GMC Member
  • 31 posts
  • Version:GM8.1

Posted 18 October 2013 - 10:58 PM

Just going to mention that this tutorial says 'Registered: none', but it does actually require registered. At least in GM 8.1.


  • 0

#21 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 18 October 2013 - 11:04 PM

Ok thank you.


  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#22 elvirais

elvirais

    GMC Member

  • GMC Member
  • 41 posts
  • Version:GM:Studio

Posted 21 October 2013 - 08:12 PM

There is by the way a different way of doing this  without surfaces. I'm not saying it's a better method, it's just different :-) You can draw an image that has alpha code in it, e.g. an image that is black but has a circle inside that slowly goes to 100% alpha. You can draw that image on top of all the objects, that works too. Probably much slower, but it might be more compatible with some systems. (I don't use GM:Studio yet, I use GM 8.1).


  • 0

#23 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 01 November 2013 - 05:34 PM

I edit the Topic. Here is a small change:

 

NOTES FOR OPTIMIZATION!!!

In the 3 examples below, ALL the code that are in the step event can be in the draw event. But BEFORE the actual code already in the draw event. So select ALL the code in the step event, CUT it and insert it on the first line of the draw event BEFORE what it is already wrote there. That fixes a little glitches on the third examples.


  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#24 Panzergeist

Panzergeist

    Insane Box Man

  • GMC Member
  • 1241 posts
  • Version:GM8

Posted 01 November 2013 - 05:57 PM

Yo Naz, could you possibly make a GM 8.0 version of the flashlight lookin' one...? That'd be great :D


  • 0

[ ._.]> Where am I...


#25 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 01 November 2013 - 06:19 PM

gm8.1 doesn't work?


  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#26 Panzergeist

Panzergeist

    Insane Box Man

  • GMC Member
  • 1241 posts
  • Version:GM8

Posted 01 November 2013 - 06:25 PM

It might, ill try. i just have 8.1 lite, so i cant export to 8.0  pro. however i just noticed you put the code out there, im so slow ^^' ill try the codes


  • 0

[ ._.]> Where am I...


#27 Tomkowiak

Tomkowiak

    GMC Member

  • GMC Member
  • 275 posts
  • Version:GM:Studio

Posted 05 November 2013 - 09:27 PM

Nice tutorial! Working in studio, no problem.

 

Just little warning. It should be with dynamic surface for bigger projects/rooms. When room is bigger it can crash game with out of memory message.


  • 0

sCflU7N.png


#28 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 06 November 2013 - 12:38 AM

Nice tutorial! Working in studio, no problem.

 

Just little warning. It should be with dynamic surface for bigger projects/rooms. When room is bigger it can crash game with out of memory message.

Thank you.

I don,t know what is a 'dynamic surface', but as I said in the tutorial:

 

/ If you got a room larger than the view/window/display
and use views (view[0...7], you could, use:

surface_create(view_wview[0...7], view_hview[0...7])
So your surface will only cover what the player is currently viewing. (It save a little
bit of ram/cpu)

 

That way you only use a small surface.


  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#29 the_me

the_me

    GMC Member

  • New Member
  • 11 posts
  • Version:GM:Studio

Posted 13 November 2013 - 04:10 AM

Been looking for something just like this! Thanks!


  • 0

#30 mangoskin

mangoskin

    GMC Member

  • GMC Member
  • 78 posts
  • Version:GM:Studio

Posted 01 December 2013 - 09:41 PM

Hi I am using the 2nd way of creating light.

 

I would like to use this to also create light around torches ive created throughout the game.

how would I make this light circle also apply to all my obj_torches as well?

 

i tried just changing the name to obj_torch instead of obj_player, but it did nothing xD

 

simple plz i am noob!

 

EDIT:

 

and also how would I make it so the darkness doesnt cover up my healthbar?


Edited by mangoskin, 01 December 2013 - 10:37 PM.

  • 0

#31 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 02 December 2013 - 12:38 AM

replace:

for (i=0; i<=bbb; i+=1)//Now we're looping through all our circles. From the larger to the smaller.
{
draw_circle(obj_torches.x, obj_torches.y, (aaa-(aaa/bbb*i)), false)
}

by:

with(obj_torches)
{
    for (i=0; i<=bbb; i+=1)//Now we're looping through all our circles. From the larger to the smaller.
    {
    draw_circle(x, y, (aaa-(aaa/bbb*i)), false)
    }
}

 

and also how would I make it so the darkness doesnt cover up my healthbar?

 

Draw your health at a lower depth than the object that draw the surface.


  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#32 mangoskin

mangoskin

    GMC Member

  • GMC Member
  • 78 posts
  • Version:GM:Studio

Posted 02 December 2013 - 03:38 AM

hahaha so fantastic man! thankyou for helping me out, it works beautifully and runs at perfect fps! (the other lighting tuts were so complicated and killed fps!)

 

much respect!


  • 0

#33 Yitcomics

Yitcomics

    GMC Member

  • GMC Member
  • 21 posts

Posted 02 December 2013 - 04:29 PM

I just wanted to know,why did you make 'light' into a global variable,I changed it to local and it works fine,so I just wanted to know was a there a reason or purpose to make it a global variable.Just asking for learning purposes


  • 0

#34 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 02 December 2013 - 04:35 PM

It could be local without problem. The thing that could be usefull is that you can change it from elsewhere EVEN if the object is not in the room. (ie: a pause room). But seriously, that doesn't make any big difference. (well, I think!)


Edited by NazGhuL, 02 December 2013 - 04:36 PM.

  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#35 mangoskin

mangoskin

    GMC Member

  • GMC Member
  • 78 posts
  • Version:GM:Studio

Posted 02 December 2013 - 10:03 PM

is there a way to make the lighting appear with the room?

 

im using method 2, and it works great the only flaw is when the room starts you see a flash of light (and are able to see secret rooms and stuff), then the darkness appears over everything. every time the room is restarted you see the flash of light.


  • 0

#36 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 03 December 2013 - 01:24 AM

Open your room editor and click setting/creation code then add:

 

global.light=surface_create(room_width,room_height)
surface_set_target(global.light)
draw_clear_alpha(c_black,1)
surface_reset_target()

 


  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#37 mangoskin

mangoskin

    GMC Member

  • GMC Member
  • 78 posts
  • Version:GM:Studio

Posted 11 December 2013 - 03:55 AM

haha another question man! 

 

in my game I have a pause menu. you press escape and this code gets excuted:

 

global.roomprev = room
room_goto(Paused)

 

so it brings you to another room (the pause room) while the previous room is still persistent waiting for your unpause.

this pause room has a big torch in the middle lighting up the buttons (super cool effect) but since the pause room is smaller than the persistent room, when you unpause the game ---- the game room lighting is now changed to the pause menu lighting, limiting the lighting effect to the size of the pause menu.

 

I hope I wrote that clear enough to understand!

How could I fix this?


  • 0

#38 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 11 December 2013 - 04:43 PM

The create event of the object controlling the light on your game room must be 're-executed'.

You need to recreate the surface.

 

Maybe the create event of the object_light should be move to the room start event? Try it.


Edited by NazGhuL, 11 December 2013 - 04:43 PM.

  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#39 mangoskin

mangoskin

    GMC Member

  • GMC Member
  • 78 posts
  • Version:GM:Studio

Posted 11 December 2013 - 06:48 PM

EDIT:

actually that worked pretty well as long as 

 

global.light=surface_create(room_width,room_height)

 

isnt in the creation code of the pause menu room.

there is still half a second where you can see the entire room when you unpause which isn't very clean looking but im still a beginner so its not a big deal


Edited by mangoskin, 11 December 2013 - 07:18 PM.

  • 0

#40 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 11 December 2013 - 08:40 PM

Perhaps you could try to make 2 different objects, 2 surfaces. 1 on each room.


  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#41 mangoskin

mangoskin

    GMC Member

  • GMC Member
  • 78 posts
  • Version:GM:Studio

Posted 14 December 2013 - 07:25 PM

how would you make multiple light sizes? so far i have torches and players flashlight the same size light


  • 0

#42 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 14 December 2013 - 07:59 PM

ex1: change the radius of the circle.

draw_circle(obj_player_0.x, obj_player_0.y, 64, false)

 

64 is the radius.

 

ex2:

change the radius.

variable aaa is the radius.

 

ex3: choose a bigger sprite.


  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#43 LuminesenceLight

LuminesenceLight

    GMC Member

  • New Member
  • 17 posts
  • Version:GM8

Posted 05 January 2014 - 04:26 PM

Hey mate! Good work! It's like Fog of War!

 

I need to ask, Is it possible to have multiple instance applying that at the same time?

 

And by the way, it also works on previous version of GM!

 

Edit:

 

Can u make the "fake light" apply at multiple instances?


Edited by LuminesenceLight, 05 January 2014 - 04:32 PM.

  • 0

#44 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 05 January 2014 - 04:53 PM

I will update this tutorial soon. I will ad a room to show how to apply multiple 'substract' to the same surface. I.E. is you need to apply that to multiple obj_torch:

 

Posted 01 December 2013 - 09:24 PM

 

replace:

for (i=0; i<=bbb; i+=1)//Now we're looping through all our circles. From the larger to the smaller.
{
draw_circle(obj_torches.x, obj_torches.y, (aaa-(aaa/bbb*i)), false)
}

by:

with(obj_torches)
{
for (i=0; i<=bbb; i+=1)//Now we're looping through all our circles. From the larger to the smaller.
{
draw_circle(x, y, (aaa-(aaa/bbb*i)), false)
}
}

  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#45 LuminesenceLight

LuminesenceLight

    GMC Member

  • New Member
  • 17 posts
  • Version:GM8

Posted 06 January 2014 - 04:53 AM

Great. but now, here I am wondering can I apply this code to so much torch in my room. Because it's getting laggish... Any chance to improve the performance?


  • 0

#46 DanielEgan

DanielEgan

    GMC Member

  • GMC Member
  • 143 posts
  • Version:GM:Studio

Posted 06 January 2014 - 06:52 AM

I am using views and cant seem to get this to work.  Any help would be appreciated.   I would paste code but all I am doing is swapping out the name of my character object and changing the places where you suggest to use views.

 

Any ideas?


  • 0
Daniel Egan
http://TheSociableGeek.com

Was I helpful? Press the green button below.


#47 LuminesenceLight

LuminesenceLight

    GMC Member

  • New Member
  • 17 posts
  • Version:GM8

Posted 06 January 2014 - 10:45 AM

I am using views and cant seem to get this to work.  Any help would be appreciated.   I would paste code but all I am doing is swapping out the name of my character object and changing the places where you suggest to use views.

 

Any ideas?

It works actually. I'm making maze game and of course it uses views. Just make sure you apply them at different object. Although I guess it will also works...


  • 0

#48 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 06 January 2014 - 11:52 AM

obj_ctrl_light_0 create event:

global.light=surface_create(room_width,room_height)
/*Surface is created here. If you got a room larger than the view/window/display
and use views (view[0...7], you could, use:

surface_create(view_wview[0...7], view_hview[0...7])
So your surface will only cover what the player is currently viewing. (It save a little
bit of ram/cpu)

Create and draw view only on your view using view_xview, view_yview and view_wview and view_hview


Edited by NazGhuL, 06 January 2014 - 11:53 AM.

  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg


#49 DanielEgan

DanielEgan

    GMC Member

  • GMC Member
  • 143 posts
  • Version:GM:Studio

Posted 06 January 2014 - 04:28 PM

UPDATE:   I got it to work but now I have another problem.

 

When I start off, the circle is around my character, but when I move to the right. and the view moves, the focus of the circle moves off of me to the right.  for some reason it does not stay on my characters x, y coordinates.

 

 

 

 

 

 

I did that.  In the create event of the obj_ctrl_light_1 I changed it to the following

global.light=surface_create(view_wview[0],view_hview[0])

in the step event I changed it to the name of my character.

draw_circle(o_char.x, o_char.y, (aaa-(aaa/bbb*i)), false)

And in the draw event I also use views

if surface_exists(global.light)
{
draw_surface(global.light,view_xview[0],view_yview[0])
}

else
{
global.light=surface_create(view_wview[0],view_hview[0])
}

I place the object in my room...

 

nothing shows up.  It is not a top down, it is a platformer but I don't expect that should matter of course. The funny think is that I can get the flashlight to work but not the circle one.. it wont even show the black.. although it is the same code except where it draws the circle or sprite.  Its driving me crazy :)


Edited by DanielEgan, 06 January 2014 - 05:00 PM.

  • 0
Daniel Egan
http://TheSociableGeek.com

Was I helpful? Press the green button below.


#50 NazGhuL

NazGhuL

    From NazTaiL

  • GMC Member
  • 2368 posts
  • Version:GM:Studio

Posted 06 January 2014 - 04:39 PM

First: Is your step event contain only that portion? You got all the code, not only the draw_circle part?

 

Second: On your draw event, it's not:

 

draw_surface(global.light,view_wview[0],view_hview[0])
 

BUT

 

draw_surface(global.light,view_xview[0],view_yview[0])

 

 

You draw it at the X and Y (the 0,0 of the view), not at the width and height.(You draw it offscreen that way.)

 

Thats probably your problem here.
 


Edited by NazGhuL, 06 January 2014 - 04:40 PM.

  • 0

tag_mtmapo.jpgtag_marketplace.jpgtag_fake_light.jpg