Chaos Project

RPG Maker => RPG Maker Scripts => Topic started by: Ryex on April 09, 2009, 10:53:28 pm

Title: "Opening" windows?
Post by: Ryex on April 09, 2009, 10:53:28 pm
how do you recreate the effect of "opening" a window ie. how a scroll would open the window starts a a thin strip and then "opens" the top and bottom of the box moving up and down respectively till the window is its full height.

I considered the idea of having the window start off at 32 pixels high and then adding to the windows height and changing the x value till it was right but then I would have to stop it from drawing the inside of the window till it was all the way open. I don't think it would work very well.
Title: Re: "Opening" windows?
Post by: Fantasist on April 10, 2009, 03:06:36 am
Just kcontrol when self.contents is created. Make the contents only after the window is opened.
Title: Re: "Opening" windows?
Post by: Ryex on April 10, 2009, 06:11:58 pm
but it will look weird opening an empty window and then creating the contents bitmap. think about it its an empty window, and then suddenly there is text. wouldn't that look a bit odd?
Title: Re: "Opening" windows?
Post by: Landith on April 10, 2009, 06:18:54 pm
Maybe... Play a transition of it sliding down as you open the window..?
Idk if you can do that only for the text though...
Title: Re: "Opening" windows?
Post by: fugibo on April 10, 2009, 07:17:36 pm
Have a boolean "animating variable:"

def initialize
  @animating = false
  ...
end


Have a fork in the "update" method:

def update
  return @animating ? animate : normal_update
end


Have an "animate" method:


def animate
  self.y -= 2
  self.width += 4
  if self.y == <desired> && self.width = <desired>
    @animating = false
    finalize
  end
end


Have a "normal_update" method:

def normal_update
  (do normal updating stuff)
end


Have a "finalize" method:

def finalize
  self.contents = Bitmap.new(<size1>, <size2>)
 
  (do stuff to draw the window)
end

Title: Re: "Opening" windows?
Post by: Ryex on April 10, 2009, 07:31:02 pm
thanks WcW

I'll try this out and see how it looks, then report back to tell you if it had the desired effect.
Title: Re: "Opening" windows?
Post by: fugibo on April 10, 2009, 07:40:11 pm
I also spent a few minutes on this:

=begin
Window_Animated Template
v 1.00

This is a template for Window Animations that simplifies
the process of having a window animate when it opens or
closes (ex. LoLIV:CP)

To use:

* Subclass Window_Animated
* Implement your initialize method, calling super(x, y, w, h) FIRST
* Now implement an animate_open method, which will do the effect for
opening
* Next, implement an opened? method which will check to see if the
animation is complete (it can check a frame count using
@open_count)
* Now implement a finalize_open method, which will create the bitmap
and such that would normally be done in initialize
* Now, do that all for close (using animate_close, closed?, @close_count,
and finalize_close)
* Now you can implement a normal_update method, which will be you regular
update method
* Optionally you can implement a universal_update method which will be
called whether or not it is opening, closing, or doing nothing. This
makes it easier for you to code -- not redefinition of update required

Note that this has no guarantee of working -- I do not have the real RMXP
on me

-- WcW (no credits require if you use this)
=end

class Window_Animated < Window
def initialize(x = 0, y = 0, w = 1, y = 1)
super(x, y, w, h)

@opening = true
@closing = false

@open_count = 0
@close_count = 0
end

def update_open
@open_count += 1

animate_open if method_defined?(:animate_open)

if method_defined?(:opened?) && opened?
@opening = false
finalize_open if method_defined?(:finalize_open)
@open_count = 0
end
end

def update_close
@close_count += 1

animate_close if method_defined?(:animate_close)

if method_defined?(:closed?) && closed?
@closing = false
finalize_close if method_defined?(:finalize_close)
@close_count = 0
end
end

def update
super()

if @opening
update_open
elsif @closing
update_close
else
normal_update if method_defined?(:normal_update)
end

universal_update if method_defined?(:universal_update)
end
end


You can try that, as it will result in cleaner, easier to maintain code. It automatically handles the hard parts :P
Title: Re: "Opening" windows?
Post by: Ryex on April 11, 2009, 01:30:29 am
 :O.o:
I didn't expect that much help thanks WcW
Title: Re: "Opening" windows?
Post by: fugibo on April 11, 2009, 05:36:16 am
NP. I just like doing things in a clean object-oriented way, and the best way is with a good base class. It's only 40 lines of code :P