Tutorial
Page 5 of 10
Lights Part I
cpu와 필요없는 그리기 기능을 없애는데 서피스가 사용되는 것을 공부했습니다. 서피스가 인스턴스를 잡아 내서( 실은 지한테 그리게 하는거지만 ) 인스턴스 종료후에도 계속 그려지도록 할 수 있는 것을 봤습니다. 서피스의 다른 기능을 봅시다.... 라이트!!!
We have shown how surfaces can be used to draw static images to save cpu and draw cycles, and we have seen how surfaces can be used to "catch" instances and display them while the instance itself is removed, so now lets look at another application for surfaces... Lights!
게임메이커에는 라이트효과를 추가하는 방법이 많지만, 이 예제에서는
스프라이트에는 더해지는(점점 밝아지는) 블렌등 효과를 사용하고
서피스에는 빼는 (점점 어두워지는) 블랜드 효과를
최종 목표는, 구멍이 난듯한..
There are many, many ways to do lighting effects within GameMaker:Studio
but for this example we are going for a simple mixture of additive blending on sprites, and subtractive blending on a surface, with the final goal being a surface with holes "punched" in it to allow the additive lights to show through. Sound complicated? It's not!
기본 라이트 오브젝트를 추가합니다. (obj_Light)
obj_Light 에 'spr_Round_Light' 스프라이트를 추가합니다.
깊이값을 (depth)를 -1600으로 설정
Create Event를 추가하고 다음 코드를 추가:
First thing's first. Let's create our base light object. Create a new object, call it "obj_Light" and assign it the sprite called "spr_Round_Light" from the sprite resources. Set it's depth to -1600, and then give it a create event with the following code:
위의 코드는 스프라이트의 x,y 크기를 두배로 세팅한다.
반투명 값을 0.5로 설정.( 너무 밝지 않게 )
라이트 인스턴스에 랜덤 색상을 블렌딩할 색상으로 할당한다.
컬르는 옵션이지만 어떻게 결과가 나올지 알아보기 위해서 사용한다.
The above code sets the image xscale and yscale to be twice the size of the sprite
(you'll find out why in a moment), sets the alpha to be 0.5 (so the light won't be overpoweringly bright) and assigns a random colour to be blended into the final light instance.
The colour part is optional,
but we'll use it just now to give an interesting effect and to illustrate what can be done.
draw event를 추가하고 다음 코드를 추가:
Now add a draw event and give it the following code:
위의 코드는 더해지는 블렌딩 효과를 사용한 위치에 스프라이트를 그린다. 더해지는 효과는 점점 밝아지게 되는데 폭발, 레이져, 라이트 같은 느낌이 난다.
룸의 아무 곳이나 인스턴스를 추가해서 결과를 확인한다.
인스턴스가 추가되면 그 부분은 좀 더 밝아 보이는데, 어두운 부분은 없다. 효과로서는 별로다. 따라서 이런 곳에 서피스를 사용한다.
The above code simply draws the sprite at it's position within the room using an additive blend mode, which is an excellent blend mode for all sorts of "bright" effects, like explosions, lasers and, obviously, lighting.
You can place some of these instances in your room now if you wish to see what happens... they do look a bit like lights, but there is no darkness to offset them with, so it's not really that good an effect. Which is why we are going to use a surface!
시작 전에,
플레이어를 위한 라이트 오브젝트를 만든다. 플래시 라이트를 들고 있게 하고 그 후에 서피스가 리얼타임으로 어둠 속에서 사용 되는지 본다.
However, before doing that,
let's create another light object for our player, so that he can have a flashlight and that way we can see how the surface we use for the darkness is updated dynamically in real time whenever the player moves across the screen.
'obj_Player_Light' 오브젝트를 새로 추가
적당한 스프라이트를(엥??) 할당하고 -1600으로 깊이값을 설정
'obj_Light'를 부모로 설정. (해서 부모 속성을 내려 받도록 ) 부모 관계 설정은 서피스 그리기 코드를 더 쉽게 해준다.
For this make another new object, call it "obj_Player_Light", assign it the appropriate sprite from the sprite resources, then set it's depth to -1600.
Now, give it the previously created "obj_Light" as it's parent so that it inherits the parent objects properties. This will also make the surface drawing code easier!
새 오브젝트에 create event 를 추가하고 다음 코드를 추가:
In thecreate event for our new object, place the following:
step event 에 이것을 :
And in the step event this:
라이트가 플레이어 오브젝트를 따라 가도록 만든다. 몸통이 가리키는 방향과 같은 방향으로 설정된다. ( 플레이어의 b_angle
변수에 의해 조절된다. )
하지만 오브젝트를 실제로 만들기 전까지는 아무 것도 안보인다.
"obj_Player" 의 create event에서 "obj_Player_Light"를 만든다.
These codes will make the light follow the player object and always point in the same direction as his body (this is controlled in the player by the b_angle
variable),
but unless we actually create this object then we won't ever see it working!
So add an extra line into the create event of the "obj_Player" object to create an instance of the "obj_Player_Light".
다음으로 가기 전에 이번에 추가한 것을 직접 확인해보자. 다음 페이지에서는 서피스에 어두움 효과를 추가한다.
You can test the game again now and see what it looks like before moving on to the next part where we will add the surface darkness.
Next 버튼을 눌러서 다음 페이지로 갑시다.