Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[Resolved] Viewport

Status
Not open for further replies.
How exactly do I use viewports? I cant find any documentation on them. I know they have something to do with making a graphic stay on the map rather than the screen, but for the life of me I cant figure it out.
 
No. Viewport are basically a plane of which things are drawn on. You layer the viewports on top of eachother, and layer sprites on the viewport.

Code:
viewport = Viewport.new(x, y, width, height)
viewport.z = z

I image the default Viewport for all images to be a 0, 0, 640, 480 with a 0 z.

Check the help file for more info on how to create them, but there's not a lot of documentation on it.


Think of it as you draw picture on a paper. The paper can be any size and such. You can layer images on your picture, but then you can stack the papers on top of eachother. It's kinda the same here.
 
Sprites, Bitmaps, Viewpoints. They're all a jumble in my understanding. I thought bitmaps were the so-called paper that you stack on each other. I've read many tutorials, but I still cant seem to grasp the concepts of them all, and my ability to manipulate them is limited.

But thank you, I understand a little better now. I guess I have to just keep playing around them them a bit.
 
Umm i´ll try to be as incisive as i can...

Imagine that Sprite is the most important element. It´s the object responsible for showing anything on the screen. But the sprite itself is an empty element, it needs to have something "inside" it to really show anything. And because of that we have the Bitmaps, that are like the "skin" for the sprites. Now, the piece of the sprite that will be shown on the screen will depend ONLY on the bitmap´s size (or on its src_rect property, read about that later, it´s on the help file). So, if you have a bitmap that´s 640x480, the sprite will take all the space on the screen (in the case it´s positioned at the top left point).

Sometimes, in your coding, you need to limit the sprites' sizes for some reason. Imagine we don´t want the bitmap to occupy all the screen, only the top half. For that we use a Viewport WHEN we initialize a Sprite object. When a sprite has a viewport, we can, like SS said, layer them somehow, and keep track of trivial data like Z and the part of the sprite that will be shown on the screen. Also, with viewports you can easily flash and blend colors in a sprite. Tilemaps and Planes uses them, and every object that´s sprite-based can.

Imagine that:
bitmaps -inside-> Sprites <-attached_by- Viewports

For instance, test those two codes on a new event on map:

Event 1:
Code:
# Trying to make a sprite without a bitmap...
sprite = Sprite.new
# WTF! Nothing appears!!

Event 2:
Code:
# Now let´s put a bitmap into it!
sprite = Sprite.new
sprite.bitmap = RPG::Cache.title("001-Title01")
# Hey! A title screen! Nice!

Event 3:
Code:
# Create a new viewport to control the sprite
view = Viewport.new(160, 120, 320, 240)
# Create the sprite attaching a viewporto to it
sprite = Sprite.new(view)
sprite.z = 0
sprite.bitmap = RPG::Cache.title("001-Title01")
# Now we can change sprite´s Z with the viewport. Note that the sprite´s Z
# and the viewport´s Z are different!
view.z = 5001
# That will make the sprite appear above all screen sprites (events, map and such)

Now test the code and see the difference... ^^


P.S.: I did a nice post about Sprites and Bitmaps, i have to find it lol ^^
P.S.2 (or edit ^^): FOUND IT!
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top