Tutorial
Page 4 of 10
Decals
근사한 소프트 그림자를 얻기 위해 서피스를 사용하는 것을 공부했습니다. 이번에는 잔해 효과를 만들기 위해서 서피스를 사용해봅니다.
You have seen how using surfaces has saved us drawing multiple instances to create a nice soft shadow effect, so lets now use this same idea and expand upon it to create a debris effect.
데칼 decals이라고 부르는 인스턴스들이 있습니다. 게임플레이에는 아무 영향도 없지만 뭔가 느낌이 있게 하고 사실감을 줍니다. 그래도 이 인스턴스는 룸에 표시되는 숫자를 제한하도록 합니다. obj_Decal에서 Alarm[0] 삭제하고 게임 플레이를 해봅시다. 한동안은 괜찮지만 점점 느려지면서 거의 플레이를 할수 없는 상태가 됩니다.
In our game, we have a series of instances which we have called decals. these instances are nice little effects that offer nothing to the gameplay, but they help give a nice "feel" to our
game and add realism. However, to keep the instance number down as low as possible, we have to limit how many of these instances we have in the room. You can test this and see what happens by
simply removing the Alarm[0] event from the obj_Decal parent object. After playing for a minute or two the game will start to slow down and eventually become un-playable.
서피스가 이런 경우에도 도움이 될까요? 당근임다.
Can surfaces help here? Yes, they most definitely can!
"obj_Decal_Surface" 라는 오브젝트를 새로 만듧니다. 이 오브젝트는 데칼 인스턴스를 잡아 내서 이놈의 스프라이트를 그립니다. 즉, 데칼오브젝트를 삭제할 수 있고 그럼으로서 cpu 사용률을 낮추고 게임 내에 수만개의 오브제트가 있는것처럼 보이게 합니다. 하지만 사실 몇개 안씁니다.
Create another new object and call it "obj_Decal_Surface". This object is going to "catch" the decal instances and draw their sprites, meaning that we can then destroy them and so save cpu cycles and make our game appear to have a million instances, but really have very few!
그림자 오브젝트처럼 Create Event에 다음 코드를 넣습니다:
As with the shadow surface object, give it a create event with the following code:
다시, Room End Event를 넣고 서피스를 삭제합니다:
Again, we need to add a Room End Event to free the surface memory too and keep everything tidy:
draw event를 추가하고 거기에 다음 코드를 넣습니다:
Now, add a draw event and in that place this code block:
벽 오브젝트에 대해서 작업할 때와 비슷해 보입니다. 이번에는 서피스를 만들때 그리지 않습니다. 대신 obj_Decal가 생긴 다음에 그립니다.
As you can see, it looks quite similar to that which we used for the walls, only this time we draw to the surface not when it is first created, but every step ther after when an instance of obj_Decal exists.
데칼 인스턴스가 있는 확인해서, 그려질 대상으로 설정하고 (이번에는 단지 그릴 뿐 반투명은 필요 없습니다.) 서피스에 그리게 합니다. 대신 데칼이 오브젝트의 애니메이션이 끝났는지는 확인해서 끝났으면 인스턴스를 삭제합니다.
What happens is that the surface instance checks to see if this decal instance (or any of its children) exists in the game,
and if they do it then sets the drawing target (no need to set the blend modes this time as we don't mind if the alphas over-write each other)
and then it makes sure that the instances have stopped moving.
If the checks are all true, the instance is drawn (with it's shadow if it has one) and then destroyed.
Finally the draw target is reset to the screen, and the surface itself is drawn for the player to see.
데칼 서피스를 게임에 넣습니다. 플레이를 하면서 데칼효과가 얼마나 많이 남는지 봅시다. 서피스가 없었다면 인스턴스 카운트가 너무 많아서 게임을 진행할 수록 점점 할 수없는 상태가 됩니다...
Place an instance of the new decals surface into your room and play your game, paying attention to how much debris is left behind while you fight now! Without surfaces, your instance count would quickly have run into the thousands and your game would be nearly un-playable...
Next 버튼을 눌러서 다음 페이지로 갑시다.