Scene help

Started by Zexion, October 11, 2012, 11:59:04 pm

Previous topic - Next topic

Zexion

Okay so I'm kind of stuck. I made a new menu scene that has fancy sliding features like kingdom hearts. I moved on to making the items menu, but I ran into a few problems.

1. I open the menu and press the items button, and it replays the sliding effect. (I fixed this already)
2. When I close the items menu and get sent back to the main menu, it replays the sliding effect.

I know that the problem is in the update method. The scene calls the update method as soon as it is opened, and the update method plays the sliding effect. Is there any way I can check if the player is accessing the scene from the map or the another menu?

Since this is a custom menu, I do not call the menu by the standard Keyboard button on the map, instead i have a common event that looks for when I press a button and opens this menu. The reason I mention this is because if need be I can add something before the event to kind of tell the scene that it was from a map. My problem is more like IDK what to put.

Lukas

QuoteIs there any way I can check if the player is accessing the scene from the map or the another menu?


def initialize(menu=true)
end

if open from map, call script with scene.new(false)

or use game_temp or game_system.

?

Spoiler: ShowHide

This image been put in a spoiler because it's 2 MB which is above the size of images allowed in a spoiler.
Thank you for your understanding.
~Blizz



~Sorry :)

Zexion

October 12, 2012, 12:54:30 am #2 Last Edit: October 12, 2012, 03:38:50 pm by Zexion
I'll try it out tomorrow, need to sleep for class in the morning :( thanks for the help though!

Edit:
Okay so I tried the initialize(menu = true) thing, and it just caused lot's of errors lol. I don't exactly know what you mean by game_system and temp though. I tried making a global variable and setting it to a certain value, but for some reason the code still executes no matter what the value is.

2nd Edit:
Okay never mind I found a way to fix it :P
I declared a variable $from_map and check the value when entering and exiting to see what the menu has to do.
I had tried this already, but I was doing
Spoiler: ShowHide
if $from_map = 0
blah
elsif $from_map = 1
blah
end

instead of
Spoiler: ShowHide
if $from_map == 0
blah
elsif $from_map == 1
blah
end

KK20

Sounds pretty weird that the images would keep sliding only after coming out of the item scene. But its no longer doing it now with the "bandage" fix? Even for the other commands in the menu?

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Lukas

Quote from: Zexion on October 12, 2012, 12:54:30 am
I'll try it out tomorrow, need to sleep for class in the morning :( thanks for the help though!

Edit:
Okay so I tried the initialize(menu = true) thing, and it just caused lot's of errors lol. I don't exactly know what you mean by game_system and temp though. I tried making a global variable and setting it to a certain value, but for some reason the code still executes no matter what the value is.

2nd Edit:
Okay never mind I found a way to fix it :P
I declared a variable $from_map and check the value when entering and exiting to see what the menu has to do.
I had tried this already, but I was doing
Spoiler: ShowHide
if $from_map = 0
blah
elsif $from_map = 1
blah
end

instead of
Spoiler: ShowHide
if $from_map == 0
blah
elsif $from_map == 1
blah
end


sorry  :^_^': , I mean :

def initialize(menu=true)
@menu = menu
end
def update
if @menu
end
end

may be better to use this way appeal using global variable.
Spoiler: ShowHide

This image been put in a spoiler because it's 2 MB which is above the size of images allowed in a spoiler.
Thank you for your understanding.
~Blizz



~Sorry :)

Zexion

Ok what was happening was that I made the main menu scene first, so I made the sliding effects for when the menu is open and closed. Then when I made the item menu, I realized that the main menu still had to close before entering the item menu. What i did was to just say if i open it from the map, do one thing, if i get to it from the item menu, do a different thing. Now my problem is that the animations going on in the backgroud keep re-starting when i switch from scene to scene. I can't figure out how to save the coordinates of the graphics, so it stops doing that.

http://www.youtube.com/watch?v=DzTTDVeYorw&feature=youtu.be

diagostimo

what i would do is a mixture of what lukas said and making storing the variables in game_Temp, so the for the initialize:

def initialize(menu = false)
@menu = menu
end

then when you call the item menu or whatever menu from within your main menu, dump the variables in Game_Temp, like so:

$game_temp.my_image_x = @my_image.x
#ect

to be able to do that you would have to create public instance variables and initialize the like so:

