self.z? [solved]

Started by diagostimo, March 02, 2012, 11:00:54 pm

Previous topic - Next topic

diagostimo

March 02, 2012, 11:00:54 pm Last Edit: March 03, 2012, 04:45:10 am by diagostimo
hi, i was wondering if anyone knows how i can change the self.z of a picture shown in a window, so it is behind my index's cursor_rect, or the other way around so the the self.z of the cursor is higher than the picture, heres my script for reference:
#==============================================================================
# ** Window_Map
#------------------------------------------------------------------------------
class Window_MapMenu < Window_Base
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
   super(0, 0, 640, 480)
   self.contents = Bitmap.new(width - 32, height - 32)
   @index = 0
   update_cursor_rect
    refresh
 end
 #-------------------------------------------------------------------------
 # * def index
 #-------------------------------------------------------------------------
 def index=(index)
   @index = index
   # Update Help Text (update_help is defined by the subclasses)
   if self.active and @help_window != nil
     update_help
   end
   # Update cursor rectangle
   update_cursor_rect
 end
 #--------------------------------------------------------------------------
 # * Cursor Rectangle Update
 #--------------------------------------------------------------------------
 def update_cursor_rect
     x = 32 + @index % 17 * 32
     y = 0 + @index / 17 % 14 * 32
     self.cursor_rect.set(x, y, 32, 32)
 end
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------
 def refresh
   @bitmap = RPG::Cache.picture("kantomap.png")
   self.contents.blt(32, 0, @bitmap, Rect.new(0, 0, @bitmap.width, @bitmap.height), 160)
 end
 
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
   super
   # if enter is being pressed
   if Input.trigger?(Input::C)
     if @index == 172
       # Play decision SE
       $game_system.se_play($data_system.decision_se)
       # Switch to item screen
       $scene = Scene_PalletTown.new
     end
   end
     # If right directional button is pushed
     if Input.repeat?(Input::RIGHT)
       # If directional button pressed down is not a repeat, or
       # cursor is not positioned on the right edge
       if Input.trigger?(Input::RIGHT) or
          @index % 17 < 16
         # Move cursor to right
         $game_system.se_play($data_system.cursor_se)
         if @index % 17 < 16
           @index += 1
         end
       end
     end
     # If left directional button is pushed
     if Input.repeat?(Input::LEFT)
       # If directional button pressed down is not a repeat, or
       # cursor is not positioned on the left edge
       if Input.trigger?(Input::LEFT) or
          @index % 17 > 0
         # Move cursor to left
         $game_system.se_play($data_system.cursor_se)
         if @index % 17 > 0
           @index -= 1
         end
       end
     end
     # If down directional button is pushed
     if Input.repeat?(Input::DOWN)
       # Move cursor down
       if @index / 17 < 13
         @index += 17
         $game_system.se_play($data_system.cursor_se)
       end
     end
     # If up directional button is pushed
     if Input.repeat?(Input::UP)
       # Move cursor up
       if @index / 17 > 0
         @index -= 17
         $game_system.se_play($data_system.cursor_se)
       end  
     end
   update_cursor_rect
 end
end
#---------------------------------------------------------------------------
# * Scene Map_Menu
#---------------------------------------------------------------------------
class Scene_MapMenu
 def initialize(index = 0)  
     @index = index
 end
 #-------------------------------------------------------------------------
 # * MAIN
 #-------------------------------------------------------------------------
 def main
   @mapmenu_window = Window_MapMenu.new
   @mapmenu_window.index = @index
   # Execute transition
   Graphics.transition
   # Main loop
   loop do
     # Update game screen
     Graphics.update
     # Update input information
     Input.update
     # Frame update
     update
     # Abort loop if screen is changed
     if $scene != self
       break
     end
   end
   # Prepare for transition
   Graphics.freeze
   # Dispose of windows
   @mapmenu_window.dispose
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
   # Update windows
   @mapmenu_window.update
   # If B button was pressed
   if Input.trigger?(Input::B)
     # Play cancel SE
     $game_system.se_play($data_system.cancel_se)
     # Switch to Menu screen
     $scene = Scene_Item.new
     return
   end
 end
end
#---------------------------------------------------------------------------
# * class Window_PalletTown
#---------------------------------------------------------------------------
class Window_PalletTown < Window_Base
 #-------------------------------------------------------------------------
 # * Object Initialization
 #-------------------------------------------------------------------------
 def initialize
   super(0, 0, 416, 352)
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
 end
 #-------------------------------------------------------------------------
 # * refresh
 #-------------------------------------------------------------------------
 def refresh
   @bitmap = RPG::Cache.picture("pallettown.png")
   self.contents.blt(0, 0, @bitmap, Rect.new(0, 0, @bitmap.width, @bitmap.height), 255)
 end
end

#---------------------------------------------------------------------------
# * Scene_PalletTown
#---------------------------------------------------------------------------
class Scene_PalletTown
 #-------------------------------------------------------------------------
 # * Main
 #-------------------------------------------------------------------------
 def main
   @pallettown_window = Window_PalletTown.new
   # Execute transition
   Graphics.transition
   # Main loop
   loop do
     # Update game screen
     Graphics.update
     # Update input information
     Input.update
     # Frame update
     update
     # Abort loop if screen is changed
     if $scene != self
       break
     end
   end
   # Prepare for transition
   Graphics.freeze
   # Dispose of windows
   @pallettown_window.dispose
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
   # Update windows
   @pallettown_window.update
   # if mapmenu is active call update_map
   # If B button was pressed
   if Input.trigger?(Input::B)
     # Play cancel SE
     $game_system.se_play($data_system.cancel_se)
     # Switch to map screen
     $scene = Scene_MapMenu.new(172)
     return
   end
 end
end

if anyone knows how i can accomplish this, i will be in your gratitude :P

G_G

That really wouldn't be possible with a complete rewrite of the Window class. Which is a hidden class. With the way windows are setup, there really is no "z" value for the contents getting drawn. You have to choose the order yourself. But there are parts you can't control, like the cursor. The drawing order occurs like this, Background -> Border -> Cursor/Arrows -> Your Content. The only way to change this is to either create your own rewrite of the class.

diagostimo

im guessing this is written in C++ for the exe right?

ForeverZer0

I think its just C.

Doesn't really make a difference in regards to your question.
Just set the opacity of the window background to 0, and set a picture behind it. It will have the same effect.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

diagostimo

im unsure where i would set the opacity :/

G_G

In the window initialization.
self.back_opacity = 0

diagostimo

cool, iv looked at how another script set a background image, and i believe i am to use this line: @sprite.bitmap = RPG::Cache.picture("") in main, but i get no image drawn, do i need to define it anywhere else?

G_G

Can't just have empty quotes. You need to actually choose a file to load.
class Scene_Alias
  def main
    @sprite = Sprite.new
    @sprite.bitmap = RPG::Cache.picture("picture name")
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    @sprite.dispose
  end
end

diagostimo

i did realise that, i was just using it as a reference, but i did forget the @sprite = Sprite.new and @sprite.dispose, thanks for your help :D

G_G

Glad I could be of some help. :3

diagostimo

i have just realised that the windows border is still showing, can i change the opacity of this to 0?

ForeverZer0

Just use @window.opacity instead of @window.back_opacity.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

diagostimo