Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Moving Windows script Help

CJF

Member

I'm trying to get Trickster's Moving Windows script to work, however, without any documentation I am helpless. The only little bit Trickster says is;
to move a window just call .move(x, y, speed)

where x is the destination x coordinate
y is the destination y coordinate
speed is the speed of the movement

My question is: Where do I call that? Where do I insert that bit of code?

What I want to do is, when you hit ESC, have the menu to slide in from the side of the screen. Then when you exit, the menu slides off.

Thanks for taking pity on my clueless soul and helping. :)

class Numeric
def sign
return 0 if self.zero?
return (self / self.abs).to_i
end
end

class Window_Base
#--------------------------------------------------------------------------
# * Move the sprite
# x : x coordinate of the destination point
# y : y coordinate of the destination point
# speed : Speed of movement
#--------------------------------------------------------------------------
def move(x, y, speed = 1)
# Set Destination Points speed and move count set moving flag
@destination_x = x
@destination_y = y
@move_speed = speed
@moving = true
# Get the distance + (negative if to left or up positive if down or right)
@distance_x = (@destination_x - self.x).to_f
@distance_y = (@destination_y - self.y).to_f
# Get slant distance (hypotenuse of the triangle (xf,yi) (xi,yf) and (xf,yf))
@distance = Math.sqrt(@distance_x ** 2 + @distance_y ** 2)
# Calculate angle of movement which is later used to determine direction
# If X distance is 0 (Prevent Infinity Error)
if @distance_x == 0
# The Angle is sign(distance_y) * - π / 2 (90° or 270°)
@angle = @distance_y.sign * Math::PI / 2
# If Y distance is 0 (Prevent Incorrect Direction for later)
elsif @distance_y == 0
# The Angle is sign(distance_x) - 1 * π / 2 (0° or 180°)
@angle = (@distance_x.sign - 1) * Math::PI / 2
else
# The Angle is the Arctangent of @distance_y / @distance_x (slope)
# Returns [-Ï€,Ï€]
@angle = Math.atan2(@distance_y, @distance_x.to_f)
end
# Convert the angle to degrees
@angle *= 180 / Math::PI
end
#--------------------------------------------------------------------------
# * Update Move
#--------------------------------------------------------------------------
alias moving_window_update update
def update
moving_window_update
update_move
end
#--------------------------------------------------------------------------
# * Moving?
#--------------------------------------------------------------------------
def moving?
return @moving
end
#--------------------------------------------------------------------------
# * Update Move
#--------------------------------------------------------------------------
def update_move
# If not moving
if (self.x == @destination_x and self.y == @destination_y) or not @moving
@moving = false
return
end
# move increase x = the cosine of the arctangent of the dist x over dist y
# move increase x = cos(arctan(disty/distx)) simplified by trigonometry
# to distance_x / slant_distance, the sprite moves (move speed)
# along the slanted line (if it is slanted)
movinc_x = @move_speed * @distance_x.abs / @distance
# same reasoning with y increase except it is the sine of the arctangent
# move increase y = sin(arctan(disty/distx)) simplified by trigonometry
# to distance_y / slant_distance
movinc_y = @move_speed * @distance_y.abs / @distance
# Move the sign of the distance left + move increase or the remaining distance
# left if it will go past that point
if @move_speed != 0
# Get distance remaining
remain_x = (@destination_x - self.x).abs
remain_y = (@destination_y - self.y).abs
self.x += (@destination_x - self.x).sign * [movinc_x.ceil, remain_x].min
self.y += (@destination_y - self.y).sign * [movinc_y.ceil, remain_y].min
end
# If Destination Reached stop moving
if self.x == @destination_x and self.y == @destination_y
@moving = false
return
end
end
end
 
Based on the script, there are two ways to call it. THe first is within the window, where you would call it as
Code:
self.move(x, y, speed)
.

Otherwise, you would call it with the variable controlling the window. So, to give an example of makeing a window and then moving it, do this:

Code:
@window = Window_Example.new

@window.move(x, y, speed)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top