class Game_Temp
  attr_accessor :my_image_x
  alias init_init initialize
  def initialize
    init_init
    @my_image_x = 0 #just setting it to a value to avoid errors
  end
end

now if we call the menu from the map we should use: $scene = Scene_Menu(true)
or from any menu within the main menu we should use: $scene = Scene_Menu  #returns a default false
now for actually setting the condition to set the x and y values when calling the menu, in the initialize method add something like this:

if @menu #returns truth check
  @my_image.x = #default value
else #it is false
  @my_image.x = $game_temp.my_image_x
end

hope this helps :)

Zexion

Hm I understand you, but at the same time...i don't. Like i get what I'm supposed to do, but I'm not sure how to actually implement it within my code.
Here's a copy of the engine so far, the scripts are under Kh Main and Kh Item.
http://www.gamefront.com/files/22447753/Kingdom+Hearts+Engine.exe
I realized that I would lose nothing by releasing this, because it's not even complete lol. Only item actually works, and it's not even fully coded yet.

Lukas

how do I download this file http://www.gamefront.com/files/22447753/Kingdom+Hearts+Engine.exe ?
I've seen your youtube videos.
QuoteNow my problem is that the animations going on in the backgroud keep re-starting when i switch from scene to scene.

May you can use :

Class Scene_Menu
def initialize(back_graphic=[])
@speed = [4,5,6,7,8]
@back_graphic = back_graphic
end
def main
if @back_graphic.empty?
# create animation file
@back_graphic[0] = Sprite.new
etc...
end

update blablaabla

@back_graphic.each {|i| i.bitmap.dispose;i.dispose} if $scene.is_a?(Scene_Map)
end
def update
@back_graphic[0].each_with_index {|c,p| c.x += @speed[p]; c.update}

$scene = Scene_Item.new(@back_graphic)
end
end

Class Scene_Item
def initialize(back_graphic=[])
same as above
end
def main
same as above
end
def update
same as above
end


sorry for my bad explanation  :facepalm:
I also have another trick  :P
Spoiler: ShowHide

This image been put in a spoiler because it's 2 MB which is above the size of images allowed in a spoiler.
Thank you for your understanding.
~Blizz



~Sorry :)

diagostimo

on my implementation you could do it something like this:

class Game_Temp
  attr_accessor :image_coordinates
  alias initialize_copy initialize
  def initialize
    initialize_copy
    #i have made the coordinates container an array so many can be stored
    #when we come to storing the coordinates it will look like so:
    #[[x, y], [x, y], [x, y]]
    @image_coordinates = []
  end
end

class Scene_Menu
  def initialize(menu=false)
  @menu = menu
  end
  def main
    #i am creating an array to store all the images inside so they can be counted and used easilly
    # in you images array for each image make another array like this: [IMAGE_NAME, INITIAL_X, INITIAL_Y]
    #first we condition if it is calling from the map
    if @menu #called from the map
      @images = [
        ["image1", X, Y],
        ["image2", X, Y]
        #ect
      ]
    else #it is not been called from the map
      x_y_source =  $game_temp.image_coordinates
      @images = [
        ["image1", x_y_source[0][0], x_y_source[0][1]] #[0] is because the first in an array has an id of 0 not 1
        ["image2", x_y_source[1][0], x_y_source[1][1]]
        ["image3", x_y_source[2][0], x_y_source[2][1]]
        #ect
        #we could create ^ that into a loop but im just hardcoding it for this example
      ]
    end
    #create the images:
    @sprite1 = Sprite.new
    @sprite1.bitmap = RPG::Cache.LOCATION(@images[0][0]) #the filename
    @sprite1.x = @images[0][1]
    @sprite1.y = @images[0][2]
    #ect
    #then continue with creating your scene
  end
  def udate
    #to change the x and y we loop through all our images
    for i in 0...@images.size
      #change the x and y
      new_x = @images[i][1] + 1 #or whatever value it increases by
      new_y = @images[i][2] + 1 #ect
      #next we replace the old image array with the one with new x and y values
      # [the name(never changes), the new x, the new y]
      replacment_array = [@images[i][0], new_x, new_y]
      @images[i] = replacment_array
    end
    #then change your x and y's how you would

    #now in the update method we dump the x any y values when calling another Scene
    if Input.trigger?(Input::C)
      case @command_window.index 
      when 0 #item scene
        for i in 0...@images.size
          #first we create our x and y container:
          $game_temp.image_coordinates[i] = []
          #then we push each value into it:
          #                                                           x                y
          $game_temp.image_coordinates[i].push(@images[i][1], @images[i][2])
        end
      end
    end
  end
