Hi :)
I'm trying to modify the title screen to add the "Credits" option.
I successfully added the "Credits" option to the menu, then I created the method "command_credits" inside Scene_Title.
def command_credits
$scene = Scene_Credits.new
end
then I wrote this for the scene:
class Scene_Credits
def main
@window = Window_Credits.new
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@window.dispose
end
def update
@window.update
end
end
then this for the window:
class Window_Credits < Window_Base
def initialize
super(0, 0, 640, 480)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
def refresh
self.contents.clear
self.contents.font.color = normal_color
self.contents.font.size = 20
self.contents.draw_text(150, 150, text_width, 32, "CREDITS")
end
end
I have two problems:
1-What should I put in text_width?
2-If I put a random nuber in text_width the game gives me the message screen without text.
text_width = self.contents.text_size('STRING TO MEASURE').width
Or is you want simple, just replace text_width width:
It changes nothing...
Regardless of what i put into text_width, the message's window stays blank.
in your update method of the scene:
def update
@window.update
end
@window = Window_Credits.new, so when you put @window.update you are calling a method called update within that class, but as i see in your window class you dont have a method called update but you do have one called refresh, change that line to @window.refresh and see if that solves your problem
That's not the problem. "refresh" is called at the end of the initialization method. "update" can still be called, its merely calling the super's update method since Window_Credits does not override it.
The code you have should be working, are you changing the font?
Also, it may be a stupid question, but is your problem the scene does not change, or that you get a blank window with no text written in it? I'm not sure where you got the "text_width" idea, but many most times you don't need a dynamic measurement of text, you can simply hard-code numbers in there.
def refresh
self.contents.clear
self.contents.draw_text(0, 0, self.contents.width, 32, "Credits", 1)
end
The problem is that i get the new scene, but with no text in it.
@foreverzer0 ah yes i never really considered it using the method from the parent class, so if i was to override it would it void the old method complety or would it act like an extension?
@sbus i coppied your code into a fresh project and everything was fine with it, you must be doing something else to the scene that we are unaware off
@diagostimo:
The old method is used implicitly since the child class does not contain a method for it. The initialize method does override it, but as you can see it uses the "super" call so that the parent class method is still being called.
@sbus:
As diagostimo said, there is something else wrong with your code that is not in what you have posted. I asked about the font earlier, because it will have the effect of not displaying text if you change the font to something that is not installed on the OS.
Everything i changed or added is there.
I haven't changed the font, so I don't think that's the problem.
I tried it in a new blank project, and it doesn't work either.
BTW I'm trying in another computer to see if it's the OS or something the problem.
I doubt that its Windows.
I just made this test real quick, which is essentially the same thing you made. It works fine. See if you have the same problem.
Simply call "$scene = Scene_Credits.new" with a script call.
class Window_Credits < Window_Base
def initialize
super(0, 0, 640, 480)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
def refresh
self.contents.clear
self.contents.font.color = normal_color
self.contents.draw_text(0, 0, 640, 32, 'Credits', 1)
end
def update
super
end
end
class Scene_Credits
def main
@window = Window_Credits.new
Graphics.transition
loop { Graphics.update; Input.update; update; break if $scene != self }
Graphics.freeze
@window.dispose
end
def update
@window.update
end
end
It works.
Lol, I don't know why, but it works.
Thanks a lot. :)
That's very strange. I honestly am not seeing a difference in what I wrote and what you posted other than you set the set the test coordinates, and I simply used the "center alignment" flag.
more on the lines of what i meant is if i create a new update method in the child class would it still contain the contents of the parent class's update method aswell as the new content defined, or would i have to allias it? or even repacliate the parent class's content, just so i know for future reference :)
If you don't call "super" within the method, you completely override it. If you do call super, it is the equivalent of an alias, although it is not quite the same thing.