设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 79|回复: 0

[制作教程] Directional Light Soruce(FlashLight)

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    慵懒
    3 天前
  • 签到天数: 207 天

    连续签到: 1 天

    [LV.7]常住居民III

    3646

    主题

    862

    回帖

    2万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    21262
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    25800

    灌水之王

    发表于 前天 21:26 | 显示全部楼层 |阅读模式
    At the time I am making this tutorial, I am making a horror game and I really wanted a flashlight. So I thought I would show how I did it. Now the lights are just examples, they can all be tweaked to look better in an image editor. I didn't spend too much time on the images to make sure this concept at least worked.

    I've seen as well as I imagine many others have, the "Lantern Effect" where all you do is make a picture that is a circle of the light you wish to give off, and then show that picture in reference of your ScreenX and ScreenY variables.

    As seen here:
    Spoiler






    Now there is nothing wrong with this method, and have seen it used in some really good RPG Games. There are a couple things that don't fit the bill for me here.
    1. This is a modern era for this map, a lantern would be non-existent.
    2. I don't like how it lights up the entire character. This can be done a lot better I know, so that it's not washed out as bad, but this is just an example. If you like this method there are plenty of places you can go to learn how to make a really nice lantern effect.

    So onto my preferred light source.

    A flashlight as seen below:
    Spoiler






    Luckily it is not too much more to pull this off. Add one more Variable, 4 Conditional Branches, and 3 more images.


    1. Make a new event (name it whatever you want) and set it to Parallel Trigger.
    2. You will need 3 Control Variables:

    • Player X = Screen X of Player (Make sure its screen X and not Map X)
    • Player Y = Screen Y of Player (Again make sure its Screen Y)
    • Direction = Direction of Player (its in the same character dropdown as the ScreenX & Y)
    That's all the variables needed, here is what it should look like thus far:
    Spoiler






    3. The next part is you need to make a some nested conditional branches so they act as an ELSE IF statement. This is what is going to determine which way we are looking determined by our "Direction" Variable (2 = Down, 4 = Left, 6 = Right, 8 = UP).

    • Conditional Branch
    • Variable "Direction" = Constant 2 (This will check for if the player is looking down)
    • Check the "Create Else Branch"
    Should look like this:
    Spoiler






    4. Make another conditional branch inside the first one after the "Else", and copy the same settings except for changing the Constant from 2, to 4, and repeat that 2 more times changing the constant to 6, and 8. When it's all done you should have something that looks like this:
    Spoiler






    5. Now onto the hardest part in my opinion, and really up to you on how you do this, but make 4 Light Images, name them something that easy to reference, so for me it was 'lightLeft', 'lightRight', 'lightUp', 'lightDown'.

    What makes this harder is when we draw them to the screen its either "Center", or "Upper Left", meaning that you will need to offset the light to account for the character size. What I decided to go with is to format them for the "Center", and offset the image to account for the character within its own canvas, but remember the character will have to sit in the center of the Image so it will need to be doubled in size on the Axis's.

    In other words if you want a 2x1 Tile light, then make it 4x2 (192x96px), X being 4 because again it needs to be doubled for the fact its being centered. The Y is 2 because you need to raise the light up slightly because if not its at your feet. Look at the lantern picture I posted and you see where the starting point is.

    I am not going to show how to do that, as it can vary depending on your needs, and you may want slightly different positions. I have added my light pictures that I reference above. However I do strongly recommend you make your own as these are quite bad, again just to be used as example and reference.
    Spoiler















    6. Now all we have to do is draw those pictures, so going back to the conditional branch we set up, under the first 'IF' make a new "Show Picture". Since this was Direction = 2 for that IF, then we need to draw the 'lightDown' picture (or whatever you named yours).  

    • Origin is "Centered" if you downloaded my examples, or decided to go with that format.
    • "Designation with Variables" setting the X to the Player X variable and the Y to the Player Y Variable that we setup earlier.
    • Set the blend mode to Additive.
    Should look something like this:
    Spoiler






    7. Repeat that for all the directions in the nested Conditional Branches that we made when you are all done it should look like this.
    Spoiler






    Just note the Image names.

    With that you should now have a working flashlight!  Of course if you want it to turn on/off, have the event require a Switch and when you set that Switch it OFF it will stop the event and stop showing the pictures.

    It seems like a lot when you first look at it, but all it really is, is just the "Lantern Effect", but changing the image when you turn. So all it is is adding 1 more Variable and 4 Conditional Branches. Like I said the hardest part is making the images, just because you will need to mess with offsetting the image within its own canvas.  

    Technically the last IF isn't needed because if the first 3 are false then you can assume the last direction. I personally don't like doing stuff like that, due to other coding experiences, I've fixed a lot of other people's code, because theoretically X should happen, but then an outside variable messes with it and then you have an issue. With this way you are checking everything. Up to you though.

    Hopefully, this at least can help you with some ideas. Like I said I highly recommend you make your own lights and just fiddle with the positioning to suit your needs perfectly.

    If anyone has anything to add to this, feel free to post it below.


    本贴来自国际rpgmaker官方论坛作者:Bigbaddevil7处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/directional-light-soruce-flashlight.93660/

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-7-10 02:06 , Processed in 0.076786 second(s), 55 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表