end

if you add those functions you should succeed in what you need, you could simplify it by creating an x and y variable for every image to store
but with arrays you save space and create large containers, i hope i have explained it well enough :)

KK20

Before I get into it, I suggest adding comments and using proper indenting for easier reading of your scripts.

1.) How to tell if the menu was opened from map or from another sub-menu:
class Scene_KEngineMain
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     menu_index : command cursor's initial position
  #--------------------------------------------------------------------------
    def initialize(menu_index = 0, from_map = true)
    @menu_index = menu_index
    @from_map = from_map
  end

And in your sub-menus (note the false when declaring the Menu Scene):
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $from_map = 0
      $scene = Scene_KEngineMain.new(0, false)
      return
    end


2.) Your waves in the background
The x-values of those sprites do nothing by the way. A simple print function gave me nil all the time. So, instead of @mnan.x, set it to @mnan.ox.

First, adding variables to Game_Temp:
class Game_Temp
  attr_accessor :wave1, :wave2, :wave3
 
  alias reinit_for_wave_oxs initialize
  def initialize
    reinit_for_wave_oxs
    @wave1, @wave2, @wave3 = 0, 0, 0
  end
 
  def store_wave_oxs(w1, w2, w3)
    @wave1, @wave2, @wave3 = w1, w2, w3
  end
 
end

And an example of how to initialize your waves in the Main Menu class:
@mnan.ox = @from_map ? 0 : $game_temp.wave1

And an example in the sub-menu classes:
@mnan.ox = $game_temp.wave1

Also, in both Menu and Sub-menu classes, add this line directly above the Graphics.freeze:
$game_temp.store_wave_oxs(@mnan.ox, @mnan2.ox, @mnan3.ox)


Blarg, so tired...hopefully I didn't miss anything.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Zexion

October 13, 2012, 12:24:33 pm #11 Last Edit: October 13, 2012, 12:54:23 pm by Zexion
Thank you so much KK20, and all of you that helped :D it's workin now weee levels for all :P

Btw, I would normally use proper indenting and lots of comments, but I want to take out as many kbs as possible, so I'm leaving everything connected and eventually when I'm done I'll delete comments lol. Since I'm going to release this, I will also make a seperate version with all comments/indenting.

Zexion

Another question. How would I save the index of a scene into a variable? The problem is i need to render the actor names in a verticle column which changes with the amount in the party, and shifts +6 x to the right when selected. I tried making a global variable and setting it to a number when case @command_window.index = whatever# , but it won't update the text when moving through the menu. I could just cheap out and straight up change the graphics to not move, but that wouldn't be very cool.

KK20

Er, I don't understand what you're doing? idunnolulz
Sounds more like an updating problem than a "saving index to a variable".

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Zexion

Spoiler: ShowHide
#==============================================================================#
#                          Kingdom Hearts Main Menu                            #
#       Scripted from scratch by Zexion/Chaos-Zexion based on Mog Menus        #
#==============================================================================#
#                                The Item Menu                                 #
#==============================================================================#
module ItemParts
  ITEM_1BUT1 = "Menu-1IB1"
  ITEM_1BUT2 = "Menu-1IB2"
  ITEM_2BUT1 = "Menu-2IB1"
  ITEM_2BUT2 = "Menu-2IB2"
  ITEM_2BUT3 = "Menu-2IB3"
  ITEM_3BUT1 = "Menu-3IB1"
  ITEM_3BUT2 = "Menu-3IB2"
  ITEM_3BUT3 = "Menu-3IB3"
  ITEM_3BUT4 = "Menu-3IB4"
  ITEM_SEL1  = "Menu-ItemSel1"
  ITEM_SEL2  = "Menu-ItemSel2"
  ITEM_SEL3  = "Menu-ItemSel3"
  ITEM_SEL4  = "Menu-ItemSel4"
  ITEM_SEL5  = "Menu-ItemSel5"
