public void SetValuesFrom(SpriteFrame spriteFrame) { Texture = spriteFrame.Texture; SpriteBorderWidth = spriteFrame.SpriteBorderWidth; TextureBorderWidth = spriteFrame.TextureBorderWidth; Alpha = spriteFrame.Alpha; BorderSides = spriteFrame.Borders; }
public GridLayout() { _alpha = 1; _items = new DataGrid<ILayoutable, GridAlignment>(); _backgroundSprite = new SpriteFrame(); _backgroundSprite.PixelSize = 0.5f; _backgroundSprite.Alpha = 0f; }
public void SetValuesFrom(SpriteFrame baseFrame, Text text) { base.SetValuesFrom(baseFrame); TextSpacing = text.Spacing; TextScale = text.Scale; TextRed = text.Red; TextGreen = text.Green; TextBlue = text.Blue; Font = text.Font; }
public SpriteBase(RenderSet render_set, double x, double y, double scalex, double scaley, Texture texture) : base(render_set) { // Size will scale _Texture width and height _Color = Color.White; _Scale.X = scalex; _Scale.Y = scaley; _TileX = 1.0; _TileY = 1.0; _AnimationFrameIndex = 0; _FrameTimer = new Stopwatch(); _AnimationDefault = _AnimationCurrent = new SpriteAnimation(texture, 0); _FrameStatic = _AnimationDefault.Frames[0]; // Position for world objects is handled differently if(!(this is IWorldObject)) Corner = new Vector3d(x, y, 0.0); }
public void Remove(SpriteFrame spriteFrame) { if (spriteFrame.mLayerBelongingTo == this) { if (spriteFrame.mCenter != null) { spriteFrame.mLayerBelongingTo.Remove(spriteFrame.mCenter); } if (spriteFrame.mTop != null) { spriteFrame.mLayerBelongingTo.Remove(spriteFrame.mTop); } if (spriteFrame.mBottom != null) { spriteFrame.mLayerBelongingTo.Remove(spriteFrame.mBottom); } if (spriteFrame.mLeft != null) { spriteFrame.mLayerBelongingTo.Remove(spriteFrame.mLeft); } if (spriteFrame.mRight != null) { spriteFrame.mLayerBelongingTo.Remove(spriteFrame.mRight); } if (spriteFrame.mTopLeft != null) { spriteFrame.mLayerBelongingTo.Remove(spriteFrame.mTopLeft); } if (spriteFrame.mTopRight != null) { spriteFrame.mLayerBelongingTo.Remove(spriteFrame.mTopRight); } if (spriteFrame.mBottomLeft != null) { spriteFrame.mLayerBelongingTo.Remove(spriteFrame.mBottomLeft); } if (spriteFrame.mBottomRight != null) { spriteFrame.mLayerBelongingTo.Remove(spriteFrame.mBottomRight); } } }
private void refreshPositionFrames() { Point pDest = new Point(5, 5); this.maxHeight = 0; for (int i = 0; i < this.sheet.Frames.Count; i++) { SpriteFrame frame = (SpriteFrame)this.sheet.Frames[i]; //Recuperer le point de la derniere frame de la liste si il y en a une if (i >= 1) { SpriteFrame lastFrame = (SpriteFrame)sheet.Frames[i - 1]; //Traiter le point pDest.X = lastFrame.Position.X + lastFrame.Image.Width + 5; pDest.Y = lastFrame.Position.Y; //Si le point en x est superieur a la largeur totale if (pDest.X + frame.Image.Width > 1024) { //Positionner les points une ligne en dessous pDest.X = 5; pDest.Y = lastFrame.Position.Y + this.maxHeight + 5; this.maxHeight = frame.Image.Height; } //Sinon else { //Enregistrer la nouvelle valeur du maxHeight de la ligne du sprite set if (frame.Image.Height > this.maxHeight) { this.maxHeight = frame.Image.Height; } } } //Modifier la position a la frame et l'ajouter a la liste frame.setPosition(pDest); } }
public static void RecordInstructions(InstructionList listToRecordTo, double timeToExecute, List <string> membersToIgnore, SpriteFrame spriteFrame) { foreach (string member in EditorData.CurrentSpriteMembersWatching) { if (membersToIgnore.Contains(member) == false) { Type memberType = InstructionManager.GetTypeForMember(mSpriteFrameType, member); Type genericType = typeof(Instruction <,>).MakeGenericType( mSpriteFrameType, memberType); object value = FlatRedBall.Instructions.Reflection.LateBinder <SpriteFrame> .Instance[spriteFrame, member]; Instruction instruction = Activator.CreateInstance(genericType, spriteFrame, member, value, timeToExecute) as Instruction; listToRecordTo.Add(instruction); } } }
public static void RecordInstructions(InstructionList listToRecordTo, double timeToExecute, List<string> membersToIgnore, SpriteFrame spriteFrame) { foreach (string member in EditorData.CurrentSpriteMembersWatching) { if (membersToIgnore.Contains(member) == false) { Type memberType = InstructionManager.GetTypeForMember(mSpriteFrameType, member); Type genericType = typeof(Instruction<,>).MakeGenericType( mSpriteFrameType, memberType); object value = FlatRedBall.Instructions.Reflection.LateBinder<SpriteFrame>.Instance[spriteFrame, member]; Instruction instruction = Activator.CreateInstance(genericType, spriteFrame, member, value, timeToExecute) as Instruction; listToRecordTo.Add(instruction); } } }
private void reloadFramesBitmap() { if (this.set != null) { CoronaGameProject projectParent = this.mainForm.CurrentProject; for (int i = 0; i < set.Frames.Count; i++) { SpriteFrame obj = set.Frames[i]; if (obj.Image == null) { string sheetDirectory = Path.Combine(projectParent.ProjectPath + "\\Resources\\SpriteSheets", obj.SpriteSheetParent.Name); string frameFileName = Path.Combine(sheetDirectory, obj.SpriteSheetParent.Name + "_frame" + i + ".png"); if (File.Exists(frameFileName)) { obj.Image = Bitmap.FromFile(frameFileName); } } } } }
public void dessineAllFrame(Graphics g, float xRatio, float yRatio, bool applyRatio) { if (this.sheet != null) { if (applyRatio == true) { for (int i = 0; i < this.sheet.Frames.Count; i++) { SpriteFrame frame = (SpriteFrame)this.sheet.Frames[i]; frame.dessineFrame(g, xRatio, yRatio, this.sheet.FramesFactor, ""); } } else { for (int i = 0; i < this.sheet.Frames.Count; i++) { SpriteFrame frame = (SpriteFrame)this.sheet.Frames[i]; frame.dessineFrame(g, xRatio, yRatio); } } } }
protected virtual void Draw(ISpriteBatch spriteBatch, Particle particle) { Vector4 color; GetFadeColor(particle, out color); int frameIndex = 0; if (AnimationMode == ParticleAnimationMode.Animated) { frameIndex = 0; } //frameIndex = (int)(particle.Timer * Animation.FrameTimeSpan) % Animation.Frames.Length; else if (AnimationMode == ParticleAnimationMode.AnimatedWithRandomStartFrame) { frameIndex = 0; } //frameIndex = (int)(particle.Timer * Animation.FrameTimeSpan + particle.Data) % Animation.Frames.Length; else if (AnimationMode == ParticleAnimationMode.AnimatedOverDuration) { frameIndex = (int)((particle.Timer / particle.Duration) * SpriteFrames.Length); } else if (AnimationMode == ParticleAnimationMode.RandomFrame) { frameIndex = particle.Data; } if (frameIndex >= SpriteFrames.Length) { frameIndex = SpriteFrames.Length - 1; } SpriteFrame frame = SpriteFrames[frameIndex]; spriteBatch.Draw(frame.Texture, particle.Position, frame.Rectangle, new Color(color), particle.Rotation, frame.Origin, particle.Scale, SpriteEffects.None, 0.0f); }
public INameable FindByName(string name) { Sprite sprite = mSprites.FindByName(name); { if (sprite != null) { return(sprite); } } foreach (SpriteGrid spriteGrid in mSpriteGrids) { if (spriteGrid.Name == name) { return(spriteGrid); } } SpriteFrame spriteFrame = mSpriteFrames.FindByName(name); { if (spriteFrame != null) { return(spriteFrame); } } Text text = mTexts.FindByName(name); { if (text != null) { return(text); } } return(null); }
public void Draw(ref MapOverlayDrawContext context, ref string text) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) SpriteFrame frame = new SpriteFrame(1, 5); DateTime now = DateTime.Now; foreach (ItemPair<Ping> item in (IEnumerable<ItemPair<Ping>>)_pings) { Ping value = item.Value; double totalSeconds = (now - value.Time).TotalSeconds; int num = (int)(totalSeconds * 10.0); frame.CurrentRow = (byte)(num % (int)frame.RowCount); context.Draw(TextureAssets.MapPing.get_Value(), value.Position, frame, Alignment.Center); if (totalSeconds > 15.0) { _pings.Remove(item.Id); } } }
public void Draw(ref MapOverlayDrawContext context, ref string text) { SpriteFrame frame = new SpriteFrame((byte)1, (byte)5); DateTime now = DateTime.Now; using (IEnumerator <SlotVector <PingMapLayer.Ping> .ItemPair> enumerator = ((IEnumerable <SlotVector <PingMapLayer.Ping> .ItemPair>) this._pings).GetEnumerator()) { while (((IEnumerator)enumerator).MoveNext()) { SlotVector <PingMapLayer.Ping> .ItemPair current = enumerator.Current; PingMapLayer.Ping ping = (PingMapLayer.Ping)current.Value; double totalSeconds = (now - ping.Time).TotalSeconds; int num = (int)(totalSeconds * 10.0); frame.CurrentRow = (byte)((uint)num % (uint)frame.RowCount); context.Draw(TextureAssets.MapPing.get_Value(), ping.Position, frame, Alignment.Center); if (totalSeconds > 15.0) { this._pings.Remove((SlotId)current.Id); } } } }
public DrawResult Draw(Texture2D texture, Vector2 position, Color color, SpriteFrame frame, float scaleIfNotSelected, float scaleIfSelected, Alignment alignment) { position = (position - _mapPosition) * _mapScale + _mapOffset; if (_clippingRect.HasValue && !_clippingRect.Value.Contains(position.ToPoint())) { return(DrawResult.Culled); } Rectangle sourceRectangle = frame.GetSourceRectangle(texture); Vector2 vector = sourceRectangle.Size() * alignment.OffsetMultiplier; Vector2 position2 = position; float num = _drawScale * scaleIfNotSelected; Vector2 vector2 = position - vector * num; bool num2 = new Rectangle((int)vector2.X, (int)vector2.Y, (int)((float)sourceRectangle.Width * num), (int)((float)sourceRectangle.Height * num)).Contains(Main.MouseScreen.ToPoint()); float scale = num; if (num2) { scale = _drawScale * scaleIfSelected; } Main.spriteBatch.Draw(texture, position2, sourceRectangle, color, 0f, vector, scale, SpriteEffects.None, 0f); return(new DrawResult(num2)); }
// * Indlæser diverse animationer STATISK (kaldes af GameController) så de ikke genindlæses i hver instans public static void InitializeGraphics() { Animations = new Dictionary <string, GameSprite>(); string imageRoot = GameController.imageRoot + "/jeep"; // * Flydende bevægelsesanimationer for en jeep List <string> directionDirs = new List <string>(8); directionDirs.Add("up-upright"); directionDirs.Add("upright-right"); directionDirs.Add("right-downright"); directionDirs.Add("downright-down"); directionDirs.Add("down-downleft"); directionDirs.Add("downleft-left"); directionDirs.Add("left-upleft"); directionDirs.Add("upleft-up"); foreach (string direction in directionDirs) { GameSprite moveSprite = new GameSprite(); List <GameSprite> sprites = new List <GameSprite>(); for (int i = 1; i <= 5; i++) { string imagePath = imageRoot + "/" + direction + "/jeep " + i + ".png"; if (File.Exists(imagePath)) { SpriteImage spriteImg = new SpriteImage(imagePath, Color.Transparent); SpriteFrame spriteFrame = new SpriteFrame(spriteImg, 5); moveSprite.AddFrame(spriteFrame); } else { throw new FileNotFoundException("404 on " + imagePath); } } Animations.Add("drive_" + direction, moveSprite); } }
protected override void InternalRead(BinaryReader r) { name = string.Intern(r.ReadStringFromNextOffset()); Description = r.ReadStringFromNextOffset(); Size = r.ReadInt32(); Bold = r.ReadIntBool(); Italic = r.ReadIntBool();; int flag = r.ReadInt32(); FirstChar = (char)(flag & 0xFFFF); CharSet = (flag >> 16) & 0xFF; AntiAlias = (flag >> 24) & 0xFF; LastChar = (char)r.ReadInt32(); var pos = r.BaseStream.Position + 4; r.BaseStream.Position = r.ReadInt32(); Frame = new SpriteFrame(); Frame.Read(r, -1); r.BaseStream.Position = pos; ScaleW = r.ReadSingle(); ScaleH = r.ReadSingle(); Glyphs = ArrayFromOffset <Glyph>(r); }
private SpriteFrameData(SpriteResource resource) { MaxWidth = resource.MaxWidth; MaxHeight = resource.MaxHeight; Frames = new SpriteFrame[resource.FrameCount]; for (int i = 0; i < resource.FrameCount; i++) { Performance.Push("SetData"); WWTexture tex = WWTexture.FromRawData(resource.MaxWidth, resource.MaxHeight, resource.Frames[i].image_data); Performance.Pop(); Frames[i] = new SpriteFrame(); Frames[i].OffsetX = resource.Frames [i].disp_x; Frames[i].OffsetY = resource.Frames [i].disp_y; Frames[i].Width = resource.Frames [i].width; Frames[i].Height = resource.Frames [i].height; Performance.Push("FromDXTexture"); Frames[i].texture = tex; Performance.Pop(); } }
//根据图片名加载其中包含的帧动画信息 public void addSpriteFrameFromFile(string fileName) { string infos = FileUtils.LoadFile(Application.dataPath, fileName); JsonData AnimJson = JsonMapper.ToObject(infos); IDictionary dict = AnimJson["frames"] as IDictionary; foreach (string key in dict.Keys) { SpriteFrame frame = new SpriteFrame(); frame.CreateMesh(AnimJson["frames"][key], AnimJson["meta"]); _spriteFrames.Add(key, frame); } string pictName = (string)AnimJson["meta"]["image"]; if (!_spriteTexture.ContainsKey(pictName)) { int index = pictName.LastIndexOf('.'); string temp = pictName.Substring(0, index); Material pict = (Material)Resources.Load("Material/" + temp); //(Texture)Resources.Load("Material/test1"); _spriteTexture.Add(pictName, pict); } }
private void sheetCmbBx_SelectedIndexChanged(object sender, EventArgs e) { this.framesSheetListView.Items.Clear(); if (this.framesSheetListView.LargeImageList != null) { this.framesSheetListView.LargeImageList.Dispose(); } this.framesSheetListView.LargeImageList = null; this.framesSheetListView.BeginUpdate(); if (this.sheetCmbBx.SelectedItem != null) { CoronaSpriteSheet sheet = (CoronaSpriteSheet)this.sheetCmbBx.SelectedItem; if (sheet != null) { ImageList spriteSetFrames = new ImageList(); spriteSetFrames.ImageSize = new Size(32, 32); this.framesSheetListView.LargeImageList = spriteSetFrames; for (int i = 0; i < sheet.Frames.Count; i++) { SpriteFrame obj = sheet.Frames[i]; if (obj.Image != null) { spriteSetFrames.Images.Add(obj.Image); ListViewItem item = new ListViewItem((i + 1).ToString(), spriteSetFrames.Images.Count - 1); this.framesSheetListView.Items.Add(item); } } } } this.framesSheetListView.EndUpdate(); }
public void UpdateDependencies(double currentTime) { for (int i = 0; i < mSprites.Count; i++) { Sprite sprite = mSprites[i]; sprite.UpdateDependencies(currentTime); } for (int i = 0; i < mSpriteFrames.Count; i++) { SpriteFrame spriteFrame = mSpriteFrames[i]; spriteFrame.UpdateDependencies(currentTime); } for (int i = 0; i < mTexts.Count; i++) { Text text = mTexts[i]; text.UpdateDependencies(currentTime); } }
public MeshAnimation createAnimation(string imageName, int start, int end, float delay, bool isLoop, float xoffset = 0, float yoffset = 0) { List <SpriteFrame> animFrames = new List <SpriteFrame>(); if (start <= 0 && end <= 0) { SpriteFrame frame = SpriteFrameCache.getInstance().getSpriteFrame(imageName + ".png"); if (frame != null) { if (xoffset != 0 || yoffset != 0) { frame.AddOffset(xoffset, yoffset); } animFrames.Add(frame); } } else { for (int i = start; i <= end; i++) { SpriteFrame frame = SpriteFrameCache.getInstance().getSpriteFrame(imageName + i + ".png"); if (frame != null) { if (xoffset != 0 || yoffset != 0) { frame.AddOffset(xoffset, yoffset); } animFrames.Add(frame); } } } MeshAnimation anim = new MeshAnimation(); anim.createWithSpriteFrames(animFrames, delay, isLoop); return(anim); }
public static void DrawMouseSelection(SpriteRender spriteRender, Vector2 mousePosition, Actions mouseAction) { SpriteFrame spriteframe = null; if (mouseAction == Actions.Townhall || mouseAction == Actions.Farm || mouseAction == Actions.Scientist || mouseAction == Actions.Quarry || mouseAction == Actions.Brewery || mouseAction == Actions.Tavern || mouseAction == Actions.Storage) { spriteframe = buildingTileSheet.Sprite(TexturePackerMonoGameDefinitions.buildingAtlas.LargeSelect); } if (mouseAction == Actions.House || mouseAction == Actions.Road || mouseAction == Actions.Woodcutter) { spriteframe = buildingTileSheet.Sprite(TexturePackerMonoGameDefinitions.buildingAtlas.SmallSelect); } foreach (Tile tile in tileMap) { if (tile != null && tile.Rect.Contains(mousePosition)) { if (spriteframe != null) { spriteRender.Draw(spriteframe, new Vector2(tile.Rect.X, tile.Rect.Y)); } } } }
private void init() { Crystals = new List <Crystal>(); OuterCrystals = new List <Crystal>(); Crystal inner = new Crystal("crystal_center", GroundPos, crystalHealth, this); SpriteFrame animation = GetAnimation(); animation.Height = inner.GetAnimation().Height; animation.Width = inner.GetAnimation().Width; Crystals.Add(inner); inner.HealthChanged += new HealthChangedHandler(updateHealth); for (int x = 0; x < numOuterCrystals; x++) { double angle = 2 * Math.PI * x / numOuterCrystals - Math.PI / 2; Vector2 offset = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * radius; Crystal outer = new Crystal("crystal_" + x, GroundPos + offset, crystalHealth, this); Crystals.Add(outer); OuterCrystals.Add(outer); outer.HealthChanged += new HealthChangedHandler(updateHealth); outer.Direction = -offset; } }
// * Indlæser diverse animationer STATISK (kaldes af GameController) så de ikke genindlæses i hver instans public static void InitializeGraphics() { Animations = new Dictionary <string, GameSprite>(); string barracksRoot = GameController.imageRoot + "/barracks"; GameSprite constructSprite = new GameSprite(); constructSprite.RepeatCount = 0; for (int i = 0; i <= 12; i++) { string imagePath = barracksRoot + "/make/barrmake " + i + ".png"; if (File.Exists(imagePath)) { SpriteImage spriteImg = new SpriteImage(imagePath, Color.Transparent); SpriteFrame spriteFrame = new SpriteFrame(spriteImg, 5); constructSprite.AddFrame(spriteFrame); } else { throw new FileNotFoundException("404"); } } Animations.Add("make", constructSprite); }
public void clean() { for (int i = 0; i < this.ListObjects.Count; i++) { DisplayObject obj = this.ListObjects[i]; if (obj.Image != null) { obj.Image.Dispose(); obj.Image = null; } } for (int i = 0; i < this.SpriteSets.Count; i++) { CoronaSpriteSet set = SpriteSets[i]; for (int j = 0; j < set.Frames.Count; j++) { SpriteFrame frame = set.Frames[j]; if (frame.Image != null) { frame.Image.Dispose(); frame.Image = null; } } } for (int i = 0; i < this.SpriteSheets.Count; i++) { CoronaSpriteSheet sheet = this.SpriteSheets[i]; if (sheet.ImageSpriteSheet != null) { sheet.ImageSpriteSheet.Dispose(); sheet.ImageSpriteSheet = null; } } }
public void RemoveFromManagers(bool clearThis) { if (!clearThis) { MakeOneWay(); } for (int i = mSprites.Count - 1; i > -1; i--) { Sprite sprite = mSprites[i]; PositionedObject oldParent = sprite.Parent; SpriteManager.RemoveSprite(sprite); if (!clearThis && oldParent != null) { sprite.AttachTo(oldParent, false); } } for (int i = mSpriteGrids.Count - 1; i > -1; i--) { //SpriteGrids don't get attached, so there is no code to preserve Parent and re-attach SpriteGrid spriteGrid = mSpriteGrids[i]; spriteGrid.Destroy(); } for (int i = mSpriteFrames.Count - 1; i > -1; i--) { SpriteFrame spriteFrame = mSpriteFrames[i]; PositionedObject oldParent = spriteFrame.Parent; SpriteManager.RemoveSpriteFrame(spriteFrame); if (!clearThis && oldParent != null) { spriteFrame.AttachTo(oldParent, false); } } for (int i = mTexts.Count - 1; i > -1; i--) { Text text = mTexts[i]; PositionedObject oldParent = text.Parent; TextManager.RemoveText(text); if (!clearThis && oldParent != null) { text.AttachTo(oldParent, false); } } if (clearThis) { Clear(); } else { MakeTwoWay(); } }
/// <summary> /// 利用动画帧信息,构造Mesh /// </summary> /// <param name="frame"></param> /// <returns></returns> public void GetMesh(SpriteFrame frame) { this.mesh.vertices = frame.vertices; this.mesh.triangles = frame.triangles; this.mesh.uv = frame.uv; }
public void ConvertToSpriteFrameClick(Window callingWindow) { if (SpriteEditorSettings.EditingSprites && GameData.EditorLogic.CurrentSprites.Count != 0) { SpriteFrame newSpriteFrame = new SpriteFrame( GameData.EditorLogic.CurrentSprites[0].Texture, SpriteFrame.BorderSides.All); SpriteManager.AddSpriteFrame(newSpriteFrame); newSpriteFrame.X = GameData.EditorLogic.CurrentSprites[0].X; newSpriteFrame.Y = GameData.EditorLogic.CurrentSprites[0].Y; newSpriteFrame.Z = GameData.EditorLogic.CurrentSprites[0].Z; newSpriteFrame.ScaleX = GameData.EditorLogic.CurrentSprites[0].ScaleX; newSpriteFrame.ScaleY = GameData.EditorLogic.CurrentSprites[0].ScaleY; newSpriteFrame.RotationX = GameData.EditorLogic.CurrentSprites[0].RotationX; newSpriteFrame.RotationY = GameData.EditorLogic.CurrentSprites[0].RotationY; newSpriteFrame.RotationZ = GameData.EditorLogic.CurrentSprites[0].RotationZ; newSpriteFrame.Alpha = GameData.EditorLogic.CurrentSprites[0].Alpha; newSpriteFrame.Red = GameData.EditorLogic.CurrentSprites[0].Red; newSpriteFrame.Green = GameData.EditorLogic.CurrentSprites[0].Green; newSpriteFrame.Blue = GameData.EditorLogic.CurrentSprites[0].Blue; newSpriteFrame.Name = GameData.EditorLogic.CurrentSprites[0].Name; GameData.DeleteCurrentSprites(); SpriteEditorSettings.EditingSpriteFrames = true; // add code for undoing this. GameData.Scene.SpriteFrames.Add(newSpriteFrame); } else if ( SpriteEditorSettings.EditingSpriteFrames && GameData.EditorLogic.CurrentSpriteFrames.Count != 0) { /* * Need to set the invisible parent Sprite's texture because it will be used * to set the new EditorSprite's texture. We could manually do this, but it's * cleaner to just call SetFromRegularSprite and have that handle everything. */ GameData.EditorLogic.CurrentSpriteFrames[0].CenterSprite.Texture = GameData.EditorLogic.CurrentSpriteFrames[0].Texture; EditorSprite es = new EditorSprite(); es.SetFromRegularSprite(GameData.EditorLogic.CurrentSpriteFrames[0].CenterSprite); es.Name = GameData.EditorLogic.CurrentSpriteFrames[0].Name; es.ScaleX = GameData.EditorLogic.CurrentSpriteFrames[0].ScaleX; es.ScaleY = GameData.EditorLogic.CurrentSpriteFrames[0].ScaleY; GameData.DeleteSpriteFrame(GameData.EditorLogic.CurrentSpriteFrames[0], true); SpriteEditorSettings.EditingSprites = true; SpriteManager.AddSprite(es); GameData.SetStoredAddToSE(es, GameData.EditorProperties.PixelSize); //GameData.ihMan.AddInstruction(new seInstructions.CreateSprite(es)); GuiData.ToolsWindow.paintButton.Unpress(); GameData.Cursor.ClickSprite(es); } }
void CustomInitialize() { if (!SpriteManager.OrderedSprites.Contains(this.SpriteObject)) { throw new Exception("The Sprite object is not being added to the managers but it should be."); } if (ShapeCollectionFile.AxisAlignedRectangles.Contains(this.InvisibleRectangle) == false) { throw new Exception("The ShapeCollection does not contain the rectangle - possibly because it's being improperly cloned"); } if (this.InvisibleRectangle.Visible) { throw new Exception("Rectangles that come from files that have their Visible set to false are still visible"); } this.SceneInstanceSetFromFileAtRuntime = SceneFile; SpriteWithInstructions.Set("X").To(4.0f).After(.1f); SpriteWithInstructions.Set("Position").To(Vector3.One).After(.25); TestingTextInterpolationInstance.CurrentTextValuesState = InterpolationEntity.TextValues.Transparent; TestingTextInterpolationInstance.InterpolateToState(InterpolationEntity.TextValues.Opaque, 1); this.DynamicallyAssignedSceneSourceFile = SceneOption1; if(this.DynamicallyAssignedSceneSourceFile != SceneOption1) { throw new Exception("Setting the source file does not do anything"); } // The CameraModifyingEntity sets the Z. This should persist if (SpriteManager.Camera.Z != CameraModifyingEntity.CameraZToSet) { throw new Exception("The CameraModifyingEntity should modify the Camera's Z, but it's not!"); } ManuallyUpdatedEntityInstance.ConvertToManuallyUpdated(); // let's make sure that this thing actually has a collision function: bool didCollide = CollisionEntityInstance.CollideAgainst(CollisionEntityInstance2); // And that it worked if (!didCollide) { throw new Exception("ICollidable entities aren't properly detecting collisions"); } CollisionEntityInstance.CollideAgainstMove(CollisionEntityInstance2, 1, 0); CollisionEntityInstance.CollideAgainstBounce(CollisionEntityInstance2, 1, 0, 1); if (this.LayerInstance.Sprites.Contains(SpriteFrameInheritingEntityInstanceLayered.CenterSprite) == false) { throw new Exception("SpriteFrame-inheriting entities do not get put on Layers properly"); } if (this.LayerInstance.Sprites.Contains(this.SpriteInheritingEntityInstanceLayered) == false) { throw new Exception("SpriteFrame-inheriting entities do not get put on Layers properly"); } if (this.LayerInstance.Texts.Contains(TextInheritingEntityInstanceLayered) == false) { throw new Exception("SpriteFrame-inheriting entities do not get put on Layers properly"); } SpriteFrameInheritingEntityInstanceLayered.MoveToLayer(LayerInstance2); SpriteInheritingEntityInstanceLayered.MoveToLayer(LayerInstance2); TextInheritingEntityInstanceLayered.MoveToLayer(LayerInstance2); // Make sure that entities with objects that are not instantiated an be moved to layers: NoInstantiationForMoveToLayer.MoveToLayer(LayerInstance2); if (this.LayerInstance2.Sprites.Contains(SpriteFrameInheritingEntityInstanceLayered.CenterSprite) == false) { throw new Exception("SpriteFrame-inheriting entities aren't moved to other layers properly"); } if (this.LayerInstance2.Sprites.Contains(this.SpriteInheritingEntityInstanceLayered) == false) { throw new Exception("SpriteFrame-inheriting entities aren't moved to other layers properly"); } if (this.LayerInstance2.Texts.Contains(TextInheritingEntityInstanceLayered) == false) { throw new Exception("SpriteFrame-inheriting entities aren't moved to other layers properly"); } SetToInvisibleTestTextVisibility.Visible = false; if (SetToInvisibleTestTextVisibility.TextInstance.Visible) { throw new Exception("Setting an Entity that inherits from a FRB type to Invisible should set its IsContainer NOS to invisible too"); } SpriteManager.AddToLayer(UnlayeredSpriteFrameNotAllSidesMoveToLayer, this.LayerInstance); // Now let's test SpriteFrames that we instantiate and add to layer right away layeredSpriteFrameInstantiatedInCode = new SpriteFrame(Aura, SpriteFrame.BorderSides.Left); SpriteManager.AddToLayer(layeredSpriteFrameInstantiatedInCode, LayerInstance); unlayeredSpriteFrameInstantiatedInCode = new SpriteFrame(Aura, SpriteFrame.BorderSides.Left); SpriteManager.AddToLayer(unlayeredSpriteFrameInstantiatedInCode, null); // Make sure AARects have the "all" reposition direction initially: var rectangle = new AxisAlignedRectangle(); if(rectangle.RepositionDirections != RepositionDirections.All) { throw new Exception("AARects should have the All reposition direction, but they don't."); } managedInvisiblTestSprite1 = new Sprite(); // January 25, 2015 // A FRB user found a // crash bug occurring // if adding a Sprite as // a ManagedInvisibleSprite, // then later adding it to a Layer. // I was able to reproduce it in the // test project. Before the bug was fixed // the engine would crash internall. SpriteManager.AddManagedInvisibleSprite(managedInvisiblTestSprite1); SpriteManager.AddToLayer(managedInvisiblTestSprite1, this.LayerInstance); // The IDrawableBatchEntity depends on draw calls happening, and we // want to make sure that they don't get skipped on platforms like iOS // where performance may be lower than PC. We're going to force draw calls // to happen after every activity. FlatRedBallServices.Game.IsFixedTimeStep = false; }
void CustomInitialize() { if (!SpriteManager.OrderedSprites.Contains(this.SpriteObject)) { throw new Exception("The Sprite object is not being added to the managers but it should be."); } if (ShapeCollectionFile.AxisAlignedRectangles.Contains(this.InvisibleRectangle) == false) { throw new Exception("The ShapeCollection does not contain the rectangle - possibly because it's being improperly cloned"); } if (this.InvisibleRectangle.Visible) { throw new Exception("Rectangles that come from files that have their Visible set to false are still visible"); } this.SceneInstanceSetFromFileAtRuntime = SceneFile; SpriteWithInstructions.Set("X").To(4.0f).After(.1f); SpriteWithInstructions.Set("Position").To(Vector3.One).After(.25); TestingTextInterpolationInstance.CurrentTextValuesState = InterpolationEntity.TextValues.Transparent; TestingTextInterpolationInstance.InterpolateToState(InterpolationEntity.TextValues.Opaque, 1); this.DynamicallyAssignedSceneSourceFile = SceneOption1; if (this.DynamicallyAssignedSceneSourceFile != SceneOption1) { throw new Exception("Setting the source file does not do anything"); } // The CameraModifyingEntity sets the Z. This should persist if (SpriteManager.Camera.Z != CameraModifyingEntity.CameraZToSet) { throw new Exception("The CameraModifyingEntity should modify the Camera's Z, but it's not!"); } ManuallyUpdatedEntityInstance.ConvertToManuallyUpdated(); // let's make sure that this thing actually has a collision function: bool didCollide = CollisionEntityInstance.CollideAgainst(CollisionEntityInstance2); // And that it worked if (!didCollide) { throw new Exception("ICollidable entities aren't properly detecting collisions"); } CollisionEntityInstance.CollideAgainstMove(CollisionEntityInstance2, 1, 0); CollisionEntityInstance.CollideAgainstBounce(CollisionEntityInstance2, 1, 0, 1); if (this.LayerInstance.Sprites.Contains(SpriteFrameInheritingEntityInstanceLayered.CenterSprite) == false) { throw new Exception("SpriteFrame-inheriting entities do not get put on Layers properly"); } if (this.LayerInstance.Sprites.Contains(this.SpriteInheritingEntityInstanceLayered) == false) { throw new Exception("SpriteFrame-inheriting entities do not get put on Layers properly"); } if (this.LayerInstance.Texts.Contains(TextInheritingEntityInstanceLayered) == false) { throw new Exception("SpriteFrame-inheriting entities do not get put on Layers properly"); } SpriteFrameInheritingEntityInstanceLayered.MoveToLayer(LayerInstance2); SpriteInheritingEntityInstanceLayered.MoveToLayer(LayerInstance2); TextInheritingEntityInstanceLayered.MoveToLayer(LayerInstance2); // Make sure that entities with objects that are not instantiated an be moved to layers: NoInstantiationForMoveToLayer.MoveToLayer(LayerInstance2); if (this.LayerInstance2.Sprites.Contains(SpriteFrameInheritingEntityInstanceLayered.CenterSprite) == false) { throw new Exception("SpriteFrame-inheriting entities aren't moved to other layers properly"); } if (this.LayerInstance2.Sprites.Contains(this.SpriteInheritingEntityInstanceLayered) == false) { throw new Exception("SpriteFrame-inheriting entities aren't moved to other layers properly"); } if (this.LayerInstance2.Texts.Contains(TextInheritingEntityInstanceLayered) == false) { throw new Exception("SpriteFrame-inheriting entities aren't moved to other layers properly"); } SetToInvisibleTestTextVisibility.Visible = false; if (SetToInvisibleTestTextVisibility.TextInstance.Visible) { throw new Exception("Setting an Entity that inherits from a FRB type to Invisible should set its IsContainer NOS to invisible too"); } SpriteManager.AddToLayer(UnlayeredSpriteFrameNotAllSidesMoveToLayer, this.LayerInstance); // Now let's test SpriteFrames that we instantiate and add to layer right away layeredSpriteFrameInstantiatedInCode = new SpriteFrame(Aura, SpriteFrame.BorderSides.Left); SpriteManager.AddToLayer(layeredSpriteFrameInstantiatedInCode, LayerInstance); unlayeredSpriteFrameInstantiatedInCode = new SpriteFrame(Aura, SpriteFrame.BorderSides.Left); SpriteManager.AddToLayer(unlayeredSpriteFrameInstantiatedInCode, null); // Make sure AARects have the "all" reposition direction initially: var rectangle = new AxisAlignedRectangle(); if (rectangle.RepositionDirections != RepositionDirections.All) { throw new Exception("AARects should have the All reposition direction, but they don't."); } managedInvisiblTestSprite1 = new Sprite(); // January 25, 2015 // A FRB user found a // crash bug occurring // if adding a Sprite as // a ManagedInvisibleSprite, // then later adding it to a Layer. // I was able to reproduce it in the // test project. Before the bug was fixed // the engine would crash internall. SpriteManager.AddManagedInvisibleSprite(managedInvisiblTestSprite1); SpriteManager.AddToLayer(managedInvisiblTestSprite1, this.LayerInstance); // The IDrawableBatchEntity depends on draw calls happening, and we // want to make sure that they don't get skipped on platforms like iOS // where performance may be lower than PC. We're going to force draw calls // to happen after every activity. FlatRedBallServices.Game.IsFixedTimeStep = false; }
protected internal void UpdateSeparators() { if (mSeparatorSkin == null) { return; } int requiredSeparatorCount = 0; if (mSeparatorSkin != null && mItems.Count != 0) { requiredSeparatorCount = System.Math.Min(mItems.Count, NumberOfVisibleElements) + mSeparatorSkin.ExtraSeparators; } while (mSeparators.Count < requiredSeparatorCount) { // There aren't enough separators, so let's add them SpriteFrame newSeparator = new SpriteFrame( mSeparatorSkin.Texture, mSeparatorSkin.BorderSides); SpriteManager.AddSpriteFrame(newSeparator); if (SpriteFrame.LayerBelongingTo != null) { SpriteManager.AddToLayer(newSeparator, SpriteFrame.LayerBelongingTo); } int indexOfNewSeparator = mSeparators.Count; mSeparators.Add(newSeparator); newSeparator.AttachTo(SpriteFrame, false); newSeparator.RelativeZ = -MathFunctions.ForwardVector3.Z * SeparatorZOffset; } while (mSeparators.Count > requiredSeparatorCount) { // There are too many separators, so remove some SpriteManager.RemoveSpriteFrame(mSeparators.Last); } UpdateSeparatorProperties(); }
public SpriteAnimation(Texture texture, int frame_time, bool looping, bool ping_pong, params int[] region_incices) : this(looping, ping_pong) { // TODO: make this better (supply color and frame time) if(region_incices == null || region_incices.Length < 1) { _Frames = new SpriteFrame[1]; _Frames[0] = new SpriteFrame(texture, 0, Color.White, frame_time); } else { _Frames = new SpriteFrame[region_incices.Length]; for(int i = 0; i < region_incices.Length; i++) _Frames[i] = new SpriteFrame(texture, region_incices[i], Color.White, frame_time); } }
public CreateSpriteFrame(SpriteFrame referenceSprite) { this.referenceObject = referenceSprite; }
public void AddFrame(SpriteFrame frame) { Frames.Add(frame); }
public Scene Clone() { Scene scene = new Scene(); #region Create the Sprites for (int i = 0; i < mSprites.Count; i++) { Sprite sprite = mSprites[i]; scene.mSprites.Add(sprite.Clone()); } for (int i = 0; i < mSprites.Count; i++) { Sprite thisSprite = mSprites[i]; if (thisSprite.Parent != null) { Sprite otherSprite = scene.mSprites[i]; otherSprite.AttachTo( scene.mSprites.FindByName(thisSprite.Parent.Name), false); } } #endregion #region Create the SpriteGrids for (int i = 0; i < mSpriteGrids.Count; i++) { SpriteGrid spriteGrid = mSpriteGrids[i]; scene.mSpriteGrids.Add(spriteGrid.Clone()); } #endregion #region Create and Attach the SpriteFrames for (int i = 0; i < mSpriteFrames.Count; i++) { SpriteFrame spriteFrame = mSpriteFrames[i]; scene.mSpriteFrames.Add(spriteFrame.Clone()); } #endregion #region Create and attach the Texts for (int i = 0; i < mTexts.Count; i++) { Text text = mTexts[i]; scene.mTexts.Add(text.Clone()); } for (int i = 0; i < mTexts.Count; i++) { Text thisText = mTexts[i]; if (thisText.Parent != null) { Text otherText = scene.mTexts[i]; otherText.AttachTo( scene.mTexts.FindByName(thisText.Parent.Name), false); } } #endregion scene.Name = Name; return(scene); }
private object CreateFlatRedBallTypeNos(NamedObjectSave namedObjectSave, PositionedObjectList <ElementRuntime> listToPopulate, Layer layerToPutOn) { object returnObject = null; ElementRuntime newElementRuntime = null; switch (namedObjectSave.SourceClassType) { case "Layer": case "FlatRedBall.Graphics.Layer": returnObject = CreateLayerObject(namedObjectSave, returnObject); break; case "AxisAlignedRectangle": case "FlatRedBall.Math.Geometry.AxisAlignedRectangle": AxisAlignedRectangle aaRectangle = ShapeManager.AddAxisAlignedRectangle(); if (layerToPutOn != null) { ShapeManager.AddToLayer(aaRectangle, layerToPutOn); } aaRectangle.Name = namedObjectSave.InstanceName; returnObject = aaRectangle; break; case "Camera": case "FlatRedBall.Camera": if (namedObjectSave.IsNewCamera) { returnObject = null; } else { returnObject = SpriteManager.Camera; } break; case "Circle": case "FlatRedBall.Math.Geometry.Circle": Circle circle = ShapeManager.AddCircle(); circle.Name = namedObjectSave.InstanceName; if (layerToPutOn != null) { ShapeManager.AddToLayer(circle, layerToPutOn); } returnObject = circle; break; case "Polygon": case "FlatRedBall.Math.Geometry.Polygon": Polygon polygon = ShapeManager.AddPolygon(); polygon.Name = namedObjectSave.InstanceName; if (layerToPutOn != null) { ShapeManager.AddToLayer(polygon, layerToPutOn); } returnObject = polygon; break; case "Sprite": case "FlatRedBall.Sprite": Sprite sprite = SpriteManager.AddSprite((Texture2D)null); if (layerToPutOn != null) { SpriteManager.AddToLayer(sprite, layerToPutOn); } sprite.Name = namedObjectSave.InstanceName; returnObject = sprite; break; case "SpriteFrame": case "FlatRedBall.ManagedSpriteGroups.SpriteFrame": SpriteFrame spriteFrame = SpriteManager.AddSpriteFrame(null, SpriteFrame.BorderSides.All); if (layerToPutOn != null) { SpriteManager.AddToLayer(spriteFrame, layerToPutOn); } spriteFrame.Name = namedObjectSave.InstanceName; returnObject = spriteFrame; break; case "Text": case "FlatRedBall.Graphics.Text": Text text = TextManager.AddText(""); if (layerToPutOn != null) { TextManager.AddToLayer(text, layerToPutOn); text.SetPixelPerfectScale(layerToPutOn); } text.Name = namedObjectSave.InstanceName; returnObject = text; break; case "Scene": case "FlatRedBall.Scene": Scene scene = new Scene(); scene.Name = namedObjectSave.InstanceName; returnObject = scene; break; default: // do nothing - need to add more types? break; } if (returnObject != null) { if (returnObject is IScalable) { newElementRuntime = new ScalableElementRuntime(null, layerToPutOn, namedObjectSave, CreationOptions.OnBeforeVariableSet, CreationOptions.OnAfterVariableSet); } else { newElementRuntime = new ElementRuntime(null, layerToPutOn, namedObjectSave, CreationOptions.OnBeforeVariableSet, CreationOptions.OnAfterVariableSet); } newElementRuntime.mDirectObjectReference = returnObject; if (returnObject is Camera && !namedObjectSave.IsNewCamera) { SpriteManager.Camera.AttachTo(newElementRuntime, false); SpriteManager.Camera.RelativePosition = Vector3.Zero; newElementRuntime.Z = 40; newElementRuntime.Name = namedObjectSave.InstanceName; } else if (returnObject is FlatRedBall.Utilities.INameable) { newElementRuntime.Name = ((FlatRedBall.Utilities.INameable)returnObject).Name; } else { object nameValueAsObject; if (LateBinder.TryGetValueStatic(returnObject, "Name", out nameValueAsObject)) { newElementRuntime.Name = (string)nameValueAsObject; } } listToPopulate.Add(newElementRuntime); } return(returnObject); }
public void ProcessSPR2(string Path) { List<IffChunk> SPR2s = new List<IffChunk>(); foreach (IffChunk Chunk in m_Chunks) { if (Chunk.Type == "SPR2") SPR2s.Add(Chunk); } foreach (IffChunk Chunk in SPR2s) { BinaryReader ChunkReader = new BinaryReader(new MemoryStream(Chunk.Data)); SPR2 Spr = new SPR2(); Spr.Version1 = ChunkReader.ReadInt16(); if (Spr.Version1 == 0) Spr.Version2 = ReadBigShort(ChunkReader); else Spr.Version2 = ChunkReader.ReadInt16(); Spr.FrameCount = ChunkReader.ReadInt32(); MessageBox.Show("Framecount: " + Spr.FrameCount); Spr.PaletteID = ChunkReader.ReadInt32(); Spr.OffsetTable = new int[Spr.FrameCount]; for (int i = 0; i < Spr.FrameCount; i++ ) Spr.OffsetTable[i] = ChunkReader.ReadInt32(); for (int i = 0; i < Spr.FrameCount; i++) { SpriteFrame Frame = new SpriteFrame(); Frame.Width = ChunkReader.ReadInt16(); Frame.Height = ChunkReader.ReadInt16(); Frame.Flags = ChunkReader.ReadInt16(); Frame.Unknown = ChunkReader.ReadInt16(); Frame.PaletteID = ChunkReader.ReadInt16(); Frame.TransparentPixel = ChunkReader.ReadInt16(); Frame.XPos = ChunkReader.ReadInt16(); Frame.YPos = ChunkReader.ReadInt16(); BinaryWriter SpriteWriter = new BinaryWriter(Frame.SpriteData); for (int l = 0; l <= Frame.Height; l++) { SpriteWriter.Write(ChunkReader.ReadBytes(2)); SpriteWriter.Write(ChunkReader.ReadBytes(Frame.Width)); } SpriteWriter.Flush(); //SpriteWriter.Close(); Spr.AddFrame(Frame); //Each SPR2 resource contains a reference to a PALT chunk/resource. Spr.Pal = new Palette(); IffChunk TmpChunk = new IffChunk(); foreach (IffChunk C in m_Chunks) { if (C.TypeNum == Spr.PaletteID) { //Guess what? The typenumber of each chunk is //NOT unique, so you have to check on type as //well! if (C.Type == "PALT") { TmpChunk = C; break; } } } BinaryReader PaltReader = new BinaryReader(new MemoryStream(TmpChunk.Data)); Spr.Pal.AlwaysOne = PaltReader.ReadInt32(); Spr.Pal.Always256 = PaltReader.ReadInt32(); PaltReader.ReadBytes(8); //The PALT header has 8 additional bytes of 0. Spr.Pal.RGBTable = new Palette.RGB[Spr.Pal.Always256]; for (int l = 0; l < Spr.Pal.Always256; l++) { Spr.Pal.RGBTable[l] = new Palette.RGB(); Spr.Pal.RGBTable[l].Red = PaltReader.ReadByte(); Spr.Pal.RGBTable[l].Green = PaltReader.ReadByte(); Spr.Pal.RGBTable[l].Blue = PaltReader.ReadByte(); } PaltReader.Close(); } for (int i = 0; i < Spr.FrameCount; i++) { SpriteFrame Frame = Spr.GetFrame(i); BinaryReader SpriteReader = new BinaryReader(new MemoryStream(Frame.SpriteData.ToArray())); int X = 0, Y = 0; bool Stop = false; Bitmap BM = new Bitmap(Frame.Width, Frame.Height); Color Transparent = Color.FromArgb(Spr.Pal.RGBTable[Frame.TransparentPixel].Red, Spr.Pal.RGBTable[Frame.TransparentPixel].Green, Spr.Pal.RGBTable[Frame.TransparentPixel].Blue); Graphics Gfx = Graphics.FromImage(BM); while (SpriteReader.BaseStream.Position < (SpriteReader.BaseStream.Length - 1) && !Stop) { byte Opcode = SpriteReader.ReadByte(); byte Data = SpriteReader.ReadByte(); switch (Opcode) { case 1: //Transparent pixels. for (int Dat = 0; Dat < Data; Dat++) { if(X < Frame.Width) BM.SetPixel(X, Y, Transparent); X++; } break; case 2: byte Col = SpriteReader.ReadByte(); for (int Dat = 0; Dat < Data; Dat++) { if (X < Frame.Width) BM.SetPixel(X, Y, GetColorFromPalette(Col, Spr)); X++; } break; case 3: //Pixels. byte Pixel = SpriteReader.ReadByte(); for (int Dat = 0; Dat < Data; Dat++) { if (X < Frame.Width && Y < Frame.Height) BM.SetPixel(X, Y, GetColorFromPalette(Pixel, Spr)); X++; } break; case 4: //New line. for (; X < BM.Width; X++) BM.SetPixel(X, Y, Transparent); Y++; //Next line. X = 0; break; case 5: //End of sprite. Stop = true; break; case 9: //Transparent rows. Gfx.FillRectangle(Brushes.Transparent, new Rectangle(0, Y, BM.Width, (Y + (Data - 1)))); X = 0; Y = Y + (Data - 1); break; } } Random Rnd = new Random(DateTime.Now.Millisecond); BM.Save(Path + "\\" + i.ToString() + Rnd.Next() + ".png", System.Drawing.Imaging.ImageFormat.Png); } } }
public void ProcessDGRPs() { List<IffChunk> DGRPs = new List<IffChunk>(); foreach (IffChunk Chunk in m_Chunks) { if (Chunk.Type == "DGRP") DGRPs.Add(Chunk); } foreach (IffChunk Chunk in DGRPs) { BinaryReader ChunkReader = new BinaryReader(new MemoryStream(Chunk.Data)); DrawGroup DGRP = new DrawGroup(); DGRP.Version = ChunkReader.ReadInt16(); if (DGRP.Version == 20000 || DGRP.Version == 20001) { DGRP.Count = Convert.ToInt32(ChunkReader.ReadBytes(2)); for (int i = 0; i < DGRP.Count; i++) { DGRPImg Img = new DGRPImg(); Img.SpriteInfoCount = Convert.ToInt32(ChunkReader.ReadBytes(2)); Img.DirFlags = ChunkReader.ReadByte(); Img.ZoomFactor = ChunkReader.ReadByte(); for (int j = 0; j < Img.SpriteInfoCount; j++) { SpriteInfo SInfo = new SpriteInfo(); SInfo.Tag = ChunkReader.ReadInt16(); SInfo.SprID = Convert.ToInt32(ChunkReader.ReadBytes(2)); SInfo.SprFrame = Convert.ToInt32(ChunkReader.ReadBytes(2)); SInfo.Flags = Convert.ToInt32(ChunkReader.ReadBytes(2)); SInfo.PixelX = Convert.ToInt32(ChunkReader.ReadBytes(2)); SInfo.PixelY = Convert.ToInt32(ChunkReader.ReadBytes(2)); if (DGRP.Version == 20001) SInfo.ZOffset = ChunkReader.ReadInt32(); SInfo.Sprite = new SPR2(); IffChunk TmpChunk = new IffChunk(); foreach (IffChunk C in m_Chunks) { if (C.TypeNum == SInfo.SprID) { if (C.Type == "SPR2") { TmpChunk = C; break; } } } BinaryReader SpriteReader = new BinaryReader(new MemoryStream(TmpChunk.Data)); SInfo.Sprite.Version1 = SpriteReader.ReadInt16(); if (SInfo.Sprite.Version1 == 0) SInfo.Sprite.Version2 = ReadBigShort(SpriteReader); else SInfo.Sprite.Version2 = SpriteReader.ReadInt16(); SInfo.Sprite.FrameCount = SpriteReader.ReadInt32(); SInfo.Sprite.PaletteID = SpriteReader.ReadInt32(); SInfo.Sprite.OffsetTable = new int[SInfo.Sprite.FrameCount]; for (int k = 0; k < SInfo.Sprite.FrameCount; k++) SInfo.Sprite.OffsetTable[k] = SpriteReader.ReadInt32(); for (int k = 0; k < SInfo.Sprite.FrameCount; k++) { SpriteFrame Frame = new SpriteFrame(); Frame.Width = SpriteReader.ReadInt16(); Frame.Height = SpriteReader.ReadInt16(); Frame.Flags = SpriteReader.ReadInt16(); Frame.Unknown = SpriteReader.ReadInt16(); Frame.PaletteID = SpriteReader.ReadInt16(); Frame.TransparentPixel = SpriteReader.ReadInt16(); Frame.XPos = SpriteReader.ReadInt16(); Frame.YPos = SpriteReader.ReadInt16(); BinaryWriter SpriteWriter = new BinaryWriter(Frame.SpriteData); for (int l = 0; l <= Frame.Height; l++) { SpriteWriter.Write(SpriteReader.ReadBytes(2)); SpriteWriter.Write(SpriteReader.ReadBytes(Frame.Width)); } SInfo.Sprite.AddFrame(Frame); SpriteWriter.Close(); } SpriteReader.Close(); //Each SPR2 resource contains a reference to a PALT chunk/resource. SInfo.Sprite.Pal = new Palette(); foreach (IffChunk C in m_Chunks) { if (C.TypeNum == SInfo.Sprite.PaletteID) { //Guess what? The typenumber of each chunk is //NOT unique, so you have to check on type as //well! if (C.Type == "PALT") { TmpChunk = C; break; } } } BinaryReader PaltReader = new BinaryReader(new MemoryStream(TmpChunk.Data)); SInfo.Sprite.Pal.AlwaysOne = PaltReader.ReadInt32(); SInfo.Sprite.Pal.Always256 = PaltReader.ReadInt32(); PaltReader.ReadBytes(8); //The PALT header has 8 additional bytes of 0. SInfo.Sprite.Pal.RGBTable = new Palette.RGB[SInfo.Sprite.Pal.Always256]; for (int l = 0; l < SInfo.Sprite.Pal.Always256; l++) { SInfo.Sprite.Pal.RGBTable[l] = new Palette.RGB(); SInfo.Sprite.Pal.RGBTable[l].Red = PaltReader.ReadByte(); SInfo.Sprite.Pal.RGBTable[l].Green = PaltReader.ReadByte(); SInfo.Sprite.Pal.RGBTable[l].Blue = PaltReader.ReadByte(); } PaltReader.Close(); Img.AddSpriteInfo(SInfo); } DGRP.AddImage(Img); } } else if (DGRP.Version == 20003 || DGRP.Version == 20004) { DGRP.Count = ChunkReader.ReadInt32(); for (int i = 0; i < DGRP.Count; i++) { DGRPImg Img = new DGRPImg(); Img.DirFlags = ChunkReader.ReadInt32(); Img.ZoomFactor = ChunkReader.ReadInt32(); Img.SpriteInfoCount = ChunkReader.ReadInt32(); //Each DrawGroup Image contains a number of SpriteInfo resources. for (int j = 0; j < Img.SpriteInfoCount; j++) { SpriteInfo SInfo = new SpriteInfo(); SInfo.SprID = ChunkReader.ReadInt32(); SInfo.SprFrame = ChunkReader.ReadInt32(); SInfo.PixelX = ChunkReader.ReadInt32(); SInfo.PixelY = ChunkReader.ReadInt32(); SInfo.ZOffset = ChunkReader.ReadInt32(); SInfo.Flags = ChunkReader.ReadInt32(); SInfo.XOffset = ChunkReader.ReadInt32(); SInfo.YOffset = ChunkReader.ReadInt32(); //Each SpriteInfo resource contains a reference to a SPR2 chunk/resource. SInfo.Sprite = new SPR2(); IffChunk TmpChunk = new IffChunk(); foreach (IffChunk C in m_Chunks) { if (C.TypeNum == SInfo.SprID) { //Guess what? The typenumber of each chunk is //NOT unique, so you have to check on type as //well! if (C.Type == "SPR2") { TmpChunk = C; break; } } } BinaryReader SpriteReader = new BinaryReader(new MemoryStream(TmpChunk.Data)); SInfo.Sprite.Version1 = SpriteReader.ReadInt16(); if (SInfo.Sprite.Version1 == 0) SInfo.Sprite.Version2 = ReadBigShort(SpriteReader); else SInfo.Sprite.Version2 = SpriteReader.ReadInt16(); SInfo.Sprite.FrameCount = SpriteReader.ReadInt32(); SInfo.Sprite.PaletteID = SpriteReader.ReadInt32(); SInfo.Sprite.OffsetTable = new int[SInfo.Sprite.FrameCount]; for (int k = 0; k < SInfo.Sprite.FrameCount; k++) SInfo.Sprite.OffsetTable[k] = SpriteReader.ReadInt32(); for (int k = 0; k < SInfo.Sprite.FrameCount; k++) { SpriteFrame Frame = new SpriteFrame(); Frame.Width = ReadBigShort(SpriteReader); MessageBox.Show("Frame.Width: " + Frame.Width.ToString()); Frame.Height = ReadBigShort(SpriteReader); MessageBox.Show("Frame.Height: " + Frame.Height.ToString()); Frame.Flags = SpriteReader.ReadInt16(); Frame.Unknown = ReadBigShort(SpriteReader); MessageBox.Show("Unknown: " + Frame.Unknown.ToString()); Frame.PaletteID = SpriteReader.ReadInt16(); Frame.TransparentPixel = SpriteReader.ReadInt16(); Frame.XPos = SpriteReader.ReadInt16(); Frame.YPos = SpriteReader.ReadInt16(); BinaryWriter SpriteWriter = new BinaryWriter(Frame.SpriteData); for (int l = 0; l <= Frame.Height; l++) { SpriteWriter.Write(SpriteReader.ReadBytes(2)); SpriteWriter.Write(SpriteReader.ReadBytes(Frame.Width)); } SInfo.Sprite.AddFrame(Frame); SpriteWriter.Close(); } SpriteReader.Close(); //Each SPR2 resource contains a reference to a PALT chunk/resource. SInfo.Sprite.Pal = new Palette(); foreach (IffChunk C in m_Chunks) { if (C.TypeNum == SInfo.Sprite.PaletteID) { //Guess what? The typenumber of each chunk is //NOT unique, so you have to check on type as //well! if (C.Type == "PALT") { TmpChunk = C; break; } } } BinaryReader PaltReader = new BinaryReader(new MemoryStream(TmpChunk.Data)); SInfo.Sprite.Pal.AlwaysOne = PaltReader.ReadInt32(); SInfo.Sprite.Pal.Always256 = PaltReader.ReadInt32(); PaltReader.ReadBytes(8); //The PALT header has 8 additional bytes of 0. SInfo.Sprite.Pal.RGBTable = new Palette.RGB[SInfo.Sprite.Pal.Always256]; for (int l = 0; l < SInfo.Sprite.Pal.Always256; l++) { SInfo.Sprite.Pal.RGBTable[l] = new Palette.RGB(); SInfo.Sprite.Pal.RGBTable[l].Red = PaltReader.ReadByte(); SInfo.Sprite.Pal.RGBTable[l].Green = PaltReader.ReadByte(); SInfo.Sprite.Pal.RGBTable[l].Blue = PaltReader.ReadByte(); } PaltReader.Close(); Img.AddSpriteInfo(SInfo); } DGRP.AddImage(Img); } } m_DGRPs.Add(DGRP); } }
public override void OnFrameExit(SpriteAnimationBehaviour animated, SpriteFrame frame) { base.OnFrameExit(animated, frame); Destroy(animated.gameObject); }
public void Remove(SpriteFrame frame) { Sprite.Remove(frame); OnPropertyChanged("Count"); }
public Brewery(SpriteFrame spriteFrame, Vector2 position, Rectangle rect, Actions type, Costs costs) : base(spriteFrame, position, rect, type, costs) { }