This project is read-only.


Multiple Viewports Skew Parallax Offset Values


When using multiple viewports, layers using parallax effects display the offset differently than when using one singular viewport.

file attachments

Closed Aug 13, 2013 at 11:36 AM by colinvella


TheBroodian wrote Sep 19, 2012 at 7:56 PM

Screencapture of a scene with one single viewport.

wrote Sep 19, 2012 at 7:58 PM

colinvella wrote Sep 20, 2012 at 10:58 AM

Keep in mind that the parallax ratio is not merely a ratio of layer sizes but also factors in the viewport size such that the layers line up exactly at the four edges.

TheBroodian wrote Sep 20, 2012 at 7:36 PM

That's unfortunate. How would one go about making viewports match up?

colinvella wrote Sep 21, 2012 at 11:10 AM

Well, if your two viewports are the same size, the parallax offaets should line offsets. Otherwise you could try rendering to a fullscreen viewport on a render target and copy only the middle bit?

TheBroodian wrote Sep 21, 2012 at 6:50 PM

Well, the issue I'm experiencing is that I've programmed a dynamic splitscreen system to allow for simultaneous co-op play that won't restrict players to be in close proximity to eachother. When they get too far away, the game becomes split screen, when they come close together again, the game reverts back to one viewport. And I've programmed it with a smooth 'snap-out'/'snap-in' style so that the transition between both modes is smooth and the whole effect is hampered by the difference in parallax layers. So- when the game is split screen, both viewports are the same size, but then obviously not when the game is in single-screen mode.

Not to say that any of that is your problem, I would just like to keep my code simple, and it would seem that it would be easier to adjust the way the ratios behave, than to use render targets? And, generally speaking, I would wager a guess that anytime somebody was going to build a world utilizing a parallax effect, they would make the parallax layer large enough that they would never need the viewport to meet any of its four corners.

That being said, if this is working as intended, and you'd rather not tamper with it, then I will take your advice and see what I can do with render targets.

TheBroodian wrote Sep 24, 2012 at 11:46 PM

I manned up and learned how RenderTargets work, after implementing them, the whole thing works fine :) I still feel like it would be a fairly useful feature if you could somehow add a method to give some manual control over parallax behaviors (maybe to allow for constant panning backdrops to give the effect that the player is in motion or something of that sort) but that aside, thank you for the advice.

colinvella wrote Sep 25, 2012 at 8:25 AM

For further control over parallax offsets you can call the Draw method of the layers individually. Heres' the signature:

/// <summary>
/// Visually renders the layer using the given display device,
/// pixel offset from the map origin and display viewport. If
/// wrapAround is set to True, the layer wraps around at the
/// edges across and / or down.
/// </summary>
/// <param name="displayDevice">Display device on which to render layer</param>
/// <param name="mapViewport">viewport on the dipslay device</param>
/// <param name="displayOffset">offset in pixel coordinates into the map from the top left</param>
/// <param name="wrapAround">Flag indicating if layer wrap-around is performed</param>
public void Draw(IDisplayDevice displayDevice, Rectangle mapViewport, Location displayOffset, bool wrapAround)

Just bear in mind that you need to call displayDevice.BeginScene() and .EndScene() before and after the calls.

wrote Feb 22, 2013 at 12:48 AM

wrote Aug 13, 2013 at 11:36 AM