end
  class Window_ActorName < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #-------------------------------------------------------------------------- 
  def initialize
    super(0, 0, 320, 224)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.windowskin = RPG::Cache.windowskin("")
    self.opacity = 0
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #-------------------------------------------------------------------------- 
  def refresh
    self.contents.clear
    self.contents.font.name = "Calibri"
    self.contents.font.size = 14
    @item_max = $game_party.actors.size
    for i in 0...$game_party.actors.size
    if $game_party.actors.size == 1     
      case @command_window.index
      when 0
      actor = $game_party.actors[0]
      draw_actor_name(actor, 20, 30)
      self.contents.draw_text(14, 45, 32, 32, "Stock")
      when 1
      actor = $game_party.actors[0]
      draw_actor_name(actor, 14, 30)
      self.contents.draw_text(20, 45, 32, 32, "Stock")
      end
    elsif $game_party.actors.size == 2
      actor = $game_party.actors[0]
      draw_actor_name(actor, 14, 30)
      actor = $game_party.actors[1]
      draw_actor_name(actor, 14, 45)
    elsif $game_party.actors.size == 3
      actor = $game_party.actors[0]
      draw_actor_name(actor, 14, 30)
      actor = $game_party.actors[1]
      draw_actor_name(actor, 14, 45)
      actor = $game_party.actors[2]
      draw_actor_name(actor, 14, 60)
    end
    end
  end
end
#==============================================================================
# ** Scene_KEngineItem
#------------------------------------------------------------------------------
#  This class performs main menu screen processing.
#==============================================================================
  class Scene_KEngineItem
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     menu_index : command cursor's initial position
  #--------------------------------------------------------------------------
    def initialize(menu_index = 0)
    @menu_index = menu_index
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make Command Window
    s1 = ""# Equip for Actor #1
    s2 = ""# Equip for Actor #2
    s3 = ""# Equip for Actor #3
    s4 = ""# Stock (inventory)
    if $game_party.actors.size == 1
    @command_window = Window_Command.new(160, [s1, s2])
    elsif $game_party.actors.size == 2
    @command_window = Window_Command.new(160, [s1, s2, s3])
    elsif $game_party.actors.size == 3
    @command_window = Window_Command.new(160, [s1, s2, s3, s4])
  end
    @command_window.index = @menu_index
    @command_window.opacity = 0
    @command_window.windowskin = RPG::Cache.windowskin("")
    @mnbg = Sprite.new
    @mnbg.bitmap = RPG::Cache.picture(Parts::BACKGROUND)
    @mnbg.opacity = 255
    @mnan = Plane.new
    @mnan.bitmap = RPG::Cache.picture(Parts::ANIMATION)
    @mnan.opacity = 160
    @mnan.ox = $game_temp.wave1
    @mnan2 = Plane.new
    @mnan2.bitmap = RPG::Cache.picture(Parts::ANIMATION)
    @mnan2.opacity = 200
    @mnan2.ox = $game_temp.wave2
    @mnan3 = Plane.new
    @mnan3.bitmap = RPG::Cache.picture(Parts::ANIMATION)
    @mnan3.opacity = 255
    @mnan3.ox = $game_temp.wave3
    @mntop = Sprite.new
    @mntop.bitmap = RPG::Cache.picture(Parts::TOP_SEC)
    @mntop.opacity = 255
    @mntop.x = 0
    @mnlwl = Sprite.new
    @mnlwl.bitmap = RPG::Cache.picture(Parts::LWL_SEC)
    @mnlwl.opacity = 255
    @mnlwl.y = 0
    @mnlwr = Sprite.new
    @mnlwr.bitmap = RPG::Cache.picture(Parts::LWR_SEC)
    @mnlwr.opacity = 255
    @mnlwr.x = 0
    @mnbut = Sprite.new   
    if $game_party.actors.size == 1
    @mnbut.bitmap = RPG::Cache.picture(ItemParts::ITEM_1BUT1)
    elsif $game_party.actors.size == 2
    @mnbut.bitmap = RPG::Cache.picture(ItemParts::ITEM_2BUT1)
    elsif $game_party.actors.size == 3
    @mnbut.bitmap = RPG::Cache.picture(ItemParts::ITEM_3BUT1)
    end
    @mnbut.opacity = 0
    @playtime_window = Window_PlayTime.new
    @playtime_window.x = -60
    @playtime_window.y = 124
    @playtime_window.contents_opacity = 255
    @munny_window = Window_Munny.new
    @munny_window.x = -35
    @munny_window.y = 174
    @munny_window.contents_opacity = 255
    @mapname_window = Window_Map_Name.new
    @mapname_window.x = 140
    @mapname_window.y = -5
    @mapname_window.contents_opacity = 255
    @charnames = Window_ActorName.new
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      @mnan.ox -= 3
      @mnan2.ox -= 2
      @mnan3.ox -= 1
      # 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
    $game_temp.store_wave_oxs(@mnan.ox, @mnan2.ox, @mnan3.ox)
    # Prepare for transition
    Graphics.freeze
    @mnbut.dispose
    # Dispose of windows
    @command_window.dispose
    @munny_window.dispose
    @playtime_window.dispose
    @mapname_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    @mnbut.opacity = 255
    # Update windows
    @command_window.update
    @playtime_window.update
    update_command
  end
  def update_command
    if $game_party.actors.size == 1   
    case @command_window.index
    when 0
    $
    @mnbut.bitmap = RPG::Cache.picture(ItemParts::ITEM_1BUT1)
    when 1
    @mnbut.bitmap = RPG::Cache.picture(ItemParts::ITEM_1BUT2)
  end
    elsif $game_party.actors.size == 2
    case @command_window.index
    when 0
    $position_name = 0
    @mnbut.bitmap = RPG::Cache.picture(ItemParts::ITEM_2BUT1)
    when 1
    $position_name = 1
    @mnbut.bitmap = RPG::Cache.picture(ItemParts::ITEM_2BUT2)
    when 2
    $position_name = 2
    @mnbut.bitmap = RPG::Cache.picture(ItemParts::ITEM_2BUT3)
  end
    elsif $game_party.actors.size == 3
    case @command_window.index
    when 0
    $position_name = 0
    @mnbut.bitmap = RPG::Cache.picture(ItemParts::ITEM_3BUT1)
    when 1
    $position_name = 1
    @mnbut.bitmap = RPG::Cache.picture(ItemParts::ITEM_3BUT2)
    when 2
    $position_name = 2
    @mnbut.bitmap = RPG::Cache.picture(ItemParts::ITEM_3BUT3)
    when 3
    $position_name = 3
    @mnbut.bitmap = RPG::Cache.picture(ItemParts::ITEM_3BUT4)
  end
    end

    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $from_map = 0
      $scene = Scene_KEngineMain.new
      return
    end
    if Input.trigger?(Input::C)
    if $game_party.actors.size == 1   
    case @command_window.index
    when 0
      #open actor 1 equip
    when 1
      #open stock items
  end
    elsif $game_party.actors.size == 2
    case @command_window.index
    when 0
      #open actor 1 equip
    when 1
      #open actor 2 equip
    when 2
      #open stock items
  end
    elsif $game_party.actors.size == 3
    case @command_window.index
    when 0 
      #open actor 1 equip
    when 1
      #open actor 2 equip
    when 2
      #open actor 3 equip
    when 3
      #open stock items
    end
  end
    end
  end
