Project1

标题: Fade out/in method [打印本页]

作者: 熊喵酱    时间: 2013-9-24 07:37
标题: Fade out/in method
本帖最后由 76213585 于 2013-9-23 22:32 编辑

In order to make window dispose more nature is to make is fade out.
==========================================
First, add def pre_terminate Into the script anywhere.(out side of any other method)
Then add a method "fade" and"dispose"
It should look like this.
  1.   def pre_terminate
  2.     fade
  3.     dispose
  4.   end
复制代码
Then below it we add  def fade and def dispose
In dispose, you dispose all the window, kind of obvious what to do.....
So we just skip the def dispose
And go to def fade
We are going to use the loop do method to help us
Let's use the Menu Scene as our example...
This is how it should look like....
If XXX is not more than 1, it exit the loop do(using"break") if it's more than 1, it does"........"part over and over
  1.   def fade
  2.     loop do
  3.       if XXX > 1
  4.          ..........................
  5.       else
  6.         break
  7.       end   
  8.     end
复制代码
The xxx should be whatever the window you have in your scene like @status_window.opacity
So let's switch to this.....
  1.   def fade
  2.     loop do
  3.       if @status_window.opacity > 1
  4.         ............
  5.       else
  6.         break
  7.       end   
  8.     end
复制代码
OK, we will do the ......... part over and over again until @status_window.opacity if more than one.
So we can add @status_window.opacity -= 1 as the .............
Which will fade out the window's opacity by 1 and 1
Also we could add other window's as well!
If you're sure that all window's opacity will be the same (Should be......)
you can just add them toghter... like under @status_window.opacity -= 1 you put @gold_window.opacity -= 1 which will fade out both of them!
So our finishing thing should look like this: (for Meun Scene)
  1.   def pre_terminate
  2.     fade
  3.     dispose
  4.   end
  5.   def fade
  6.     loop do
  7.    # a = @status_window.opacity
  8.       if @status_window.opacity > 1
  9.         @gold_window.opacity -= 1
  10.         @command_window.opacity -= 1
  11.         @status_window.opacity -= 1
  12.         @variable_window.opacity -= 1
  13.       else
  14.         break
  15.       end   
  16.     end
  17.   end
  18.   def dispose
  19.     @ActorPortrait.dispose
  20.     @gold_window.dispose
  21.     @command_window.dispose
  22.     @status_window.dispose
  23.     @variable_window.dispose
  24.   end
复制代码
For the other scene, it's exactly the same as well!
作者: xTsukihime    时间: 2013-9-25 00:30
I prefer to use update method instead of using a loop.
Here is a script I wrote a year ago that uses the update method to perform animations

http://himeworks.wordpress.com/2 ... animation-designer/

Just copy the script into your project and then copy one of the examples I posted under it and open the menu in the game.
作者: 熊喵酱    时间: 2013-9-25 12:07
xTsukihime 发表于 2013-9-24 09:30
I prefer to use update method instead of using a loop.
Here is a script I wrote a year ago that uses ...

So basically, I just keep update the window's opacity until it meets the required amount?
but what I don't get is, what is update different from loop do?
(I know I maybe am being stupid, but I just don't get it.....)
作者: xTsukihime    时间: 2013-9-25 23:08
The update method is called once every frame. It updates everything like graphics and input and events.

If you loop, the game does not update the graphics, so everything will just freeze until you exit the loop.






欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1