QLNEO Posted August 8, 2017 Share Posted August 8, 2017 Whenever we animate a sprite or image from an atlas, our reference is a (x,y) coordinate that would correspond to the top left of each frame. However, that has some issues when a frame has different dimensions from the previous. Suppose these two frames (i misspelled there, it should be "frame 1" and "frame 2" instead) represent, respectively, the object standing still and the object in movement (that's supposed to be motion blur). Frame 2 has a bigger length than Frame 1, so, relative to its coordinates, the face is more to the right. I want it to look something like this when in movement (let's suppose linear velocity): (in dislocation) For each passing frame, the face is equally distant. The dark red lines represent the spacing between the face in each frame. The red lines represent the (x,y) coordinates in each frame. It's equally spaced. But, since the sprites in movement are larger, between the first and second frames the face is more distant, whereas between the last and second-to-last frames the face looks closer (as shown by the dark red line). The linear movement doesn't look so linear now because of the motion blur. I tried using pictures to be more clear, but I'm not sure if you follow. Having said that, I bet this is a very common problem, so I'm fairly sure this is a known situation. What's the best solution in Phaser? Link to comment Share on other sites More sharing options...
Tom Atom Posted August 9, 2017 Share Posted August 9, 2017 First, make all frames of your animation as large as largest frame in it - atlas tools will trim empty space, so there is no waste, Second, position you characters within frame so it is convenient for you - see example below. Anchor 0.5, 1 can be used for all frames: Link to comment Share on other sites More sharing options...
QLNEO Posted August 9, 2017 Author Share Posted August 9, 2017 Hmm.. The idea of making each frame as large as needed is good and I even thought of it at some point, but if the atlas trims empty space anyway, won't that render these efforts useless? Link to comment Share on other sites More sharing options...
lewster32 Posted August 10, 2017 Share Posted August 10, 2017 Although it trims the empty space, Phaser recreates that missing space when loading the texture, so the effect is of packing more sprites into the atlas, but having them act as if they were all evenly sized. Link to comment Share on other sites More sharing options...
QLNEO Posted August 10, 2017 Author Share Posted August 10, 2017 But aren't sprite dimensions defined by the atlas software itself? I've been creating the spritesheets directly in my paint software and use the atlas tool only to generate the atlas, so maybe that's the problem? Link to comment Share on other sites More sharing options...
Sturb Posted August 10, 2017 Share Posted August 10, 2017 Whenever your software trims the white space, the original dimensions are recorded along with the difference between the origin and trimmed dimensions. When imported into Phaser, Phaser will create a texture the size of the original sprite, and offset the trimmed image by the difference within the dimensions of the original. raaaahman 1 Link to comment Share on other sites More sharing options...
stupot Posted August 12, 2017 Share Posted August 12, 2017 Phaser doesn't recreate any gfx, it simply takes into account any trimming when calculating the render matrix. Link to comment Share on other sites More sharing options...
Recommended Posts