Home > RGSS Script Reference > Game_Picture
Game_Picture
Inherits from: None
Description: This class holds information about a picture and contains methods for showing, moving, rotating, and erasing pictures.
class Game_Picture
# ------------------------------------
attr_reader :number
attr_reader :name
attr_reader :origin
attr_reader :x
attr_reader :y
attr_reader :zoom_x
attr_reader :zoom_y
attr_reader :opacity
attr_reader :blend_type
attr_reader :tone
attr_reader :angle
# ------------------------------------
def initialize(number)
@number = number
@name = ""
@origin = 0
@x = 0.0
@y = 0.0
@zoom_x = 100.0
@zoom_y = 100.0
@opacity = 255.0
@blend_type = 1
@duration = 0
@target_x = @x
@target_y = @y
@target_zoom_x = @zoom_x
@target_zoom_y = @zoom_y
@target_opacity = @opacity
@tone = Tone.new(0, 0, 0, 0)
@tone_target = Tone.new(0, 0, 0, 0)
@tone_duration = 0
@angle = 0
@rotate_speed = 0
end
# ------------------------------------
def show(name, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
@name = name
@origin = origin
@x = x.to_f
@y = y.to_f
@zoom_x = zoom_x.to_f
@zoom_y = zoom_y.to_f
@opacity = opacity.to_f
@blend_type = blend_type
@duration = 0
@target_x = @x
@target_y = @y
@target_zoom_x = @zoom_x
@target_zoom_y = @zoom_y
@target_opacity = @opacity
@tone = Tone.new(0, 0, 0, 0)
@tone_target = Tone.new(0, 0, 0, 0)
@tone_duration = 0
@angle = 0
@rotate_speed = 0
end
# ------------------------------------
def move(duration, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
@duration = duration
@origin = origin
@target_x = x.to_f
@target_y = y.to_f
@target_zoom_x = zoom_x.to_f
@target_zoom_y = zoom_y.to_f
@target_opacity = opacity.to_f
@blend_type = blend_type
end
# ------------------------------------
def rotate(speed)
@rotate_speed = speed
end
# ------------------------------------
def start_tone_change(tone, duration)
@tone_target = tone.clone
@tone_duration = duration
if @tone_duration == 0
@tone = @tone_target.clone
end
end
# ------------------------------------
def erase
@name = ""
end
# ------------------------------------
def update
if @duration >= 1
d = @duration
@x = (@x * (d - 1) + @target_x) / d
@y = (@y * (d - 1) + @target_y) / d
@zoom_x = (@zoom_x * (d - 1) + @target_zoom_x) / d
@zoom_y = (@zoom_y * (d - 1) + @target_zoom_y) / d
@opacity = (@opacity * (d - 1) + @target_opacity) / d
@duration -= 1
end
if @tone_duration >= 1
d = @tone_duration
@tone.red = (@tone.red * (d - 1) + @tone_target.red) / d
@tone.green = (@tone.green * (d - 1) + @tone_target.green) / d
@tone.blue = (@tone.blue * (d - 1) + @tone_target.blue) / d
@tone.gray = (@tone.gray * (d - 1) + @tone_target.gray) / d
@tone_duration -= 1
end
if @rotate_speed != 0
@angle += @rotate_speed / 2.0
while @angle < 0
@angle += 360
end
@angle %= 360
end
end
end
|
Number: The picture's ID number defined in the "Show Picture" command.
Name: The picture's filename.
Origin: The point relative to which the picture will be shown (0 = Upper-Left, 1 = Center).
X: The X coordinate of the picture's origin.
Y: The Y coordinate of the picture's origin.
Zoom_X: The horizontal magnification of the picture.
Zoom_Y: The vertical magnification of the picture.
Opacity: The picture's opacity value (0 = Completely transparent, 255 = Completely opaque)
Blend_Type: The picture's graphical blend type (0 = Normal, 1 = Additive, 2 = Negative).
Tone: The picture's tone setting.
Angle: The picture's rotation angle relative to its original orientation. Increasing the angle represents a rotation to the right relative to the origin, while decreasing the angle represents a rotation to the left relative to the origin.
Duration: The remaining time in a "Move Picture" command.
Target_X: The target X coordinate for a "Move Picture" command.
Target_Y: The target Y coordinate for a "Move Picture" command.
Target_Zoom_X: The target horizontal magnification for a "Move Picture" command.
Target_Zoom_Y: The target vertical magnification for a "Move Picture" command.
Target_Opacity: The target opacity value for a "Move Picture" command.
Tone_Target: The tone target for a "Tint Picture" command.
Tone_Duration: The remaining time in a "Tint Picture" command.
Rotate_Speed: The rotation speed of the picture.
Initialize
Arguments:
Number: The picture number to initialize.
Local Variables: None
How it Works: This method initializes the picture to a null state.
Show
Arguments:
Name: The picture's filename.
Origin: The origin value of the picture.
X: The X coordinate at which to show the picture.
Y: The Y coordinate at which to show the picture.
Zoom_X: The horizontal magnification for the picture.
Zoom_Y: The vertical magnification for the picture.
Opacity: The opacity value of the picture.
Blend_Type: The graphical blend type of the picture.
Local Variables: None
How it Works: This method shows a picture on the screen. The lower-level graphics routines actually handle showing the picture, so this method just sets the instance variables associated with the picture to the appropriate values.
Move
Arguments:
Duration: The transition time for the Move Picture operation, in frames.
Name: The picture's filename.
Origin: The origin value of the picture. It's possible to move a picture from Upper-Left-relative coordinates to Center-relative coordinates and vice-versa.
X: The X coordinate to which to move the picture.
Y: The Y coordinate to which to move the picture.
Zoom_X: The new horizontal magnification for the picture after movement.
Zoom_Y: The new vertical magnification for the picture after movement.
Opacity: The opacity value of the picture after movement.
Blend_Type: The graphical blend type of the picture after movement.
Local Variables: None
How it Works: This method sets up a "Move Picture" command. The Update method carries out the frame-by-frame updating of the movement effect. This method just sets the instance variables representing the new values.
Rotate
Arguments:
Speed: The rotation speed of the picture. A positive value indicates rotating to the right, while a negative value indicates rotating to the left.
Local Variables: None
How it Works: This method sets up a "Rotate Picture" command. The Update method carries out the frame-by-frame updating of the rotation effect. This method sets the rotation speed instance variable.
Start_Tone_Change
Arguments:
Tone: The new tone.
Duration: The transition time from the old tone to the new tone, in frames.
Local Variables: None
How it Works: This method sets up a "Tint Picture" command. This method sets the @tone_target and @tone_duration instance variables. If the value of @tone_duration is 0, the method sets the picture's current tone to the new tone directly. Otherwise, the Update method carries out the frame-by-frame updating of the tinting effect.
Erase
Arguments: None
Local Variables: None
How it Works: Erases the picture by setting its filename to a null string.
Update
Arguments: None
Local Variables: None
How it Works: This method does the frame-by-frame transition updates for "Move Picture", "Tint Picture", and "Rotate Picture". The if @duration >= 1 clause handles Move Picture effects. The instance variable change statements for @x, @y, @zoom_x, @zoom_y, and @opacity each change their respective picture properties by an amount equal to ((target value - previous value) / total duration). The if @tone_duration >= 1 clause handles tone changes in progress, updating each of the four tone components (red, green, blue, gray) by an amount equal to ((target value - previous value) / total duration). Finally, the if @rotate_speed != 0 clause handles picture rotation. The picture's angle is rotated by one half of one degree per unit of rotation speed. The while loop converts a negative angle into the equivilant positive angle by adding 360. The modulous statement ensures that the value of @angle represents a rotation angle only a part of one revolution from the origin, since allowing multiple revolutions adds more complexity without adding any functionality.
|
|