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

[制作教程] Animate Pictures w/ Simple Script Call

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    前天 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    4452

    主题

    864

    回帖

    2万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

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

    灌水之王

    发表于 3 天前 | 显示全部楼层 |阅读模式
    So, you have pictures you want to animate, perhaps in a cycle or even to fade in and out things in an endless loop using a lot of frames but don't want to waste your time inputting each and every single "Show Picture" command into the event editor?  Neither do I.  This simple, and very powerful, little script call will make all of that a quick and painless reality.

    Okay, now this does involve scripting, but not extensive knowledge in it and I'll explain everything so that you don't get lost.  It's really very simple.

    Okay, so let's start with something rather basic, which is a simple fade in & out.  This usually requires a lot of "Show Picture" commands along with a Wait command after every single one to control how fast or slow the animation goes.  With this method, you can throw that right out the window.

    i=0while i<=255 do  screen.pictures[1].show("map_name1.png", 0, 48, 64, 100, 100, i, 0)  i+=16  wait(2)endSo, what does this do?  Well, let's take a look at each and every single thing involved here.

    i=0

    The letter i is a variable, being used as such just as you would use a variable in the event editor.  It's setting the variable, which I have set to i, to a value of 0.  Why?  You'll see in a bit.  Still, when you call this, and it does need to be written every time you're doing something like this unless you're doing a for loop, but that won't be covered.  So really, all this is doing is this:





    You may ask, well if you can just do that, why not do that instead?  Because you're saving yourself a variable slot in the event editor and it's much simpler to simply type out i=0 than to event it.  For programmers, don't worry about using a semi-colon at the end.  In Ruby, it's not needed.

    By the way, the variable can be named whatever you want as long as you don't put spaces in the name.  A good practice to have is to use names like iLetter, variable_i, or just i or even a simple name like opacity_vari if you really wanted.

    while i<=255 do

    Okay, so, this looks confusing, doesn't it?  If you're a programmer, not so much, but to the average joe/jane, it is.  What this is doing is a normal Loop command.  However, doing Loops in eventing is tricky and, in my own personal opinion, messy.  This loop will run as long as the variable i is less than i and will run once more once it reaches 255.

    Well, what if it goes above that?  Easy.  We can write an if/else statement to make sure that it breaks the loop.  I'll tell you about that in a sec.  First off, let's continue.  So, the do is literally saying, do this command that coming up.  Simple, right?  So, the loop will run while the variable i is less than 255 and will run once more at 255 before finally finishing.  It will auto-break out of itself so it doesn't loop forever.

    screen.pictures[1].show("map_name1.png", 0, 48, 64, 100, 100, i, 0)

    The fun part.  Now we get to how this simplifies the picture animation process.  So, if you read the line, you'll see the variable i in there.  This is because it's going to be used to replace the static number used for opacity.  Without the process I'm teaching you, you'd still have to copy&paste the line for as many times as you want to have the picture fade in and out, so you don't gain much out of this method at all.  However, using a variable will give you a beautiful shortcut.  First, let me break down all of this.

    So, screen.pictures[1].show() is just what you'd expect, it's the "Show Picture" command in script form.  Simple enough.  In side the parenthesis, there are 8 values you can change dynamically or keep them static using this method.  These values are, from left to right:


    • Picture filename (including the extension, such as PNG or JPG)
    • Position (0 is Top-Left & 1 is Center)
    • X Position (on the screen, not the map)
    • Y Position (same as #3)
    • X Zoom (This is what percentage the image should be zoomed horizontally)
    • Y Zoom (Same as #5, but vertically)
    • Opacity (This controls transparency.  Laymens terms, completely transparent/see-through or opaque/non see-through)
    • Blend Type (0 is Normal, 1 is Addition & 2 is Subtraction).  If you don't know what these do, stick with Normal or 0.
    Okay, so now you know what each value does.  It's the same options you have in the "Show Picture" command, just in scripted form.  So, why do it this way instead of just placing one "Show Picture" command and using a variable inside the command?  Easy, because you can't.  Let me show you.





    For opacity, all you can do is set a static number per "Show Picture" command.  I find this to be rather silly, but that's why we're doing this.  I mean, we can do it with Conditional Branches and Loop commands, but not anything else?  Ah well, anyway.

    So, right, before you get confused, or further confused, let us move on to the beefy part of how this works.  We know how to create the variable, we know where to put it and what it will be doing, which is controlling the image opacity.  Now, how is it gonna increase to make it go from transparent to opaque?  Easy.

    i+=16

    This simple little thing here.  What this is going is basically adding a value of 16 to i every single time it loops until it reaches 255.  Normally, it would reach 256, but we're not starting from 1, but instead starting from 0.  You all are probably wondering, why are you using +=?  That doesn't make any sense!  It does in programming and scripting.  See, in programming, if you type i+16, it's as if you're writing i + 16 = i.  When it loops, all it will do is simply add 16 to 0, but 0 will never actually change.  When you do i+=16, it's as if you're writing i = i + 16, which continuously adds 16 to i and increases it.  So instead of keeping it at 0 and then simply adding 16 and doing that over and over again without change, we use the += to add 16 every time to i.  Confusing, I know, but simply keep this in mind:

    Use + if you want i to stay at 0 and just add 16, then reset and do it again.

    Use += if you want to always add on 16 to i and increase it's value by 16 every time.

    wait(2)

    I'm sure this is pretty self-explanatory.  Wait command and the number of frames is 2.  Moving on.

    end

    This will finally end the loop once it's reached its goal of 255.  Simple!

    The reason I'm using 255 and not 256 or any other number above 255 is because maximum opacity is 255 on a scale of 0-255.  This is why the number was set to 255 for the end goal.  Now, earlier, the question was posed, what if it goes beyond 255?  We can simply add an if/else statement, or more commonly called "Conditional Branch".

    i=0while i<=255 do  if i>255    i=255    break  else    screen.picture_show[1](blah blah)    i+=16    wait(2)  endendEvery time the loop starts, it will do a check to see if i is greater than 255.  If it's not, the check will be ignored and do the loop as normal.  If it does end up going over 255, it will set i to 255 and then end the loop.  Pretty easy, right?  Make sure you write in break or else it will continue on to do the check and loop endlessly!

    This little script call will ensure you have an image that fades in at a speed your comfortable with.  All you need to do is change the wait(2) value to whatever you want and even the i+=16 value to something lower or higher to control it even more.

    Fading out from here is the same thing, but you're going to change a couple of things:

    i=255while i>=0 do  screen.pictures[1].show("meyer_farm.png", 0, 48, 64, 100, 100, i, 0)  i-=16  wait(2)endInstead of +=16, we're doing -=16, which is subtracting 16 every time from i.  This means out picture is becoming more transparent until it reaches 0, or completely see-through.

    If you want to wait about 2 seconds before the image fades out after just fading in, simply use a normal "Wait" command and set it to however many frames you want (ex. 2sec = 120 frames).

    So, what about animated waterfalls and things like that?  Well, that involves copy&pasting what I had talked about before and simply putting that in a simple loop that will either run forever or until you leave the screen or until a certain variable has been reached.  Here's a short example.

    anim_min=0while anim_min < 30 do  screen.picture_show[1]("rain1.png", 0, 0, 0, 100, 100, 255, 0)  wait(1)  screen.picture_show[1]("rain2.png", 0, 0, 0, 100, 100, 255, 0)  wait(1)  screen.picture_show[1]("rain3.png", 0, 0, 0, 100, 100, 255, 0)  wait(1)  screen.picture_show[1]("rain4.png", 0, 0, 0, 100, 100, 255, 0)  wait(1)  screen.picture_show[1]("rain5.png", 0, 0, 0, 100, 100, 255, 0)  wait(1)  anim_min+=1endAs you can see, the command was copy&pasted, but it cut out one very important thing: fiddling with the editor.  Using the editor to go in and select every image is tedious and no one likes doing that when there's a simpler way, which is to copy&paste then simply change the numbers and/or names of the other pictures to match the animation frames in the script.  This will save you time and headaches later on, especially if you change the filenames later on since you can simply rewrite the filenames without having to edit the event, go select each image, assuming you have a mountain of resources to deal with and would have to scroll all over the place to find it, and then do it over and over again until they are all done.

    Well that's about it for now!  If you have any questions, don't hesitate to ask!


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

    本帖子中包含更多资源

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

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

    使用道具 举报

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

    本版积分规则

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

    幸运抽奖

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

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2026-7-14 15:26 , Processed in 0.106650 second(s), 56 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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