예제 #1
0
        public static ImageAsset GetImageAsset(string rFilename, float rScaleX, float rScaleY)
        {
            App.Log("Media.cs", 2, "media", "Requested image: " + rFilename + " " + rScaleX.ToString() + " " + rScaleY.ToString());

            foreach (var i in Media.ImageList)
            {
                if (i.File == rFilename)
                {
                    if (i.ScaleX == rScaleX && i.ScaleY == rScaleY)
                    {
                        if (Agk.GetImageExists(i.ResourceNumber) == 1)
                        {
                            App.Log("Media.cs", 2, "media", " > found image on " + i.ResourceNumber.ToString());
                            return(i);
                        }
                        else
                        {
                            App.Log("Media.cs", 2, "media", " > found image on " + i.ResourceNumber.ToString() + "but is not valid: reload it");

                            if (System.IO.File.Exists(rFilename))
                            {
                                i.ResourceNumber = Agk.LoadImageResized(rFilename, rScaleX, rScaleY, 0);
                                return(i);
                            }
                        }
                    }
                }
            }

            if (System.IO.File.Exists(rFilename))
            {
                App.Log("Media.cs", 2, "media", " > image not loaded: load it");

                var tImg = Agk.LoadImageResized(rFilename, rScaleX, rScaleY, 0);
                Agk.SetImageWrapU(tImg, 1);
                Agk.SetImageWrapV(tImg, 1);
                var i = new ImageAsset()
                {
                    ResourceNumber = tImg,
                    File           = rFilename,
                    ScaleX         = rScaleX,
                    ScaleY         = rScaleY
                };
                Media.ImageList.Add(i);
                return(i);
            }
            else
            {
                if (rFilename.Contains("media"))
                {
                    //if filename does not include the media folder, we are looking for a generated sprite color image, just return null and keep running
                    //if filename does include media folder, the file is not found and we got problems.
                    App.Log("Media.cs", 5, "error", "ERROR: File not found: " + rFilename + " on Media.GetImageAsset");
                    App.StopRunning(true);
                }
            }

            return(null);
        }