(RMVXA) create_background [Me again ._.]

Started by BanisherOfEden, March 14, 2013, 02:50:05 am

Previous topic - Next topic

BanisherOfEden

Hello, it's me again.   ._.

This time, I want to screw up mess with the drawing of the menu background.
 
  def create_background
    @background_sprite = Sprite.new
    @background_sprite.bitmap = SceneManager.background_bitmap
    @background_sprite.color.set(16, 16, 16, 128)
  end


So, I'm most likely completely wrong... but this is what I think it's doing.
background_sprite = sprite.new
I see this a lot, the whole X.new. Not sure what it does. >_>

The part where it says~
@background_sprite.bitmap = SceneManager.background_bitmap
That's pulling the image SceneManager.background_bitmap from somewhere, and setting it as background_sprite... right? (I think I have that backwards.)

(Sorry scripters, mak'n u faceplam and junk.)

TS;DB
Is there a way for me to substitute "Scenemanager.background_bitmap" for another image?

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.
Max characters: 2000; characters remaining: 1952

diagostimo

hey there banisher, first ill explain a little about what the .new means, basically when you have a class and you want to use it, it must be created, to do this we assign it to a variable that we can use, so for example:

variable = classname.new

that creates the class we want to use and can be used with the variable name.
so next in this case we are using the Sprite class, which is used for drawing images to, to actually make the sprite have graphics we use its bitmap, just think of that as the paper you draw too, we can create a blank bitmap that we can add drawings to, or we can create a bitmap that already has graphics, I use xp but I think the classes are pretty similar, to make a sprites bitmap have graphics we would do this:

sprite = Sprite.new
sprite.bitmap = Bitmap.new(GRAPHICS_NAME_INCLUDING_DIRECTORY)
#so if I wanted to use an image called image in the directory graphics:
sprite.bitmap = Bitmap.new("graphics//image")

to create a blank bitmap we add drawings to we would do this:

sprite = Sprite.new
sprite.bitmap = Bitmap.new(WIDTH, HEIGHT)
#to actually draw to our blank bitmap we use other bitmap objects,
#so to draw an image to our blank bitmap
bitmap2 = Bitmap.new("image")
sprite.bitmap.blt(X, Y, bitmap2, RECT)

what happens there is pretty self explanatory, you define the x and y location the image will be drawn on the bitmap, then you tell it what image its going to draw, then you define a the rectangle area of the source image its going to draw, the rect is this:
Rect.new(X, Y, WIDTH, HEIGHT)
the rect is used to only draw part of an image, and is very useful for that as its used to animate characters ect, but if you want to draw the whole image you still have to define a rect area, so here is a couple of examples of us using the rect:

#blah blah we've already created our sprite and bitmap
#the following example will draw our second bitmap on our first bitmap at the x of 0 and the y of 0,
#it will also draw the whole bitmap defined by the rect
sprite.bitmap.blt(0, 0, bitmap2, Rect.new(0, 0, bitmap2.width, bitmap2.height))
#an example of the rects parameters
Rect.new(X1, Y1, X2, Y2)
#X1 & Y1 are the start locations and X2 & Y2 are the end locations for the area coppied,
# so for the whole bitmap we start at 0 and end at its width/height

#this would just copy the given area:
sprite.bitmap.blt(0, 0, bitmap2, Rect.new(40, 40, 80, 80))
#so the area drawn to the bitmap would start at 40pixles and end at 80 for both x&y,
# drawing a 40x40 square area of the bitmap


so that's an overview of how the drawing works, I think iv been pretty clear so I hope this helps :)

BanisherOfEden

You've been both clear and helpful. Thank you. ^_^
I'll put this knowledge to good use.
Max characters: 2000; characters remaining: 1952