Inheritance: Jurassic.Library.ObjectInstance
Ejemplo n.º 1
0
        public EmitterInstance(ScriptEngine engine, ImageInstance image, ColorInstance color, double life, double speed)
            : base(engine)
        {
            Image = image;
            ImgWidth = (int)image.Texture.Size.X;
            ImgHeight = (int)image.Texture.Size.Y;
            StartX = 0;
            StartY = 0;
            Life = life;
            Speed = speed;
            Color = color;

            PopulateFunctions();
        }
Ejemplo n.º 2
0
 public void BlitImage(int x, int y, ImageInstance instance)
 {
     FloatRect dest = new FloatRect(x, y, _source.Width, _source.Height);
     _batch.Add(instance.Texture, _source.Left + x, _source.Top + y, Color.White);
     _changed = true;
 }
Ejemplo n.º 3
0
 public void BlitImage(int x, int y, ImageInstance instance)
 {
     _myBatch.Add(instance.Texture, (float)x, (float)y);
     _changed = true;
 }
Ejemplo n.º 4
0
 public void SetCharacterImage(int ch, ImageInstance image)
 {
     _glyphs[ch].Dispose();
     _glyphs[ch] = image.GetImage();
     _updated = true;
 }
Ejemplo n.º 5
0
 public static EmitterInstance CreateEmitter(ImageInstance image, ColorInstance color, double life, double speed)
 {
     return new EmitterInstance(Program._engine, image, color, life, speed);
 }
Ejemplo n.º 6
0
 public void BlitImage(int x, int y, ImageInstance instance)
 {
     using (Image img = instance.GetImage())
     {
         DrawImage(x, y, img.Pixels, (int)img.Size.X, (int)img.Size.Y);
     }
     _changed = true;
 }
Ejemplo n.º 7
0
        private static void SetTileImage(int tile, ImageInstance image)
        {
            if (tile < 0) return;

            using (var img = image.GetImage())
            {
                _tileatlas.SetImageAt((uint)tile, img);
                _tileatlas.Refresh();
            }

            _fastatlas.SetImageAt((uint)tile, (uint)tile);
        }
Ejemplo n.º 8
0
        private void ReadFromFile(string filename)
        {
            if (!File.Exists(filename))
            {
                new SpritesetException(filename, "can't find file");
            }

            using (BinaryReader reader = new BinaryReader(File.OpenRead(filename)))
            {
                if (!new String(reader.ReadChars(4)).Equals(".rss"))
                    throw new SpritesetException(filename, "Invalid header.");
                _version = reader.ReadInt16();
                short num_images = reader.ReadInt16();
                _width = reader.ReadInt16();
                _height = reader.ReadInt16();
                short num_dir = reader.ReadInt16();
                _bx1 = reader.ReadInt16(); _by1 = reader.ReadInt16();
                _bx2 = reader.ReadInt16(); _by2 = reader.ReadInt16();
                this["base"] = CreateBase();
                reader.ReadBytes(106);

                if (_version != 3)
                    throw new SpritesetException(filename, "Invalid version");
                else
                {
                    object[] images = new object[num_images];
                    Image[] list = new Image[num_images];
                    for (var i = 0; i < num_images; ++i)
                    {
                        int size = _width * _height * 4;
                        Image img = new Image((uint)_width, (uint)_height, reader.ReadBytes(size));
                        images[i] = new ImageInstance(Engine, new Texture(img), false);
                        list[i] = img;
                    }
                    ConstructTextureAtlas(list);

                    this["images"] = Program._engine.Array.New(images);

                    object[] dirs = new object[num_dir];
                    for (var d = 0; d < num_dir; ++d)
                    {
                        ObjectInstance o = Program.CreateObject();

                        short num_frames = reader.ReadInt16();
                        reader.ReadBytes(6);

                        string name = new string(reader.ReadChars(reader.ReadInt16()));
                        if (name.EndsWith("\0"))
                            name = name.Substring(0, name.Length - 1);
                        o["name"] = name;

                        object[] frames = new object[num_frames];
                        for (var f = 0; f < num_frames; ++f)
                        {
                            short index = reader.ReadInt16();
                            short delay = reader.ReadInt16();
                            reader.ReadBytes(4);

                            ObjectInstance frame_o = Program.CreateObject();
                            frame_o["index"] = (int)index;
                            frame_o["delay"] = (int)delay;
                            frames[f] = frame_o;
                        }
                        o["frames"] = Engine.Array.New(frames);
                        dirs[d] = o;
                    }
                    this["directions"] = Program._engine.Array.New(dirs);
                }
            }
        }