public ObjectData GetThingData(ushort id, ThingCategory category, bool singleFrameGroup) { ThingType thing = this.Things.GetThing(id, category); if (thing == null) { return(null); } if (singleFrameGroup) { thing = ThingType.ToSingleFrameGroup(thing); } SpriteGroup spriteGroups = new SpriteGroup(); Console.WriteLine(thing.FrameGroupCount); for (byte i = 0; i < thing.FrameGroupCount; i++) { FrameGroupType groupType = (FrameGroupType)i; FrameGroup frameGroup = thing.GetFrameGroup(groupType); int length = frameGroup.SpriteIDs.Length; Sprite[] sprites = new Sprite[length]; for (int s = 0; s < length; s++) { sprites[s] = this.Sprites.GetSprite(frameGroup.SpriteIDs[s]); } spriteGroups.Add(groupType, sprites); } return(new ObjectData(thing, spriteGroups)); }
private void DrawImages(SpriteGroup group) { for (int i = 0; i < capacity; i++) { string name = "Element " + (i + 1); float aspect = 1; if (group.Sprites[i] != null) { name = (i + 1) + ": " + group.Sprites[i].name; aspect = (float)group.Sprites[i].rect.width / group.Sprites[i].rect.height; } EditorGUILayout.BeginHorizontal(); { GUILayout.Label(name, GUILayout.Width(labelWidth)); GUILayout.FlexibleSpace(); group.Sprites[i] = (Sprite)EditorGUILayout.ObjectField( group.Sprites[i], typeof(Sprite), false, new GUILayoutOption[] { GUILayout.Height(imageSize), GUILayout.Width(imageSize * aspect) } ); GUILayout.Space(20); } EditorGUILayout.EndHorizontal(); GUILayout.Space(verticalSpacing); } }
public IntPtr Draw(float x, float y, Action <ISpriteDrawing> pre = null, Action <ISpriteDrawing> post = null) { _drawing.SetViewport(0, Width, 0, Height); _drawing.DestinationTexture = _spriteTexture; _drawing.Clear(_settings.EditorBackground); pre?.Invoke(_drawing); int posX; int posY; if (SpriteGroup.Count > 0) { posX = -SpriteGroup.Min(x => Math.Min(x.Left, x.Right)); posY = -SpriteGroup.Min(x => Math.Min(x.Top, x.Bottom)); } else { posX = 0; posY = 0; } _renderer.Draw(0, _frameIndex++, posX + x, posY + y); _drawing.Flush(); post?.Invoke(_drawing); _drawing.DestinationTexture = null; return(TextureId); }
public override void DrawSprites(SpriteGroup sGroup, float frameProgress) { for (int i = 0; i < sGroup.sprites.Length; i += 1) { sGroup.sprites[i].isVisible = visible; if (myText != null) myText.isVisible = visible; } if (visible) { for (int i = 0; i < sGroup.sprites.Length; i += 1) { sGroup.sprites[i].x = Mathf.Lerp(this.lastPos.x, this.pos.x, frameProgress); sGroup.sprites[i].y = Mathf.Lerp(this.lastPos.y, this.pos.y, frameProgress); } if (myText != null) { myText.x = sGroup.sprites[0].x; myText.y = sGroup.sprites[1].y; } if (MouseOver && (!VoezEditor.confirmBoxOpen || confirmComponent)) sGroup.sprites[0].color = Color.Lerp(sGroup.sprites[0].color, Color.gray, 0.15f); else sGroup.sprites[0].color = Color.Lerp(sGroup.sprites[0].color, DefaultColor(), 0.15f); sGroup.sprites[0].alpha = myAlpha; } base.DrawSprites(sGroup, frameProgress); }
private void Add(string name, Sprite sprite, string partName = null) { SpriteGroup group; if (_sprites.ContainsKey(name)) { group = _sprites[name]; } else { group = new SpriteGroup(this); _sprites.Add(name, group); if (currentSpriteGroup == null) { currentSpriteGroup = group; } } group.Add(sprite, partName); if (group == currentSpriteGroup) { sprite.Play(); } }
public SpriteGroup GetSpriteGroup(string name) { SpriteGroup group = null; m_SpriteGroupDict.TryGetValue(name, out group); return(group); }
public override void DrawSprites(SpriteGroup sGroup, float frameProgress) { if (lastPos == Vector2.zero || pos == Vector2.zero) { for (int i = 0; i < sGroup.sprites.Length; i += 1) { sGroup.sprites[i].isVisible = false; } } else { for (int i = 0; i < sGroup.sprites.Length; i += 1) { sGroup.sprites[i].isVisible = true; } } Vector2 drawPos = new Vector2(Mathf.Lerp(lastPos.x, pos.x, frameProgress), Mathf.Lerp(lastPos.y, pos.y, frameProgress)); sGroup.sprites[0].x = drawPos.x - bounds.width * 0.5f; sGroup.sprites[1].x = drawPos.x + bounds.width * 0.5f; sGroup.sprites[0].y = drawPos.y; sGroup.sprites[1].y = drawPos.y; sGroup.sprites[2].y = drawPos.y - bounds.height * 0.5f; sGroup.sprites[3].y = drawPos.y + bounds.height * 0.5f; sGroup.sprites[2].x = drawPos.x; sGroup.sprites[3].x = drawPos.x; base.DrawSprites(sGroup, frameProgress); }
public virtual void DrawSprites(SpriteGroup sGroup, float frameProgress) { if (readyForDeletion) { sGroup.CleanSpritesAndRemove(); } }
/// <summary> /// Constructs a SelectTargetMouseHandler instance. /// </summary> /// <param name="scrollEventSource">The UISensitiveObject that will raise the events for scrolling.</param> /// <param name="mapDisplay">Reference to the target map display.</param> /// <param name="normalMouseEventSource">The UISensitiveObject that will raise the additional mouse events.</param> /// <param name="sprites">The sprites to be used when displaying object placement box.</param> public SelectTargetMouseHandler(UISensitiveObject scrollEventSource, IMapDisplay mapDisplay, UISensitiveObject normalMouseEventSource, SpriteGroup sprites) : base(scrollEventSource, mapDisplay) { if (normalMouseEventSource == null) { throw new ArgumentNullException("normalMouseEventSource"); } if (sprites == null) { throw new ArgumentNullException("sprites"); } if (this.CommandView.TargetSelectionMode == TargetSelectionModeEnum.NoTargetSelection) { throw new InvalidOperationException("Target selection is not possible currently!"); } this.targetSelectionMode = this.CommandView.TargetSelectionMode; this.multiplayerService = ComponentManager.GetInterface <IMultiplayerService>(); this.normalMouseEventSource = normalMouseEventSource; this.objectPlacementInfo = this.targetSelectionMode == TargetSelectionModeEnum.BuildingLocationSelection ? new ObjectPlacementInfo( ComponentManager.GetInterface <IViewService>().CreateView <INormalModeMapObjectPlacementView>(), sprites) : null; this.normalMouseEventSource.MouseSensor.ButtonDown += this.OnMouseDown; this.multiplayerService.GameUpdated += this.OnGameUpdate; }
public override void InitiateSprites(SpriteGroup sGroup) { sGroup.sprites = new FSprite[6]; sGroup.sprites[Spr_SliderBack] = new FSprite("Futile_White"); sGroup.sprites[Spr_SliderBack].color = Color.black; sGroup.sprites[Spr_SliderBack].scaleX = (width + 4f) / sGroup.sprites[Spr_SliderBack].width; sGroup.sprites[Spr_SliderBack].scaleY = 10f / sGroup.sprites[Spr_SliderBack].height; sGroup.sprites[Spr_SliderFront] = new FSprite("Futile_White"); sGroup.sprites[Spr_SliderFront].scaleX = width / sGroup.sprites[Spr_SliderFront].width; sGroup.sprites[Spr_SliderFront].scaleY = 10f / sGroup.sprites[Spr_SliderFront].height; sGroup.sprites[Spr_SliderScrubberBack] = new FSprite("Futile_White"); sGroup.sprites[Spr_SliderScrubberBack].scaleX = SCRUBBER_SIZE / Mathf.Sqrt(2f * Mathf.Pow(sGroup.sprites[Spr_SliderScrubberBack].width, 2f)); sGroup.sprites[Spr_SliderScrubberBack].scaleY = SCRUBBER_SIZE / Mathf.Sqrt(2f * Mathf.Pow(sGroup.sprites[Spr_SliderScrubberBack].height, 2f)); sGroup.sprites[Spr_SliderScrubberBack].rotation = 45f; sGroup.sprites[Spr_SliderScrubberBack].alpha = 0.8f; sGroup.sprites[Spr_SliderScrubberBack].color = Color.black; sGroup.sprites[Spr_SliderScrubberFront] = new FSprite("outlineBoxMed"); sGroup.sprites[Spr_SliderScrubberFront].scaleX = (SCRUBBER_SIZE - 5f) / Mathf.Sqrt(2f * Mathf.Pow(sGroup.sprites[Spr_SliderScrubberFront].width, 2f)); sGroup.sprites[Spr_SliderScrubberFront].scaleY = (SCRUBBER_SIZE - 5f) / Mathf.Sqrt(2f * Mathf.Pow(sGroup.sprites[Spr_SliderScrubberFront].height, 2f)); sGroup.sprites[Spr_SliderScrubberFront].rotation = 45f; sGroup.sprites[Spr_LoopPointBack] = new FSprite("Futile_White"); sGroup.sprites[Spr_LoopPointBack].scaleX = (SCRUBBER_SIZE * 0.5f) / Mathf.Sqrt(2f * Mathf.Pow(sGroup.sprites[Spr_LoopPointBack].width, 2f)); sGroup.sprites[Spr_LoopPointBack].scaleY = (SCRUBBER_SIZE * 0.5f) / Mathf.Sqrt(2f * Mathf.Pow(sGroup.sprites[Spr_LoopPointBack].height, 2f)); sGroup.sprites[Spr_LoopPointBack].rotation = 45f; sGroup.sprites[Spr_LoopPointBack].color = Color.red; sGroup.sprites[Spr_LoopPointFront] = new FSprite("outlineBoxMed"); sGroup.sprites[Spr_LoopPointFront].scaleX = ((SCRUBBER_SIZE * 0.5f) - 5f) / Mathf.Sqrt(2f * Mathf.Pow(sGroup.sprites[Spr_LoopPointFront].width, 2f)); sGroup.sprites[Spr_LoopPointFront].scaleY = ((SCRUBBER_SIZE * 0.5f) - 5f) / Mathf.Sqrt(2f * Mathf.Pow(sGroup.sprites[Spr_LoopPointFront].height, 2f)); sGroup.sprites[Spr_LoopPointFront].rotation = 45f; sGroup.sprites[Spr_LoopPointFront].color = Color.white; }
public override void AddToContainer(SpriteGroup sGroup, FContainer newContainer) { for (int i = 0; i < labels.Length; i += 1) { newContainer.AddChild(labels[i]); } }
public void AddObject(UpdatableObject obj) { this.updateList.Add(obj); if (obj is IDrawable) { SpriteGroup group = new SpriteGroup(obj as IDrawable); spriteGroups.Add(group); if (obj is UIElement) { group.AddSpritesToContainer(foregroundContainer); } else { group.AddSpritesToContainer(backgroundContainer); } } if (obj is Track) { activeTracks.Add(obj as Track); } if (obj is Note) { activeNotes.Add(obj as Note); } }
public override void InitiateSprites(SpriteGroup sGroup) { sGroup.sprites = new FSprite[1]; float effectiveSize = Mathf.Sqrt(Mathf.Pow(size, 2f) / 2f); if (data == null) { sGroup.sprites[0] = new FSprite("outlineBoxLargest"); sGroup.sprites[0].color = Color.black; sGroup.sprites[0].alpha = 0.1f; } else { if (data.thumbnail != null) { sGroup.sprites[0] = new FSprite("thumbnail_" + data.songName); } else { sGroup.sprites[0] = new FSprite("defaultThumbnail"); } } sGroup.sprites[0].rotation = 45; sGroup.sprites[0].scale = effectiveSize / Mathf.Max(sGroup.sprites[0].width, sGroup.sprites[0].height); }
public override void InitiateSprites(SpriteGroup sGroup) { if (mySymbol != null) sGroup.sprites = new FSprite[3]; else sGroup.sprites = new FSprite[2]; sGroup.sprites[0] = new FSprite("Futile_White"); sGroup.sprites[0].color = DefaultColor(); sGroup.sprites[0].alpha = myAlpha; if (diamond) { sGroup.sprites[0].rotation = 45f; float newEffectiveWidth = Mathf.Sqrt(2f * Mathf.Pow(sGroup.sprites[0].width, 2)); sGroup.sprites[0].scale = size / newEffectiveWidth; } else sGroup.sprites[0].scale = size / sGroup.sprites[0].width; sGroup.sprites[1] = new FSprite("outlineBoxMed"); if (diamond) { sGroup.sprites[1].rotation = 45f; float newEffectiveWidth = Mathf.Sqrt(2f * Mathf.Pow(sGroup.sprites[1].width, 2)); sGroup.sprites[1].scale = (size - 7f) / newEffectiveWidth; } else sGroup.sprites[1].scale = (size - 7f) / sGroup.sprites[1].width; if (mySymbol != null) { sGroup.sprites[2] = mySymbol; sGroup.sprites[2].scale = (size * 0.6f) / Mathf.Max(sGroup.sprites[2].width, sGroup.sprites[2].height); } }
public void SizeChanged() { var rect = SpriteGroup.GetVisibilityRectangleForFrameGroup(); if (rect.Width == Width && rect.Height == Height) { return; } Width = rect.Width; Height = rect.Height; _spriteTexture?.Dispose(); _spriteTexture = _drawing.CreateSpriteTexture(Width, Height); if (TextureId == IntPtr.Zero) { TextureId = _textureBinder.BindTexture(_spriteTexture); } else { _textureBinder.RebindTexture(TextureId, _spriteTexture); } Draw(0, 0); }
protected override async Task LoadContent() { await base.LoadContent(); spriteBatch = new SpriteBatch(GraphicsDevice); sphere = Asset.Load<Texture>("Sphere"); rotatedImages = Asset.Load<SpriteGroup>("RotatedImages"); }
public override void DrawSprites(SpriteGroup sGroup, float frameProgress) { sGroup.sprites[0].x = pos.x; sGroup.sprites[0].y = pos.y; sGroup.sprites[0].color = myColor; sGroup.sprites[0].alpha = Mathf.Abs(Mathf.Sin(sinTimer * ((2f * Mathf.PI) / 240f))) * 0.6f + 0.4f; base.DrawSprites(sGroup, frameProgress); }
public override void DrawSprites(SpriteGroup sGroup, float frameProgress) { sGroup.sprites[0].x = 0; sGroup.sprites[0].x = 0; sGroup.sprites[1].y = 0; sGroup.sprites[1].y = VoezEditor.windowRes.y; base.DrawSprites(sGroup, frameProgress); }
public override void DrawSprites(SpriteGroup sGroup, float frameProgress) { Vector2 drawPos = new Vector2(Mathf.Lerp(lastPos.x, pos.x, frameProgress), Mathf.Lerp(lastPos.y, pos.y, frameProgress)); sGroup.sprites[0].x = drawPos.x; sGroup.sprites[0].y = drawPos.y; base.DrawSprites(sGroup, frameProgress); }
protected override async Task LoadContent() { await base.LoadContent(); spriteUv = Asset.Load <SpriteGroup>("SpriteUV"); spriteSphere = Asset.Load <SpriteGroup>("SpriteSphere"); spriteBatch = new SpriteBatch(GraphicsDevice); }
protected override async Task LoadContent() { await base.LoadContent(); spriteUv = Asset.Load<SpriteGroup>("SpriteUV"); spriteSphere = Asset.Load<SpriteGroup>("SpriteSphere"); spriteBatch = new SpriteBatch(GraphicsDevice); }
protected override async Task LoadContent() { await base.LoadContent(); spriteBatch = new SpriteBatch(GraphicsDevice); sphere = Asset.Load <Texture>("Sphere"); rotatedImages = Asset.Load <SpriteGroup>("RotatedImages"); }
public override void AddToContainer(SpriteGroup sGroup, FContainer newContainer) { foreach (FSprite fsprite in sGroup.sprites) { fsprite.RemoveFromContainer(); VoezEditor.Editor.gridContainer.AddChild(fsprite); } }
public SpriteEntry(byte[] preamble, SpriteGroup sprites) { preamble.ThrowIfNull(nameof(preamble)); sprites.ThrowIfNull(nameof(sprites)); Preamble = preamble.ToArray(); Sprites = sprites; }
public override void DrawSprites(SpriteGroup sGroup, float frameProgress) { Vector2 drawPos = new Vector2(Mathf.Lerp(lastPos.x, pos.x, frameProgress), Mathf.Lerp(lastPos.y, pos.y, frameProgress)); sGroup.sprites[Spr_Back].x = drawPos.x; sGroup.sprites[Spr_Back].y = drawPos.y; Vector3 mouse = Input.mousePosition; sGroup.sprites[Spr_Hover].isVisible = false; for (int i = 0; i < numLines; i += 1) { if (mouse.x >= pos.x - WIDTH * 0.5f && mouse.x <= pos.x + WIDTH * 0.5f && mouse.y < pos.y + HEIGHT * 0.5f - LINES_START - LINE_HEIGHT * i && mouse.y >= pos.y + HEIGHT * 0.5f - LINES_START - LINE_HEIGHT * (i + 1)) { sGroup.sprites[Spr_Hover].isVisible = true; sGroup.sprites[Spr_Hover].x = drawPos.x; sGroup.sprites[Spr_Hover].y = drawPos.y + HEIGHT * 0.5f - LINES_START - LINE_HEIGHT * i; if (InputManager.leftMousePushed) { selectedLine = i; keyframeEditor.transSelected = -1; // Jump playback time to the time being referenced/edited if (selectedLine == 0 || selectedLine == 2) { VoezEditor.Editor.JumpToTime(data.start); } if (selectedLine == 1) { VoezEditor.Editor.JumpToTime(data.end); } } } } sGroup.sprites[Spr_Selector].x = drawPos.x; sGroup.sprites[Spr_Selector].y = drawPos.y + HEIGHT * 0.5f - LINES_START - LINE_HEIGHT * selectedLine; if (selectedLine < 0) { sGroup.sprites[Spr_Selector].isVisible = false; } else { sGroup.sprites[Spr_Selector].isVisible = true; } startLabel.x = pos.x - WIDTH * 0.5f + 20f + startLabel.textRect.width * 0.5f; endLabel.x = pos.x - WIDTH * 0.5f + 20f + endLabel.textRect.width * 0.5f; valueLabel.x = pos.x - WIDTH * 0.5f + 20f + valueLabel.textRect.width * 0.5f; startLabel.y = pos.y + HEIGHT * 0.5f - LINES_START - LINE_HEIGHT * 0.5f; endLabel.y = pos.y + HEIGHT * 0.5f - LINES_START - LINE_HEIGHT * 1.5f; valueLabel.y = pos.y + HEIGHT * 0.5f - LINES_START - LINE_HEIGHT * 2.5f; base.DrawSprites(sGroup, frameProgress); }
public override void InitiateSprites(SpriteGroup sGroup) { sGroup.sprites = new FSprite[1]; sGroup.sprites[0] = new FSprite("Futile_White"); sGroup.sprites[0].scaleX = bounds.width / sGroup.sprites[0].width; sGroup.sprites[0].scaleY = bounds.height / sGroup.sprites[0].height; sGroup.sprites[0].color = Color.black; sGroup.sprites[0].alpha = 0.8f; }
public override void AddToContainer(SpriteGroup sGroup, FContainer newContainer) { foreach (FSprite fsprite in sGroup.sprites) { fsprite.RemoveFromContainer(); newContainer.AddChild(fsprite); } newContainer.AddChild(text); }
public void AddSpriteGroup(SpriteGroup spriteGroup) { int groupCount = Children.Count; if (HasSpecialSprite) { groupCount--; } InsertSpriteGroup(groupCount, spriteGroup); }
public virtual void AddToContainer(SpriteGroup sGroup, FContainer newContainer) { defaultContainer = newContainer; foreach (FSprite fsprite in sGroup.sprites) { fsprite.RemoveFromContainer(); newContainer.AddChild(fsprite); } }
public void AddSpriteGroup(IShape shape, Sprite[] images, Vector2Int size_, byte id_ = 0) { byte id = id_ == 0 || id_ < sprite_groups.Count ? (byte)sprite_groups.Count : id_; SpriteGroup group = new SpriteGroup(images, shape) { size = size_ }; sprite_groups.Add(id, group); }
public override void InitiateSprites(SpriteGroup sGroup) { sGroup.sprites = new FSprite[1]; sGroup.sprites[0] = new FSprite("Futile_White"); sGroup.sprites[0].anchorX = 0f; sGroup.sprites[0].anchorY = 0f; sGroup.sprites[0].scaleX = VoezEditor.windowRes.x / sGroup.sprites[0].width; sGroup.sprites[0].scaleY = VoezEditor.windowRes.y / sGroup.sprites[0].height; sGroup.sprites[0].color = color; }
public override void DrawSprites(SpriteGroup sGroup, float frameProgress) { Vector2 drawPos = new Vector2(Mathf.Lerp(this.lastPos.x, this.pos.x, frameProgress), Mathf.Lerp(this.lastPos.y, this.pos.y, frameProgress)); normalText.x = drawPos.x; normalText.y = drawPos.y; shadowText.x = drawPos.x + offset.x; shadowText.y = drawPos.y + offset.y; base.DrawSprites(sGroup, frameProgress); }
protected override async Task LoadContent() { await base.LoadContent(); var virtualResolution = new Vector3(GraphicsDevice.BackBuffer.ViewWidth, GraphicsDevice.BackBuffer.ViewHeight, 200); spriteBatch = new SpriteBatch(GraphicsDevice) { VirtualResolution = virtualResolution }; spheres = Asset.Load<SpriteGroup>("SpriteSphere"); round = Asset.Load<Texture>("round"); staticFont = Asset.Load<SpriteFont>("StaticFonts/CourierNew10"); dynamicFont = Asset.Load<SpriteFont>("DynamicFonts/CourierNew10"); colorTexture = Texture.New2D(GraphicsDevice, 1, 1, PixelFormat.R8G8B8A8_UNorm, new[] { Color.White }); }
public ThingData(ThingType type, SpriteGroup sprites) { if (type == null) { throw new ArgumentNullException("type"); } if (sprites == null) { throw new ArgumentNullException("sprites"); } this.type = type; this.sprites = sprites; this.Format = DatFormat.Format_1057; }
protected override async Task LoadContent() { await base.LoadContent(); spriteBatch = new SpriteBatch(GraphicsDevice); offlineTarget = Texture.New2D(GraphicsDevice, OfflineWidth, OfflineHeight, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this); depthBuffer = Texture.New2D(GraphicsDevice, OfflineWidth, OfflineHeight, PixelFormat.D16_UNorm, TextureFlags.DepthStencil).DisposeBy(this); uv = Asset.Load<Texture>("uv"); spheres = Asset.Load<SpriteGroup>("SpriteSphere"); arial = Asset.Load<SpriteFont>("StaticFonts/Arial13"); width = GraphicsDevice.BackBuffer.ViewWidth; height = GraphicsDevice.BackBuffer.ViewHeight; }
protected override async Task LoadContent() { await base.LoadContent(); // sets the virtual resolution areaSize = new Vector2(GraphicsDevice.BackBuffer.Width, GraphicsDevice.BackBuffer.Height); // Creates the camera CameraComponent.UseCustomProjectionMatrix = true; CameraComponent.ProjectionMatrix = SpriteBatch.CalculateDefaultProjection(new Vector3(areaSize, 200)); // Load assets groundSprites = Asset.Load<SpriteGroup>("GroundSprite"); ballSprite1 = Asset.Load<Texture>("Sphere1"); ballSprite2 = Asset.Load<Texture>("Sphere2"); ball = Asset.Load<Entity>("Ball"); // create fore/background entities foreground = new Entity(); background = new Entity(); foreground.Add(new SpriteComponent { SpriteProvider = new SpriteFromSpriteGroup { SpriteGroup = groundSprites }, CurrentFrame = 1 }); background.Add(new SpriteComponent { SpriteProvider = new SpriteFromSpriteGroup { SpriteGroup = groundSprites }, CurrentFrame = 0 }); Scene.AddChild(ball); Scene.AddChild(foreground); Scene.AddChild(background); spriteComponent = ball.Get(SpriteComponent.Key); transfoComponent = ball.Get(TransformComponent.Key); transfoComponent.Position.X = areaSize.X / 2; transfoComponent.Position.Y = areaSize.Y / 2; var decorationScalings = new Vector3(areaSize.X, areaSize.Y, 1); background.Get(TransformComponent.Key).Scale = decorationScalings; foreground.Get(TransformComponent.Key).Scale = decorationScalings; background.Get(TransformComponent.Key).Position = new Vector3(0, 0, -1); foreground.Get(TransformComponent.Key).Position = new Vector3(0, areaSize.Y, 1); SpriteAnimation.Play(spriteComponent, 0, spriteComponent.SpriteProvider.SpritesCount-1, AnimationRepeatMode.LoopInfinite, 30); }
public ThingData GetThingData(ushort id, ThingCategory category, bool singleFrameGroup) { ThingType thing = this.Things.GetThing(id, category); if (thing == null) { return null; } if (singleFrameGroup) { thing = ThingType.ToSingleFrameGroup(thing); } SpriteGroup spriteGroups = new SpriteGroup(); Console.WriteLine(thing.FrameGroupCount); for (byte i = 0; i < thing.FrameGroupCount; i++) { FrameGroupType groupType = (FrameGroupType)i; FrameGroup frameGroup = thing.GetFrameGroup(groupType); int length = frameGroup.SpriteIDs.Length; Sprite[] sprites = new Sprite[length]; for (int s = 0; s < length; s++) { sprites[s] = this.Sprites.GetSprite(frameGroup.SpriteIDs[s]); } spriteGroups.Add(groupType, sprites); } return new ThingData(thing, spriteGroups); }
private static SpriteComponent CreateSpriteComponent(int nbOfFrames) { var spriteGroup = new SpriteGroup { Images = new List<Sprite>() }; var sprite = new SpriteComponent { SpriteProvider = new SpriteFromSpriteGroup { SpriteGroup = spriteGroup } }; // add a few sprites for (int i = 0; i < nbOfFrames; i++) { spriteGroup.Images.Add(new Sprite(Guid.NewGuid().ToString())); } return sprite; }
private static ThingData DecodeV1(BinaryReader reader) { reader.BaseStream.Position = 0; Console.WriteLine(reader.ReadUInt16()); ushort nameLength = reader.ReadUInt16(); byte[] buffer = reader.ReadBytes(nameLength); string categoryStr = Encoding.UTF8.GetString(buffer, 0, buffer.Length); ThingCategory category = ThingCategory.Invalid; switch (categoryStr) { case "item": category = ThingCategory.Item; break; case "outfit": category = ThingCategory.Outfit; break; case "effect": category = ThingCategory.Effect; break; case "missile": category = ThingCategory.Missile; break; } ThingType thing = new ThingType(category); if (!ThingTypeSerializer.ReadProperties(thing, DatFormat.Format_1010, reader)) { return null; } FrameGroup group = new FrameGroup(); group.Width = reader.ReadByte(); group.Height = reader.ReadByte(); if (group.Width > 1 || group.Height > 1) { group.ExactSize = reader.ReadByte(); } else { group.ExactSize = Sprite.DefaultSize; } group.Layers = reader.ReadByte(); group.PatternX = reader.ReadByte(); group.PatternY = reader.ReadByte(); group.PatternZ = reader.ReadByte(); group.Frames = reader.ReadByte(); if (group.Frames > 1) { group.IsAnimation = true; group.AnimationMode = AnimationMode.Asynchronous; group.LoopCount = 0; group.StartFrame = 0; group.FrameDurations = new FrameDuration[group.Frames]; for (byte i = 0; i < group.Frames; i++) { group.FrameDurations[i] = new FrameDuration(category); } } int totalSprites = group.GetTotalSprites(); if (totalSprites > 4096) { throw new Exception("The ThingData has more than 4096 sprites."); } group.SpriteIDs = new uint[totalSprites]; SpriteGroup spriteGroup = new SpriteGroup(); Sprite[] sprites = new Sprite[totalSprites]; for (int i = 0; i < totalSprites; i++) { uint spriteID = reader.ReadUInt32(); group.SpriteIDs[i] = spriteID; uint dataSize = reader.ReadUInt32(); if (dataSize > Sprite.PixelsDataSize) { throw new Exception("Invalid sprite data size."); } byte[] pixels = reader.ReadBytes((int)dataSize); Sprite sprite = new Sprite(spriteID, true); sprite.SetPixelsARGB(pixels); sprites[i] = sprite; } thing.SetFrameGroup(FrameGroupType.Default, group); spriteGroup.Add(FrameGroupType.Default, sprites); return new ThingData(thing, spriteGroup); }