/// <summary> /// Call this to initialize a Behaviour with data supplied in a file. /// </summary> /// <param name="fileName">The file to load from.</param> public override void LoadContent(String fileName) { base.LoadContent(fileName); SpriteRenderDefinition def = GameObjectManager.pInstance.pContentManager.Load<SpriteRenderDefinition>(fileName); mSpriteFileName = def.mSpriteFileName; mTexture = GameObjectManager.pInstance.pContentManager.Load<Texture2D>(mSpriteFileName); if (def.mScreenStretchPercentage != null) { System.Diagnostics.Debug.Assert(def.mAnimationSets == null, "mScreenStretchPercentage is not yet supported for animated sprites."); if (def.mScreenStretchPercentage.X >= 0) { System.Diagnostics.Debug.Assert(def.mScreenStretchPercentage.X >= 0 && def.mScreenStretchPercentage.X <= 1.0f, "Percentage should be expressed as floating point value from 0 - 1"); Single width = CameraManager.pInstance.pScreenViewRect.pDimensions.X; Single initialPercent = mTexture.Width / width; mParentGOH.pScaleX = def.mScreenStretchPercentage.X / initialPercent; } if (def.mScreenStretchPercentage.Y >= 0) { System.Diagnostics.Debug.Assert(def.mScreenStretchPercentage.Y >= 0 && def.mScreenStretchPercentage.Y <= 1.0f, "Percentage should be expressed as floating point value from 0 - 1"); Single height = CameraManager.pInstance.pScreenViewRect.pDimensions.Y; Single initialPercent = mTexture.Height / height; mParentGOH.pScaleY = def.mScreenStretchPercentage.Y / initialPercent; } } mAttachmentPoints = new Dictionary<string, SpriteRenderDefinition.AtachmentPoint>(); if (def.mAttachmentPoints != null) { for (Int32 i = 0; i < def.mAttachmentPoints.Count; i++) { mAttachmentPoints.Add(def.mAttachmentPoints[i].mName, def.mAttachmentPoints[i]); } } mHasShadow = def.mHasShadow; Single colHeight = mTexture.Height; if (def.mFrameHeight > 0) { colHeight = def.mFrameHeight; } if (def.mAnimationSets != null) { mIsAnimated = true; if (def.mFrameHeight == 0) { System.Diagnostics.Debug.Assert(false, "Sprite has animations but a frame height of 0. FrameHeight must be > 0."); def.mFrameHeight = 1; } mFrameHeight = def.mFrameHeight; mAnimations = new List<AnimationSet>(); for (int i = 0; i < def.mAnimationSets.Count; i++) { AnimationSet temp = new AnimationSet(); temp.Reset(); temp.mNumFrames = def.mAnimationSets[i].mNumFrames; temp.mTicksPerFrame = def.mAnimationSets[i].mTicksPerFrame; temp.mName = def.mAnimationSets[i].mName; temp.mStartingFrame = def.mAnimationSets[i].mStartingFrame; temp.mLooping = def.mAnimationSets[i].mLooping; temp.mRemoveGameObjectOnComplete = def.mAnimationSets[i].mRemoveGameObjectOnComplete; temp.mAnimationComplete = false; temp.mFrameOverrides = def.mAnimationSets[i].mFrameOverrides; mAnimations.Add(temp); } } else { mIsAnimated = false; } Reset(); mOnAnimationCompleteMsg = new OnAnimationCompleteMessage(); mGetMotionTrailHistoryMsg = new MotionTrail.GetMotionTrailHistoryMessage(); }
/// <summary> /// Call this to initialize a Behaviour with data supplied in a file. /// </summary> /// <param name="fileName">The file to load from.</param> public override void LoadContent(String fileName) { base.LoadContent(fileName); SpriteRenderDefinition def = GameObjectManager.pInstance.pContentManager.Load <SpriteRenderDefinition>(fileName); mSpriteFileName = def.mSpriteFileName; mTexture = GameObjectManager.pInstance.pContentManager.Load <Texture2D>(mSpriteFileName); mAttachmentPoints = new Dictionary <string, SpriteRenderDefinition.AtachmentPoint>(); if (def.mAttachmentPoints != null) { for (Int32 i = 0; i < def.mAttachmentPoints.Count; i++) { mAttachmentPoints.Add(def.mAttachmentPoints[i].mName, def.mAttachmentPoints[i]); } } mHasShadow = def.mHasShadow; Single colHeight = mTexture.Height; if (def.mFrameHeight > 0) { colHeight = def.mFrameHeight; } if (def.mAnimationSets != null) { mIsAnimated = true; if (def.mFrameHeight == 0) { System.Diagnostics.Debug.Assert(false, "Sprite has animations but a frame height of 0. FrameHeight must be > 0."); def.mFrameHeight = 1; } mFrameHeight = def.mFrameHeight; mAnimations = new List <AnimationSet>(); for (int i = 0; i < def.mAnimationSets.Count; i++) { AnimationSet temp = new AnimationSet(); temp.Reset(); temp.mNumFrames = def.mAnimationSets[i].mNumFrames; temp.mTicksPerFrame = def.mAnimationSets[i].mTicksPerFrame; temp.mName = def.mAnimationSets[i].mName; temp.mStartingFrame = def.mAnimationSets[i].mStartingFrame; temp.mLooping = def.mAnimationSets[i].mLooping; temp.mRemoveGameObjectOnComplete = def.mAnimationSets[i].mRemoveGameObjectOnComplete; temp.mAnimationComplete = false; temp.mFrameOverrides = def.mAnimationSets[i].mFrameOverrides; mAnimations.Add(temp); } } else { mIsAnimated = false; } Reset(); mOnAnimationCompleteMsg = new OnAnimationCompleteMessage(); }