RelativeX
Introduction
Requirements for use
Example
// Create the animationChain
AnimationChain animationChain = new AnimationChain();
// Create the redball texture that will be used
Texture2D redballTexture = FlatRedBallServices.Load<Texture2D>("redball.bmp");
// Add the 5 frames
float frameLength = .1f; // in seconds
AnimationFrame frame = new AnimationFrame(redballTexture, frameLength);
animationChain.Add(frame); // this is the "whole ball" image
frame = frame.Clone(); // same frame time, same texture
frame.RightCoordinate = .5f;
frame.BottomCoordinate = .5f;
frame.RelativeX = -.5f;
frame.RelativeY = .5f;
animationChain.Add(frame); // top left quadrant
frame = frame.Clone();
frame.LeftCoordinate = .5f;
frame.RightCoordinate = 1;
// top and bottom are still the same - 0 and .5f respectively
frame.RelativeX = .5f;
// RelativeY still .5f like it should be for this frame
animationChain.Add(frame); // top right quadrant
frame = frame.Clone();
// left and right are set ok from the cloned frame
frame.TopCoordinate = .5f;
frame.BottomCoordinate = 1;
// RelativeX still .5f like it shoudl be for this frame
frame.RelativeY = -.5f;
animationChain.Add(frame); // bottom right quadrant
frame = frame.Clone();
// top and bottom are set ok from the cloned frame
frame.LeftCoordinate = 0;
frame.RightCoordinate = .5f;
// RelativeY still -.5f like it shoudl be for this frame
frame.RelativeX = -.5f;
animationChain.Add(frame); // bottom right quadrant
Sprite animatedSprite = SpriteManager.AddSprite(animationChain);
// make sure to have the Sprite use the AnimationFrame's relative values:
animatedSprite.UseAnimationRelativePosition = true;
// Set the pixel size so it gets resized:
// Make sure to use a float!!
animatedSprite.PixelSize = 1.0f / redballTexture.Width;
// Normally this'd be added to the SpriteManager,
// but for this example it's not necessary.
PositionedObject parent = new PositionedObject();
animatedSprite.AttachTo(parent, false);
Last updated
Was this helpful?