Пример #1
0
 /// <summary>
 /// 从资源文件中获取图片资源并返回精灵对象
 /// </summary>
 /// <param name="sourceName">资源名称</param>
 /// <param name="rtype">资源类型</param>
 /// <param name="cutRect">纹理切割矩</param>
 /// <returns>该资源的精灵</returns>
 private YuriSprite GetGraphicSprite(string sourceName, ResourceType rtype, Int32Rect? cutRect)
 {
     if (sourceName == "") { return null; }
     YuriSprite sprite = new YuriSprite();
     string DevURI = null, PackURI = null;
     // 处理路径
     switch (rtype)
     {
         case ResourceType.Background:
             DevURI = GlobalDataContainer.DevURI_PA_BACKGROUND;
             PackURI = GlobalDataContainer.PackURI_PA_BACKGROUND;
             break;
         case ResourceType.Stand:
             DevURI = GlobalDataContainer.DevURI_PA_CHARASTAND;
             PackURI = GlobalDataContainer.PackURI_PA_CHARASTAND;
             break;
         case ResourceType.Pictures:
             DevURI = GlobalDataContainer.DevURI_PA_PICTURES;
             PackURI = GlobalDataContainer.PackURI_PA_PICTURES;
             break;
         default:
             return null;
     }
     // 总是先查看是否有为封包的数据
     if (this.resourceTable.ContainsKey(DevURI) &&
         this.resourceTable[DevURI].ContainsKey(sourceName))
     {
         KeyValuePair<long, long> sourceLocation = this.resourceTable[DevURI][sourceName];
         byte[] ob = PackageUtils.GetObjectBytes(IOUtils.ParseURItoURL(PackURI + GlobalDataContainer.PackPostfix),
             sourceName, sourceLocation.Key, sourceLocation.Value);
         MemoryStream ms = new MemoryStream(ob);
         sprite.Init(sourceName, rtype, ms, cutRect);
     }
     // 没有封包数据再搜索开发目录
     else
     {
         string furi = IOUtils.JoinPath(GlobalDataContainer.DevURI_RT_PICTUREASSETS, DevURI, sourceName);
         if (File.Exists(IOUtils.ParseURItoURL(furi)))
         {
             Uri bg = new Uri(IOUtils.ParseURItoURL(furi), UriKind.RelativeOrAbsolute);
             sprite.Init(sourceName, rtype, bg, cutRect);
         }
         else
         {
             throw new Exception("文件不存在:" + sourceName);
         }
     }
     return sprite;
 }
Пример #2
0
 /// <summary>
 /// 为主窗体描绘一个精灵
 /// </summary>
 /// <param name="sprite">精灵</param>
 /// <param name="descriptor">精灵描述子</param>
 private void DrawSprite(YuriSprite sprite, SpriteDescriptor descriptor)
 {
     if (sprite == null) { return; }
     Image spriteImage = new Image();
     BitmapImage bmp = sprite.SpriteBitmapImage;
     spriteImage.Width = bmp.PixelWidth;
     spriteImage.Height = bmp.PixelHeight;
     spriteImage.Source = bmp;
     spriteImage.Opacity = descriptor.Opacity;
     sprite.CutRect = descriptor.CutRect;
     sprite.DisplayBinding = spriteImage;
     sprite.Anchor = descriptor.AnchorType;
     Canvas.SetLeft(spriteImage, descriptor.X);
     Canvas.SetTop(spriteImage, descriptor.Y);
     Canvas.SetZIndex(spriteImage, descriptor.Z);
     spriteImage.Visibility = Visibility.Visible;
     this.view.BO_MainGrid.Children.Add(spriteImage);
     sprite.InitAnimationRenderTransform();
     SpriteAnimation.RotateToAnimation(sprite, TimeSpan.FromMilliseconds(0), descriptor.Angle, 0);
     SpriteAnimation.ScaleToAnimation(sprite, TimeSpan.FromMilliseconds(0), descriptor.ScaleX, descriptor.ScaleY, 0, 0);
 }
Пример #3
0
 /// <summary>
 /// 将精灵从画面移除
 /// </summary>
 /// <param name="sprite">精灵实例</param>
 private void RemoveSprite(YuriSprite sprite)
 {
     if (sprite != null)
     {
         Image spriteView = sprite.DisplayBinding;
         if (spriteView != null)
         {
             if (this.view.BO_MainGrid.Children.Contains(spriteView))
             {
                 this.view.BO_MainGrid.Children.Remove(spriteView);
             }
         }
         sprite.DisplayBinding = null;
     }
 }
Пример #4
0
 /// <summary>
 /// 初始化文字小三角
 /// </summary>
 private void InitMsgLayerTria()
 {
     this.MainMsgTriangleSprite = ResourceManager.GetInstance().GetPicture(GlobalDataContainer.GAME_MESSAGELAYER_TRIA_FILENAME, new Int32Rect(-1, 0, 0, 0));
     Image TriaView = new Image();
     BitmapImage bmp = MainMsgTriangleSprite.SpriteBitmapImage;
     this.MainMsgTriangleSprite.DisplayBinding = TriaView;
     TriaView.Width = bmp.PixelWidth;
     TriaView.Height = bmp.PixelHeight;
     TriaView.Source = bmp;
     TriaView.Visibility = Visibility.Hidden;
     TriaView.RenderTransform = new TranslateTransform();
     Canvas.SetLeft(TriaView, GlobalDataContainer.GAME_MESSAGELAYER_TRIA_X);
     Canvas.SetTop(TriaView, GlobalDataContainer.GAME_MESSAGELAYER_TRIA_Y);
     Canvas.SetZIndex(TriaView, GlobalDataContainer.GAME_Z_PICTURES - 1);
     this.view.BO_MainGrid.Children.Add(this.MainMsgTriangleSprite.DisplayBinding);
 }