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.

Assigning Picture X Magnification To A Variable?

Hey hey hey,
Does anyone know a little code snippet to do something like 'Move Picture 2 @ 10, Upper Left, (4,31), (X%, 100%)' or
Move Picture 2
10 Frames
Position Upper Left, X: 4, Y: 31
Magnification, X: X%, Y: 100%

Where X is Variable 0002?

Yours Concordantly/Polemically,
Heronaut
 
Hmm... I found this
Code:
game_screen.pictures[2].move(@parameters[1] * 2, @parameters[2], 4, 31, @parameters[6], @parameters[7], @parameters[8], @parameters[9])
In the Interpreter.. how do I use it?
 

khmp

Sponsor

First don't hard code the position of where you want the picture to go to. I'm referring to the 4 and 31 you stuck into that call. Change that line back to:
Code:
$game_screen.pictures[number].move(@parameters[1] * 2, @parameters[2],
      x, y, @parameters[6], @parameters[7], @parameters[8], @parameters[9])

Next, @parameters[6], @parameters[7] in that method represent zoom_x and zoom_y respectively speaking. That method you have above is called whenever the "Move Picture" event command is used. However @parameters[6], @parameters[7] are taken from the event command as hard coded numbers. You can get around this awkwardly however:

Code:
#==============================================================================
# ** Game_Screen
#------------------------------------------------------------------------------
#  This class handles screen maintenance data, such as change in color tone,
#  flashing, etc. Refer to "$game_screen" for the instance of this class.
#==============================================================================

class Game_Screen
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias_method :hero_zooming_game_screen_intialize, :initialize
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :var_zoom_x,   # Should a variable be used to alter zoom x?
                :zoom_index_x, # What index has the zoom x value.
                :var_zoom_y,   # Should a variable be used to alter zoom y?
                :zoom_index_y  # What index has the zoom y value.
  #--------------------------------------------------------------------------
  # * Object Initialization                                           !ALIAS!
  #--------------------------------------------------------------------------
  def initialize
    hero_zooming_game_screen_intialize
    @var_zoom_x = @var_zoom_y = false
    @zoom_index_x = @zoom_index_y = 0
  end
end

#==============================================================================
# ** Game_Picture
#------------------------------------------------------------------------------
#  This class handles the picture. It's used within the Game_Screen class
#  ($game_screen).
#==============================================================================

class Game_Picture
  #--------------------------------------------------------------------------
  # * Move Picture                                                 !OVERRIDE!
  #     duration   : time
  #     origin     : starting point
  #     x          : x-coordinate
  #     y          : y-coordinate
  #     zoom_x     : x directional zoom rate
  #     zoom_y     : y directional zoom rate
  #     opacity    : opacity level
  #     blend_type : blend method
  #--------------------------------------------------------------------------
  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
    
    # If we are using a game_variables to zoom.
    @target_zoom_x = $game_screen.var_zoom_x ? 
      $game_variables[$game_screen.zoom_index_x].to_f : zoom_x.to_f
    @target_zoom_y = $game_screen.var_zoom_y ? 
      $game_variables[$game_screen.zoom_index_y].to_f : zoom_y.to_f
    
    @target_opacity = opacity.to_f
    @blend_type = blend_type
  end
end

Refer to the FAQ for questions involving the installation of scripts.

Alright this requires some additional work on your part though. First you need one obvious "Control Variables" event command. The next portion is actually warning Game_Screen that you will be using a variable to override either zoom_x or zoom_y or both. For this we will use "Script...":
Code:
$game_screen.var_zoom_x = true
$game_screen.zoom_index_x = 2
What that tells Game_Screen is that you will be overriding the zoom_x value supplied inside "Move Picture" and the index where the variable that contains the override is at index 2. It's a state machine. So if you want it to stop overriding zoom_x use the following "Script..." event command:
Code:
$game_screen.var_zoom_x = false

zoom_y mirrors the exact same functionality as x has. Meaning to change the zoom_y parameter would be using the same code above but with a y instead of an x. Example:
Code:
$game_screen.var_zoom_y = true
$game_screen.zoom_index_y = 3
And to stop overriding:
Code:
$game_screen.var_zoom_y = false

Good luck with it Heronaut! :thumb:
 

khmp

Sponsor

Alright well check out this Demo to see how I used the code. There is no freezing so I don't know what you are doing in particular. If you still have an issue let me know and preferably post a demo of your project. If you are worried about privacy you can PM me the link.

Good luck with it Heronaut! :thumb:
 
Thank you very much, it works perfectly...
Except my character won't move (I think it's because I'm using Common Events)I fixed it with a simple movement event  :lol: (Doesn't allow Player Touch, goddammit)
Also, Is there a way to have 2 of these with different variables in the one event?
 
Hah, I figured it out, I had a common event on Autorun, God I'm so retarded...
So, is there a way to make 2 different bars on 2 different variables?
Bah. Never mind.
khmp, I'm in your debt good sir.
 

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