[Resolved][RMXP] Having an issue with sprites

Started by bigace, October 03, 2013, 09:51:13 pm

Previous topic - Next topic

bigace

October 03, 2013, 09:51:13 pm Last Edit: October 04, 2013, 12:21:41 pm by bigace
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:


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.


Use Dropbox to upload your files. Much simpler than other upload sites, you can simply place a folder on your desktop that will sync with your DropBox account.

KK20

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.

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!

bigace

October 04, 2013, 12:22:14 am #2 Last Edit: October 04, 2013, 12:18:58 pm by bigace
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?



Use Dropbox to upload your files. Much simpler than other upload sites, you can simply place a folder on your desktop that will sync with your DropBox account.

KK20

October 04, 2013, 12:30:29 am #3 Last Edit: October 04, 2013, 01:05:09 am by KK20
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.

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!

bigace

October 04, 2013, 12:14:50 pm #4 Last Edit: October 04, 2013, 12:17:49 pm by bigace
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:



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.


Use Dropbox to upload your files. Much simpler than other upload sites, you can simply place a folder on your desktop that will sync with your DropBox account.