Example #1
0
 public override void Initialize(ContentManager Content)
 {
     if (sprite != null)
     {
         return;
     }
     sprite = new Sprite(textureDir);
     sprite.Initialize(Content);
     base.Initialize(Content);
 }
        public List<BaseSprite> CreateBaseSprites(XElement elements)
        {
            BaseSprite sprite = null;
            var items = elements.Descendants("Items");
            var element = elements.Descendants("CustomProperties").Descendants("Property");

            float layerDepth = 0;
            foreach (var property in element)
            {
                if (property.Attribute("Name") != null)
                {
                    string name = property.Attribute("Name").Value;
                    if (name == "LayerDepth")
                    {
                        layerDepth = float.Parse(property.Descendants("string").First<XElement>().Value, CultureInfo.InvariantCulture);
                    }
                }
            }

            List<BaseSprite> lsSprites = new List<BaseSprite>();

            foreach (var item in items)
            {
                var parts = item.Descendants("Item");

                foreach (var part in parts)
                {
                    if (part.Name == "Item")
                    {
                        element = part.Descendants("Position");
                        float posx = float.Parse(element.Elements("X").ElementAt(0).Value, CultureInfo.InvariantCulture);
                        float posy = float.Parse(element.Elements("Y").ElementAt(0).Value, CultureInfo.InvariantCulture);

                        float rot = float.Parse(part.Elements("Rotation").ElementAt(0).Value, CultureInfo.InvariantCulture);

                        element = part.Descendants("Scale");
                        float width = float.Parse(element.Elements("X").ElementAt(0).Value, CultureInfo.InvariantCulture);
                        float height = float.Parse(element.Elements("Y").ElementAt(0).Value, CultureInfo.InvariantCulture);

                        sprite = new BaseSprite();
                        sprite.Rot = rot;
                        sprite.PosZ = layerDepth;
                        sprite.Position = new Vector2(posx, -posy);
                        sprite.Scale = new Vector2(width, height);
                        lsSprites.Add(sprite);
                    }
                }
            }

            return lsSprites;
        }
Example #3
0
        public int CompareTo(object o)
        {
            if (!(o is BaseSprite))
            {
                return(0);
            }
            BaseSprite other = o as BaseSprite;

            if (other.Layer == Layer)
            {
                return(0);
            }
            else
            {
                return(other.Layer - Layer);
            }
        }
Example #4
0
        public virtual bool IsVisible(BaseSprite sprite)
        {
            {
                float max = (float)Math.Max(sprite.Width * ScaleX, sprite.Height * ScaleY);
                Vector2 pos = sprite.Position;

                Vector2 bottomRight = ScreenToWorld(Vector2.One);
                Vector2 topLeft = ScreenToWorld(Vector2.Zero);

                if (pos.X < bottomRight.X && pos.X > topLeft.X)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }

            JabRectangle camView = new JabRectangle(0, 0, 1.0f, 1.0f);
            JabRectangle spriteRect = sprite.GetRectangle();

            if (!(camView.Intersects(spriteRect) || spriteRect.Intersects(camView)))
            {
                int k = 0;
            }

            return camView.Intersects(spriteRect) || spriteRect.Intersects(camView);
        }
Example #5
0
 BaseSprite LoadTyre(BaseSprite sprite, string texturedir, XElement part)
 {
     BasketBall b = new BasketBall();
     b.IsTyre = true;
     b.Width = sprite.Width;// *sprite.ScaleX;
     b.Height = sprite.Height;// *sprite.ScaleY;
     b.Dimension = sprite.Dimension;
     b.Scale = sprite.Scale;
     b.World = world;
     b.Initialize(Content);
     b.Position = sprite.Position;
     return b;
 }
Example #6
0
 BaseSprite LoadFan(BaseSprite sprite, string texturedir, XElement part)
 {
     Fan f = new Fan(world);
     f.Initialize(Content);
     f.Rot = sprite.Rot;
     f.Position = sprite.Position;
     return f;
 }
Example #7
0
 BaseSprite LoadDonutCase(BaseSprite sprite, string texturedir, XElement part)
 {
     DonutCase c = new DonutCase(this);
     c.Scale = sprite.Scale;
     c.Initialize(Content);
     c.Position = sprite.Position;
     if(sprite.Rot != 0)
         c.Rot = sprite.Rot;
     return c;
 }
