public override void Initialize(Section owner) { graphics = (AnimatedGraphicsObject)ContentPackageManager.GetGraphicsResource("SMBCoin"); IsMoving = false; collectSound = new CachedSound(ContentPackageManager.GetAbsoluteFilePath("nsmbwiiCoin")); base.Initialize(owner); }
public override void Initialize(Section owner) { questionGraphics = (AnimatedGraphicsObject)ContentPackageManager.GetGraphicsResource("SMBQuestionBlock"); emptyGraphics = (StaticGraphicsObject)ContentPackageManager.GetGraphicsResource("SMBEmptyBlock"); SetGraphicsObjects(questionGraphics, emptyGraphics); base.Initialize(owner); }
/// <summary> /// Loads a ComplexGraphicsObject. /// </summary> /// <param name="filePath">The file path to the image.</param> /// <param name="config"> /// A DataReader containing the configuration file for this object. /// </param> public void Load(string filePath, DataReader config) { if (!isLoaded) { FilePath = filePath; configFilePath = config.FilePath; if (!(config[0] == "[Complex]")) { throw new FormatException("ComplexGraphicsObject.Load(string, DataReader): Invalid or corrupt configuration file."); } var settings = config.ReadFullSection("[Complex]"); int totalGraphicsObjects; string startingObject; FrameSize = Vector2Extensions.Parse(settings["FrameSize"]); if (!int.TryParse(settings["TotalGraphicsObjects"], out totalGraphicsObjects)) { throw new FormatException(string.Format("ComplexGraphicsObject.Load(string, DataReader): Invalid number of graphics objects specified. Got {0}.", settings["TotalGraphicsObjects"])); } startingObject = settings["StartingObject"]; for (int i = 0; i < totalGraphicsObjects; i++) { string objectHeader = string.Concat("[Object", i, "]"); var objectData = config.ReadFullSection(objectHeader); string name = objectData["Name"]; string type = objectData["Type"]; switch (type) { case "static": StaticGraphicsObject staticObject = new StaticGraphicsObject(); staticObject.Load(objectData, this); graphicsObjects.Add(name, staticObject); break; case "animated": AnimatedGraphicsObject animatedObject = new AnimatedGraphicsObject(); animatedObject.Load(objectData, this); graphicsObjects.Add(name, animatedObject); break; case "animated_runonce": AnimatedGraphicsObject animatedRunOnceObject = new AnimatedGraphicsObject(); animatedRunOnceObject.Load(objectData, this); animatedRunOnceObject.IsRunOnce = true; graphicsObjects.Add(name, animatedRunOnceObject); break; default: break; } } CurrentObjectName = startingObject; isLoaded = true; } }
/// <summary> /// Loads an instance of IGraphicsObject from a given file path. If a /// text file with the same name is in the same folder, that will be /// used to determine what kind of graphics object it is. If no text /// file is present, the object is assumed to be static. Otherwise, the /// type (animated, complex) depends on what the first line of the file is. /// </summary> /// <param name="filePath"> /// The path to the image of the graphics object. /// </param> /// <returns>A loaded IGraphicsObject instance.</returns> public static IGraphicsObject LoadGraphicsObject(string filePath) { if (!loadedObjects.ContainsKey(filePath)) { // We'll assume we have the right path (considering graphics overrides). string fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath); string directoryName = new FileInfo(filePath).DirectoryName; string configPath = Path.Combine(directoryName, string.Concat(fileNameWithoutExt, ".txt")); if (!File.Exists(configPath)) { // No configuration, so the object is probably static var result = new StaticGraphicsObject(); result.Load(filePath); loadedObjects.Add(filePath, result); return result; } else { // A configuration! Let's read it to find out what it is. DataReader config = new DataReader(configPath); if (config[0] == "[Animated]" || config[0] == "[Animated_RunOnce]") { var result = new AnimatedGraphicsObject(); result.Load(filePath, config); loadedObjects.Add(filePath, result); return result; } else if (config[0] == "[Complex]") { var result = new ComplexGraphicsObject(); result.Load(filePath, config); loadedObjects.Add(filePath, result); return result; } } } else { return loadedObjects[filePath].Clone(); } return null; }
/// <summary> /// Loads the content for this object. /// </summary> public override void LoadContent() { this.graphics = (AnimatedGraphicsObject)SMLimitless.Content.ContentPackageManager.GetGraphicsResource("smb3_goomba"); this.graphics.LoadContent(); }
/// <summary> /// Returns a deep copy of this object. The texture is not cloned, but /// everything else is. /// </summary> /// <returns>A deep copy of this object.</returns> public IGraphicsObject Clone() { var clone = new AnimatedGraphicsObject(); clone.filePath = filePath; clone.configFilePath = configFilePath; clone.textures = textures; clone.frameCount = frameCount; clone.frameWidth = frameWidth; clone.AnimationCycleLength = AnimationCycleLength; clone.IsRunOnce = IsRunOnce; clone.isLoaded = isLoaded; clone.isContentLoaded = isContentLoaded; return clone; }