end

I have no idea what I have in that code atm i kinda just had it open for a while lol. Basically I want to shift the name, or text over by 6 spaces depending on the value of @menu_idex. My problem is i don't know how to make it update the variable i used to save it in, and also I don't exactly know if that is the best way to do it..

KK20

Your names are drawn in @charnames. Nowhere in the Items scene does that ever get updated.

First off, add this into your class Window_ActorName
  alias update_and_refresh update
  def update
    update_and_refresh
    refresh
  end
Also, replace your refresh method with
  def refresh
    self.contents.clear
    self.contents.font.name = "Calibri"
    self.contents.font.size = 14
    @item_max = $game_party.actors.size
    y = 0
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      if self.index == i
        draw_actor_name(actor, 26, 30+y)
      else
        draw_actor_name(actor, 20, 30+y)
      end
      y += 15
    end
  end
And in your Scene update method, be sure to add:
@charnames.update

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Zexion

October 16, 2012, 12:13:55 pm #16 Last Edit: October 16, 2012, 06:07:51 pm by Noctis
Spoiler: ShowHide
Lol like I said I really didn't know what was there when I posted it :p I think at that point I was frustrated and started removing junk..
Anyways, Thanks for the fix again your definitely getting credit for this lol.

Edit: I just got around to adding the fix, and I realized that it still doesn't work. I forgot to mention that the actorname window is never actually selectable, it's just a window to display names..which is why i mentioned i need to make the it store the command_window.index instead of it's own. On the plus side you managed to make me look like a complete noob :wacko: and reduced def refresh code like x10  :naughty: so that's always good haha