knoxcoder Posted October 11, 2013 Report Share Posted October 11, 2013 I'm having trouble getting the images to line up correctly when we export a texture atlas that trims empty space. Correct version: I thought I could scale the quad based on the original vs atlas size: Rect size(0, 0, originalSize.x, originalSize.y);Vector2 temp(originalSize.x * pivot.x, originalSize.y * pivot.y);size -= temp;float sx = textureSize.x / originalSize.x;float sy = textureSize.y / originalSize.y;size.left *= sx; size.right *= sx;size.top *= sy; size.bottom *= sy; It produces this: So next I tried to use the offset from the top/left which is the amount removed from the top/left. The idea is to compute the original quad and then get the true quad based on that: Rect size(0, 0, originalSize.x, originalSize.y);Vector2 temp(originalSize.x * pivot.x, originalSize.y * pivot.y);size -= temp;size.left += offset.x;size.right += offset.y;size.right = size.left + textureSize.x;size.bottom = size.top + textureSize.y; It produces this: Any ideas what I'm doing wrong here? Robert Quote Link to comment Share on other sites More sharing options...
lucid Posted October 14, 2013 Report Share Posted October 14, 2013 Hi Robert, I think the following would work, and if I were making the implementation, I would personally do this at load time, and keep the updated pivot points in your dom in place of the ones from the file. Sorry for the late reply, and let me know if this works: originalSize (as written in the scml file for each file) newSize(the new size based on the trimmed atlas file) topLeft(the top left offset in the trimmed atlas) originalPivotAbsoluteX=originalSize.x*pivotX; newPivotAbsoluteX=originalPivotX-topLeft.x; newPivotX=newPivotAbsoluteX/newSize.x; originalPivotAbsoluteY=originalSize.y*pivotY; newPivotAbsoluteY=originalPivotY-topLeft.y; newPivotY=newPivotAbsoluteY/newSize.y; then your new pivot point is newPivotX,newPivotY Quote Link to comment Share on other sites More sharing options...
knoxcoder Posted October 16, 2013 Author Report Share Posted October 16, 2013 This worked. Thanks. Robert Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.