how does the Viewport system work in RGSS?

Started by Ryex, November 18, 2009, 07:28:39 pm

Previous topic - Next topic

Ryex

how does the Viewport system work in RGSS? ie. If I have a bunch of sprite in several different view ports how do I know the stack order of the sprites
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

G_G

well to change the layer of each viewport use
viewport.z

And I think they work the same way views do in game maker. Pretty much the x and y are the location of this view on screen. Of course width and height is well width and height.
I guess they're pretty much like Rects.

Cant really explain it. But I think they're used to follow something like the viewport1 in Spriteset_Map is used to draw the map where the player is which creates an effect that its following the player.

I think anyways...might wanna ask someone experienced with viewports >___>

fugibo

The Viewports are automatically drawn in ascending order of Z value, and within each the sprites are drawn the same way. It's just a way to collect sprites and limit where they're drawn.

Ryex

November 18, 2009, 10:20:36 pm #3 Last Edit: November 18, 2009, 10:25:30 pm by Ryexander
so
viewport 1: z=1
 sprite 1: z=1
 sprite 2: z=2
viewport 2: z = 2
 sprite 3: z = 1
 sprite 4: z = 4
viewport 3: z = 3
 sprite 5: z = 1

would be drawn

sprite 5 on top
then sprite 4
then 3
then 2
then 1?

not
sprite 4
2
and then 5, 3, and one depending on the order drawn?

so if i create a new viewport, and then pass it as an argument to several sprites, changing the z of said viewport would change the draw position for all of the sprites that have it as an argument?

I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

fugibo

Quote from: Ryexander on November 18, 2009, 10:20:36 pm
so
viewport 1: z=1
 sprite 1: z=1
 sprite 2: z=2
viewport 2: z = 2
 sprite 3: z = 1
 sprite 4: z = 4
viewport 3: z = 3
 sprite 5: z = 1

would be drawn

sprite 5 on top
then sprite 4
then 3
then 2
then 1?

not
sprite 4
2
and then 5, 3, and one depending on the order drawn?

so if i create a new viewport, and then pass it as an argument to several sprites, changing the z of said viewport would change the draw position for all of the sprites that have it as an argument?




IIRC, yes. But I could be wrong.

Blizzard

You're right, this is how it works. I think that it doesn't just limit where sprites are drawn, it can also increase performance if a sprite is out of the drawing view. Just remember that inside the viewport the coordinates are reset. That means that a sprite with x, y = 0, 0 is located in the upper left corner of the viewport, not the screen.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.