I'm using a Spritesheet in an AS3 project, and upgrading from using a very resource heavy method of cutting up the bitmap into each frame and then storing them, to using scrollRect so it just displays the required frame. That is working mostly fine with a HUGE resource saving.
That said, there is a problem as the sprite as displayed via scrollrect is now jumping around like crazy. The Spritesheets have been checked and are fine, and seam to be okay on small sheets where there is only one row of sprites, so only the X axis is moved in.
However, on larger ones, like the main character, where there are more then one row, it's a lot worse.. When the sprite is loaded, it is given the values for the height and width of the sprite in question, and then it works out how many sprites in the sheet (counting blank spaces which are later ignored) and puts the values into an point array. The sprites are a fair size, so each frame is 480 width by 631 height (I know that isn't a square of 2 but I don't see an issue with that).
the code for making that array is pretty simple and is as follows:
'var tempSprite:Point;
for (var k:int = 0; k < h; k++){
for (var j:int = 0; j < i; j++) {
tempSprite.x = (SpriteWidth) * j;
tempSprite.y = (SpriteHeight * k)
SpriteOffsets.push(tempSprite);
}
}'
Bitmapdata is given for each time it changes to a new sheet and that works fine, also it checks to make sure its not changing it to a new sheet when one isn't required. scrollRect is done passing the X and Y value from the point array (SpriteOffsets) along with giving the width and height of the sprite, so it knows the full size. it is then set to cacheAsBitmap (to make sure) and smoothing is turned on.
problem appears to kinda be weird.. as if it's trying to do a scale and screwing up as often it's a pixel out, sometimes more. When scaling the player window, it also appears to affect the amount it is out by differently. It appears to only be the Y axis though.
When using a transparent PNG source for the bitmap data, it also appears that it is 'snapping' to the top of the frame more then displaying everything, including the blank lines.
the code i'm using for the Scrollrect is just:
bitmap.scrollRect = new Rectangle(SpriteOffsets[FrameOrder[AnimSet][AnimFrame]].x, SpriteOffsets[FrameOrder[AnimSet][AnimFrame]].y, RSpriteWidth, RSpriteHeight);
where the Spriteoffset bits call from the SpriteOffset array which stores (and I've checked) the correct X and Y position for the start of the frame, and RSpriteWidth and RSpriteHeight are the height and width of the frame, which are static for all frames. So all fairly typical of creating such as thing as I understand.
Really, this is my first try at upgrading to using scrollRect and while there are SOOO many pluses.. this seam to be creating a huge problem for me..
I have tried to manually work out the sprite offset and to account for that, it also appeared, at one time, that the rectangle was in fact, 1 pixel too tall, despite being told the correct number of pixels, so I tried to just reduce the height by 1 but to little avail.
Thank you for any help or advice.