Then let's practice some scripting.
For starters open your project. Now open up the Script Editor, it's the icon with the pencil and the writing tablet. Or press F11 which is the shortcut key. On the right side of this window is the code panel. All the code we will be writing goes in that section. To the left is the script listings. Every section can be modified or edited to suit your needs. It's what makes VX so flexible. Each section in VX represents a class that coincides with its label in the left hand side. Selecting
Scene_Title for example will reveal the
Scene_Title class and all the code associated with it on the right. Within classes there are methods. These methods dictate the behavior of the class. For example in
Scene_Title there's a method called
create_title_graphic. This method creates the sprite object that will hold the bitmap that displays when you start the game. This method will be overridden because we want to make a
Plane object instead.
Plane objects are special in that they can tile a bitmap. Which is what you are looking for.
Now onto the first rule of thumb.
Don't edit the existing scripts. Sure it's easy to do but not the wisest maneuver. We can alter every piece of code using redefinition(overriding) and aliasing. We won't be using alias I don't think. A quick example of overriding:
class Test
def method_test
print 'tsaot'
end
end
class Test
def method_test
print 'toast'
end
end
test = Test.new
test.method_test # This will print "toast"
What is effectively occurring is that when the code is read during runtime it sees two definitions of same method. So which one is used? The last one encountered is the one that will be used.
Why is this important? This is the idea we will use to replace the
create_title_graphic method within
Scene_Title. So right click the "( Insert here )" section in the script listing on the left and select
Insert (Ins). Start with the class definition line:
class Scene_Title < Scene_Base
Skip down a couple lines and have the end block:
Now in the script listings on the left run to the default Scene_Title section we are going to copy the original
create_title_graphic. Now go back to our custom section. Paste this method within the class definition line and the end. It should be pretty simple if you were following along but just in case. Here's what it should look like right now:
class Scene_Title < Scene_Base
def create_title_graphic
@sprite = Sprite.new
@sprite.bitmap = Cache.system("Title")
end
end
Remember me telling you about the Plane object? Well let's put it to use. Change:
to:
Now if you run the code you should see absolutely no change. That's good because we haven't incorporated the most important part of using a plane object, scrolling. But to use scrolling we would need to constantly affect the
Plane. In short we need to copy another method from the original default
Scene_Title. So scoot on back to
Scene_Title and search for
update. Copy the whole method and add it into our custom Scene_Title section like we did with the
create_title_graphic method. Within update you should see the line:
This line calls Scene_Base's update but that's a whole different case of worms. The importance of it is that right below it we are going to add two new lines of code:
@sprite.ox += 1
@sprite.oy += 1
What these lines do is offset where on the bitmap to begin drawing from. Let's say we had a 100x100 pixel bitmap. If I set ox to 50 the bitmap would start to draw at 50, 0 effectively halving the bitmap.
class Scene_Title < Scene_Base
def create_title_graphic
@sprite = Plane.new
@sprite.bitmap = Cache.system("Title")
end
def update
super
@sprite.ox += 1
@sprite.oy += 1
@command_window.update
if Input.trigger?(Input::C)
case @command_window.index
when 0 #New game
command_new_game
when 1 # Continue
command_continue
when 2 # Shutdown
command_shutdown
end
end
end
end
If you run the code now you should see the background scroll to the upper left. Lower right would be a -= 1 instead of += 1. Refer to the readme for a different explanation if you want.
Next flashing "PRESS START" and then the command window appears. To get this guy we will need to alter a lot more methods. Once again go into the default
Scene_Title class and grab the
post_start method this time. Paste it in our custom
Scene_Title like before. We don't want the window to open when we first start. We want the "PRESS START" to appear instead. So delete the
open_command_window line. In place of it we are going to create a sprite object. And initialize it's bitmap object so we can draw text on it. So we will have:
def post_start
super
@press_start = Sprite.new
@press_start.bitmap = Bitmap.new(128, 24)
end
Now to actually draw on it. We will use Bitmap.draw_text which takes in a x coordinate, y coordinate, the maximum width the string is allowed to use when drawing, the maximum height string is allowed to use when drawing, the actual string that will draw, and alignment which by default is left(0). But it can be (1) center or (2) right.
@press_start.bitmap.draw_text(0, 0, 128, 24, "PRESS START", 1)
And let's not forget to place the image somewhere other than 0, 0. So below the the line drawing the text have:
@press_start.x = n
@press_start.y = o
When n and o represent the values of where you want the sprite to appear. Quick note: Screen Coordinates. The y axis is flipped and the origin is at the upper left. So y increases as you go down. And for the hell of it let's create one more thing. A variable that will modulate the opacity of @press_start.
Now to get it modulate opacity. We will go back into update. But first we need to make sure that if the @press_start sprite exists than don't do any of the other code in the update method. We don't need to test for window input or update the window if @press_start isn't disposed. We still want it to scroll regardless. This converts our update method to:
def update
super
@sprite.ox += 1
@sprite.oy += 1
if !@press_start.disposed?
else
@command_window.update
if Input.trigger?(Input::C)
case @command_window.index
when 0 #New game
command_new_game
when 1 # Continue
command_continue
when 2 # Shutdown
command_shutdown
end
end
end
end
Are you following so far? Next we need to modulate the opacity of the sprite. So remember that @dir variable we created. Inside the first part of that if statement we are going to add it to the current opacity of the @press_start sprite:
@press_start.opacity += @dir
Opacity for all objects that have opacity are capped at the maximum of 255 and the minimum of 0. If the sprite already has an opacity of 255 and you add 1 it will not be 256 it will remain at 255. This is only relevant to the next part. Which is reversing @dir if opacity is equal to the min or max of opacity. So below the addition to the opacity incorporate the following check:
@dir *= -1 if @press_start.opacity == 255 || @press_start.opacity == 0
That will reverse @dir once the opacity reaches 255 or 0.
If you run the code now you should see "PRESS START" text where ever you placed it on screen and it should fade to nothing and fade in and continually do it forever. Let's make sure forever ends when the user actually presses the C button. So below our check for opacity min and max. Make another if statement. Built into VX an Input module that catches all the buttons that VX uses. We will be checking for the key press of Input::C. Which would look like this:
if Input.trigger?(Input::C)
end
Within this if statement we need to do exactly three things. First we need to dispose of our press start sprite and it's bitmap. Then we need to open the Window_Command we prevented from opening.
@press_start.bitmap.dispose
@press_start.dispose
open_command_window
If you run it now and press the action key you should see a little hiccup as the window opens. To correct this we need to override one last method,
open_command_window. For one last time go back to the default
Scene_Title section and copy that method and paste it into our custom
Scene_Title. Include the lines for scrolling the ox and oy like we did above into the loop it should look something like this:
def open_command_window
@command_window.open
begin
@sprite.ox += 1
@sprite.oy += 1
@command_window.update
Graphics.update
end until @command_window.openness == 255
end
If you're really interested in learning Ruby which is the code used in RGSS2 search for Ruby tutorials there are plenty of them on this site and also don't be afraid to google it either. If you get stuck let us know and we'll try to help you.
Good luck with it +++Danny+++! :thumb: