I hate asking questions, but here we go. So I'm writing an menu system for my game and I'm using sprites instead of windows. What I'm trying to do is to figure out why this title screen keeps doing this:
(https://db.tt/Pri2yAuF)
It's supposed be:
-New Game
-New Game Plus
-Continue/No Data
-Manual
-Website
-Shut Down
But I get what's in that image instead. I'm guessing it's something to do with the symbols I'm using, but I have a headache trying to figure this out for the past day and a half. So I was wondering if anyone else had a solution to this.
Let me teach you how to debug. :)
In Sprite_TitleCommand, make your method look like this
def update_position
@org_pos = [Graphics.width / 2, (26 * @data.size) + 200]
self.x = @org_pos[0]
self.y = @org_pos[1]
self.z = 12
msgbox_p([@data,@data.size,self.x,self.y]) #<============= Namely this guy right here
end
Tell me what you learn after doing this.
Oh :facepalm: it's categorizing each symbol by number of characters instead of the order its in the array. Okay :O.o:
Edit: But why isn't it counting the size of the array, instead of the symbol's characters?
Precisely. I'm guessing you thought @data would be an array of Symbols, and, each time you pushed a new Sprite_TitleCommand in (which would call an update method to change its position), you thought the array's size would increase by one, effectively putting each new sprite below the previous. Problem is that @data will never be an array object, based on the way you are initializing your sprites:
@commands << Sprite_TitleCommand.new(nil, command)
where 'command' is iterating over
TITLE_COMMANDS =[:new_game, :new_game_plus, :continue, :manual, :website,
:shutdown]
So your best solution would probably be to overload your Sprite_TitleCommand to take another parameter for index position, as you said.
def initialize(viewport, data, index)
@item_draw_index = index
...
super(viewport, data)
end
...
def update_position
@org_pos = [Graphics.width / 2, (26 * @item_draw_index) + 200]
...
EDIT:
To achieve the effect you were probably going for, you would need to do
@commands << Sprite_TitleCommand.new(nil, @commands + [command])
but this will cause errors with some of your methods.
Sorry it was 1:45 A.M. and I fell asleep :zzz:
Quote from: KK20 on October 04, 2013, 12:30:29 am
Precisely. I'm guessing you thought @data would be an array of Symbols, and, each time you pushed a new Sprite_TitleCommand in (which would call an update method to change its position), you thought the array's size would increase by one, effectively putting each new sprite below the previous.
Basically yes, but anyways thank you for the help; results:
(https://db.tt/Pri2yAuF)
class Scene_Title < Scene_Base
def create_command_sprites
@commands = []; index = 0
WarriorManager::TITLE_COMMANDS.each do |command|
case command
when :new_game, :continue, :manual, :website, :shutdown
when :new_game_plus then next unless new_game_plus?
else next
end
@commands << Sprite_TitleCommand.new(nil, command, index)
index += 1
end
end
end
class Sprite_TitleCommand < Sprite_CommandBase
def initialize(viewport, data, index)
@item_draw_index = index
...
super(viewport, data)
end
...
def update_position
@org_pos = [Graphics.width / 2, (26 * @item_draw_index) + 200]
...
end
end
Now I just have to fix the graphics (as that looks ugly), create a moving background image (obviously I'm not using that one), and add mouse function to the buttons. Should take a couple of hours.