T2dScroller - setScrollPosition
by Phillip O'Shea · in Torque Game Builder · 05/31/2008 (8:53 pm) · 1 replies
There is an error when setting the scroll position of a t2dScroller in TGB. It relates to how the protected fields "scrollPositionX/Y" are loaded once a scene is loaded.
In TGB when you set the scroll position of a scroller, it will scale that number back based upon the number of times it repeats and the size of the object. This new value is then saved into the field "scrollPositionX/Y", as one would expect. When the scene loads, this value is then scaled again (because it is a protected field, it runs through the setScrollPosition function again). This means that the scroll position you set inside your level builder will never be the same as the one inside your game.
A really dirty and quick fix would be to remove the rescaling alltogether:
In TGB when you set the scroll position of a scroller, it will scale that number back based upon the number of times it repeats and the size of the object. This new value is then saved into the field "scrollPositionX/Y", as one would expect. When the scene loads, this value is then scaled again (because it is a protected field, it runs through the setScrollPosition function again). This means that the scroll position you set inside your level builder will never be the same as the one inside your game.
A really dirty and quick fix would be to remove the rescaling alltogether:
void t2dScroller::setScrollPosition( F32 scrollX, F32 scrollY )
{
// Yes, so calculate texel shift per world-unit.
//const F32 scrollTexelX = mRepeatX / getSize().mX;
//const F32 scrollTexelY = mRepeatY / getSize().mY;
// Calculate new offset and clamp.
mTextureOffsetX = mFmod( /*scrollTexelX * */ scrollX, 1.0f );
mTextureOffsetY = mFmod( /*scrollTexelY * */ scrollY, 1.0f );
// Reset Tick Scroll Positions.
resetTickScrollPositions();
}About the author
Head of Violent Tulip, a small independent software development company working in Wollongong, Australia. Go to http://www.violent-tulip.com/ to see our latest offerings.
Associate Melv May
The bug report reference is "TGB-90".
Melv.