Example #8
0
 public override void Initialize(ContentManager Content)
 {
     if (sprite != null)
     {
         return;
     }
     sprite = new Sprite(textureDir);
     sprite.Initialize(Content);
     base.Initialize(Content);
 }
        public List<Sprite> CreateSprites(XElement elements)
        {
            BaseSprite sprite = null;
            var items = elements.Descendants("Items");
            var element = elements.Descendants("CustomProperties").Descendants("Property");

            float layerDepth = 0;
            foreach (var property in element)
            {
                if (property.Attribute("Name") != null)
                {
                    string name = property.Attribute("Name").Value;
                    if (name == "LayerDepth")
                    {
                        layerDepth = float.Parse(property.Descendants("string").First<XElement>().Value, CultureInfo.InvariantCulture);
                    }
                }
            }

            List<Sprite> lsSprites = new List<Sprite>();

            foreach (var item in items)
            {
                var parts = item.Descendants("Item");

                foreach (var part in parts)
                {
                    if (part.Name == "Item")
                    {
                        element = part.Descendants("Position");
                        float posx = float.Parse(element.Elements("X").ElementAt(0).Value, CultureInfo.InvariantCulture);
                        float posy = float.Parse(element.Elements("Y").ElementAt(0).Value, CultureInfo.InvariantCulture);

                        float rot = float.Parse(part.Elements("Rotation").ElementAt(0).Value, CultureInfo.InvariantCulture);

                        element = part.Descendants("Scale");
                        float width = float.Parse(element.Elements("X").ElementAt(0).Value, CultureInfo.InvariantCulture);
                        float height = float.Parse(element.Elements("Y").ElementAt(0).Value, CultureInfo.InvariantCulture);

                        element = part.Descendants("asset_name");
                        string textureDir = element.ElementAt(0).Value;

                        textureDir = "textures\\" + textureDir;

                        bool continueLoad = true;
                        if (GetInterception(textureDir) != null)
                        {
                            SingleTextureToMassTexture s = GetInterception(textureDir);
                            string newTextureDir = s.newTextureDir;
                            string newTextureDirXML = s.newTextureDirXML;

                            sprite = new Sprite(newTextureDir);
                            sprite.Initialize(Content);
                            (sprite as Sprite).CreateFramesFromXML(newTextureDirXML);
                            (sprite as Sprite).CurrentFrame = s.FrameName;
                            (sprite as Sprite).ResetDimensions();
                        }
                        else if (HasObjInterceptor(textureDir))
                        {
                            sprite = new BaseSprite();
                        }
                        else
                        {
                            continueLoad = false;
                            sprite = null;
                            /*
                            try
                            {
                                Texture2D texture = Content.Load<Texture2D>(textureDir);
                                sprite = new Sprite(textureDir);
                                sprite.Initialize(Content);

                            }
                            catch (Exception e)
                            {
                                sprite = null;
                                int k = 0;
                            }*/
                        }

                        if (sprite != null)// && !HasObjInterceptor(sprite.TextureDir))
                        {
                            sprite.Rot = rot;
                            sprite.PosZ = layerDepth;
                            sprite.Position = new Vector2(posx, -posy);
                            sprite.Scale = new Vector2(width, height);

                            if (HasObjInterceptor(textureDir))
                            {
                                AddNode(ObjInterceptor(textureDir)(sprite, textureDir, part));
                            }
                            else
                            {
                                lsSprites.Add(sprite as Sprite);
                            }
                        }

                    }
                }
            }

            return lsSprites;
        }
Example #10
0
        public void AddNode(BaseSprite sprite)
        {
            nodes.Add(sprite);

            nodes.Sort();
        }
Example #11
0
 public AddNodeEvent(BaseSprite objToAdd)
 {
     Obj = objToAdd;
 }
Example #12
0
 public void RemoveNode(BaseSprite sprite)
 {
     nodes.Remove(sprite);
 }
Example #13
-26
 BaseSprite LoadDonut(BaseSprite sprite, string texturedir, XElement part)
 {
     Donut f = new Donut(this);
     f.Initialize(Content);
     f.Rot = sprite.Rot;
     f.Position = sprite.Position;
     return f;
 }