X.new creates a new object of the class X, and runs the initialize method on that object. This line here sets the variable background_sprite to be a new object of the Sprite class.
Remember your American-English, Ms.
Just to note, there doesn't
need to be an 'initialize' method defined in a class. If there is such a method, however, that's probably the first thing to be called.
@Boe (+anyone else who cares)
Check this article out here:
http://www.rubyist.net/~slagell/ruby/objinitialization.htmlIt tells you a little about object initialization following the use of X.new.
That is setting the bitmap property of the instance variable @background_sprite to the background_bitmap method of the SceneManager module.
That's all I can tell you for now, unfortunately, as I don't have VXA on this computer, because it can't run VXA, because it's a MacBook. And I can't be bothered using Boot Camp and installing VXA right now.
This is why I find it hard to move away from Windows. At least I know things work with Windows.
As a little extra, here's a thing to keep in mind. Using your code snippet as an example:
def create_background
@background_sprite = Sprite.new
@background_sprite.bitmap = SceneManager.background_bitmap
@background_sprite.color.set(16, 16, 16, 128)
end
Specifically with the line:
@background_sprite.bitmap = SceneManager.background_bitmap
SceneManager, as you will notice if you look at the list on the left in the editor, is a script. When it comes to the default editor (with no added custom scripts involved) the names of the scripts share the name with the classes/modules that are written in that script. The 'SceneManager' script contains the module, SceneManager, which as you can see from the code is being directly referred to in the code 'SceneManager.background_bitmap'. What you can do, is look at the script and try to find a method called 'background_bitmap'.
def self.background_bitmap
@background_bitmap
end
This is that method. You will notice the 'self' part prefixing the method name, but I wouldn't concern yourself with that just yet - you can expand your knowledge into the
self part of a class or module later. For now, just know that
SceneManager.background_bitmap is calling that method there.
This method does one thing only. It returns the variable,
@background_bitmap. It's not necessary to use the
return keyword in certain situations. Basically, the last statement, or line, in a method will return the result of that statement on its own, without any direction from the programmer. It just does that for some reason. It took me a while to get used to it, because I come from other languages where the
return is needed to return some object or value.
In this particular example, whatever @background_bitmap refers to will be handed back to the method that called SceneManager.background_bitmap. If you change that variable, you can change what background bitmap is handed back.
@background_sprite.bitmap = SceneManager.background_bitmap
In this line, then, the bitmap that is held in the @background_bitmap variable in SceneManager is being assigned to the bitmap of @background_sprite. So if @background_bitmap in SceneManager is "CloudyFields", following this line of code above, @background_sprite.bitmap is now also "CloudyFields".
Hopefully that helps a little. I know that my explanations tend to get a little winded and can be a bit confusing straight away.
WWTP?
I was hoping that even with my complete lack of scripting knowledge, I could understand enough to poke it until it did what I wanted it to.
This is how I learned how to use Ruby. Just have patience, do some research and ask questions. Keep poking and eventually you will get there.