Exemple #1
0
        public void Atlas_MissingResource()
        {
            TestRuntime.AssertSystemVersion(PlatformName.iOS, 7, 0, throwIfOtherPlatform: false);
            TestRuntime.AssertSystemVersion(PlatformName.TvOS, 9, 0, throwIfOtherPlatform: false);
            TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 9, throwIfOtherPlatform: false);
            TestRuntime.AssertSystemVersion(PlatformName.WatchOS, 3, 0, throwIfOtherPlatform: false);

            using (var atlas = new SKTextureAtlas()) {
                // that returns a texture, calling 'MissingResource.png' (128 x 128)
                using (var texture = atlas.TextureNamed("ship")) {
                    // this completionHandler is *NOT* optional -> crash if null
                    SKTexture.PreloadTextures(new [] { texture }, CrashAvoider);

                    // this completionHandler is *NOT* optional -> crash if null
                    texture.Preload(CrashAvoider);

                    Assert.That(texture.FilteringMode, Is.EqualTo(SKTextureFilteringMode.Linear), "FilteringMode");

#if !MONOMAC
                    // FIXME: bug in iOS9 - it will randomly return 0,0 (but almost always on the first try)
                    if (!TestRuntime.CheckSystemVersion(PlatformName.iOS, 9, 0, throwIfOtherPlatform: false))
                    {
                        Assert.That(texture.Size, Is.EqualTo(new CGSize(128, 128)), "Size");
                    }
#endif

                    Assert.That(texture.TextureRect, Is.EqualTo(new CGRect(0, 0, 1, 1)), "TextureRect");
                    Assert.False(texture.UsesMipmaps, "UsesMipmaps");
                }
            }
        }
        protected override void LoadSceneAssets()
        {
            SKTextureAtlas atlas = SKTextureAtlas.FromName("Environment");

            // Load archived emitters and create copyable sprites.
            sharedProjectileSparkEmitter = GraphicsUtilities.EmitterNodeWithEmitterNamed("ProjectileSplat");
            sharedSpawnEmitter           = GraphicsUtilities.EmitterNodeWithEmitterNamed("Spawn");

            sharedSmallTree = new Tree(new SKNode[] {
                SKSpriteNode.FromTexture(atlas.TextureNamed("small_tree_base.png")),
                SKSpriteNode.FromTexture(atlas.TextureNamed("small_tree_middle.png")),
                SKSpriteNode.FromTexture(atlas.TextureNamed("small_tree_top.png"))
            }, 25);
            sharedBigTree = new Tree(new SKNode[] {
                SKSpriteNode.FromTexture(atlas.TextureNamed("big_tree_base.png")),
                SKSpriteNode.FromTexture(atlas.TextureNamed("big_tree_middle.png")),
                SKSpriteNode.FromTexture(atlas.TextureNamed("big_tree_top.png"))
            }, 150);
            sharedBigTree.FadeAlpha = true;
            sharedLeafEmitterA      = GraphicsUtilities.EmitterNodeWithEmitterNamed("Leaves_01");
            sharedLeafEmitterB      = GraphicsUtilities.EmitterNodeWithEmitterNamed("Leaves_02");

            // Load the tiles that make up the ground layer.
            LoadWorldTiles();

            // Load assets for all the sprites within this scene.
            Cave.LoadSharedAssetsOnce();
            HeroCharacter.LoadSharedAssetsOnce();
            Archer.LoadSharedAssetsOnce();
            Warrior.LoadSharedAssetsOnce();
            Goblin.LoadSharedAssetsOnce();
            Boss.LoadSharedAssetsOnce();
        }
        public static void LoadSharedAssetsOnce()
        {
                        #if __IOS__
            var whiteColor = UIColor.White;
                        #else
            NSColor whiteColor = null;
            new NSObject().InvokeOnMainThread(() => {
                whiteColor = NSColor.White;
            });
                        #endif

            SKTextureAtlas atlas = SKTextureAtlas.FromName("Environment");

            sharedIdleAnimationFrames   = GraphicsUtilities.LoadFramesFromAtlas("Goblin_Idle", "goblin_idle_", DefaultNumberOfIdleFrames);
            sharedWalkAnimationFrames   = GraphicsUtilities.LoadFramesFromAtlas("Goblin_Walk", "goblin_walk_", DefaultNumberOfWalkFrames);
            sharedAttackAnimationFrames = GraphicsUtilities.LoadFramesFromAtlas("Goblin_Attack", "goblin_attack_", GoblinAttackFrames);
            sharedGetHitAnimationFrames = GraphicsUtilities.LoadFramesFromAtlas("Goblin_GetHit", "goblin_getHit_", GoblinGetHitFrames);
            sharedDeathAnimationFrames  = GraphicsUtilities.LoadFramesFromAtlas("Goblin_Death", "goblin_death_", GoblinDeathFrames);
            sharedDamageEmitter         = GraphicsUtilities.EmitterNodeWithEmitterNamed("Damage");
            sharedDeathSplort           = SKSpriteNode.FromTexture(atlas.TextureNamed("minionSplort.png"));
            sharedDamageAction          = SKAction.Sequence(new [] {
                SKAction.ColorizeWithColor(whiteColor, 1, 0),
                SKAction.WaitForDuration(0.75f),
                SKAction.ColorizeWithColorBlendFactor(0, 0.1)
            });
        }
        void LoadOdrsResources()
        {
            request = new NSBundleResourceRequest(new[] { "odr" });
            request.BeginAccessingResources(error => {
                NSOperationQueue.MainQueue.AddOperation(() => {
                    if (error != null)
                    {
                        Console.WriteLine("Error occurred: {0}", error.LocalizedDescription);
                        return;
                    }

                    SKTextureAtlas atlas = SKTextureAtlas.FromName("Atlas");
                    if (atlas == null)
                    {
                        Throw("Failed to load on-demand resource Atlas");
                    }

                    var alertController = UIAlertController.Create("Success", "All types of resources loaded OK", UIAlertControllerStyle.Alert);

                    // Create the action.
                    var acceptAction = UIAlertAction.Create("OK", UIAlertActionStyle.Default, null);

                    // Add the actions.
                    alertController.AddAction(acceptAction);
                    PresentViewController(alertController, true, null);

                    Console.WriteLine("All types of resources loaded OK");
                });
            });
        }
Exemple #5
0
        public void Atlas_MissingResource()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                Assert.Ignore("Requires iOS7");
            }

            using (var atlas = new SKTextureAtlas()) {
                // that returns a texture, calling 'MissingResource.png' (128 x 128)
                using (var texture = atlas.TextureNamed("ship")) {
                    // this completionHandler is *NOT* optional -> crash if null
                    SKTexture.PreloadTextures(new [] { texture }, CrashAvoider);

                    // this completionHandler is *NOT* optional -> crash if null
                    texture.Preload(CrashAvoider);

                    Assert.That(texture.FilteringMode, Is.EqualTo(SKTextureFilteringMode.Linear), "FilteringMode");

                    // FIXME: bug in iOS9 - it will randomly return 0,0 (but almost always on the first try)
                    if (!UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
                    {
                        Assert.That(texture.Size, Is.EqualTo(new SizeF(128, 128)), "Size");
                    }

                    Assert.That(texture.TextureRect, Is.EqualTo(new RectangleF(0, 0, 1, 1)), "TextureRect");
                    Assert.False(texture.UsesMipmaps, "UsesMipmaps");
                }
            }
        }
Exemple #6
0
        public MapNode(Map map)
        {
            this.map = map;
            Name     = "Map";

            UserInteractionEnabled = true;

            int idx = 0;

            atlas = SKTextureAtlas.FromName("TileImages");
            foreach (var tid in map.TIDs)
            {
                Tile t = map.TIDToTile [tid];
                CoreGraphics.CGPoint position = map.PositionToPoint(map.IndexToPosition(idx));

                SKTexture    tex  = atlas.TextureNamed(t.ImageName);
                SKSpriteNode node = SKSpriteNode.FromTexture(tex);
                node.UserInteractionEnabled = false;
                node.Position  = position;
                node.ZPosition = idx;

                node.AnchorPoint = new CoreGraphics.CGPoint(0.5, 0);
                AddChild(node);

                idx++;
            }

            var nc = NSNotificationCenter.DefaultCenter;

            nc.AddObserver((NSString)InventoryComponent.ItemCollectedNotification, HandleItemCollected);
            nc.AddObserver((NSString)InventoryComponent.ItemDroppedNotification, HandleItemDropped);
        }
        public new static void LoadSharedAssetsOnce()
        {
                        #if __IOS__
            var whiteColor = UIColor.White;
                        #else
            NSColor whiteColor = null;
            new NSObject().InvokeOnMainThread(() => {
                whiteColor = NSColor.White;
            });
                        #endif

            SKTextureAtlas atlas = SKTextureAtlas.FromName("Environment");

            sharedProjectile             = SKSpriteNode.FromTexture(atlas.TextureNamed("warrior_throw_hammer.png"));
            sharedProjectile.PhysicsBody = SKPhysicsBody.CreateCircularBody(ProjectileCollisionRadius);
            sharedProjectile.Name        = "Projectile";
            sharedProjectile.PhysicsBody.CategoryBitMask    = (uint)ColliderType.Projectile;
            sharedProjectile.PhysicsBody.CollisionBitMask   = (uint)ColliderType.Wall;
            sharedProjectile.PhysicsBody.ContactTestBitMask = sharedProjectile.PhysicsBody.CollisionBitMask;

            sharedProjectileEmitter     = GraphicsUtilities.EmitterNodeWithEmitterNamed("WarriorProjectile");
            sharedIdleAnimationFrames   = GraphicsUtilities.LoadFramesFromAtlas("Warrior_Idle", "warrior_idle_", WarriorIdleFrames);
            sharedWalkAnimationFrames   = GraphicsUtilities.LoadFramesFromAtlas("Warrior_Walk", "warrior_walk_", DefaultNumberOfWalkFrames);
            sharedAttackAnimationFrames = GraphicsUtilities.LoadFramesFromAtlas("Warrior_Attack", "warrior_attack_", WarriorThrowFrames);
            sharedGetHitAnimationFrames = GraphicsUtilities.LoadFramesFromAtlas("Warrior_GetHit", "warrior_getHit_", WarriorGetHitFrames);
            sharedDeathAnimationFrames  = GraphicsUtilities.LoadFramesFromAtlas("Warrior_Death", "warrior_death_", WarriorDeathFrames);
            sharedDamageAction          = SKAction.Sequence(new [] {
                SKAction.ColorizeWithColor(whiteColor, 10, 0),
                SKAction.WaitForDuration(0.5),
                SKAction.ColorizeWithColorBlendFactor(0, 0.25)
            });
        }
        void LoadWorldTiles()
        {
            var sw = new Stopwatch();

            sw.Start();

            Console.WriteLine("Loading world tiles");

            SKTextureAtlas tileAtlas = SKTextureAtlas.FromName("Tiles");

            backgroundTiles = new SKNode[1024];
            for (int y = 0; y < WorldTileDivisor; y++)
            {
                for (int x = 0; x < WorldTileDivisor; x++)
                {
                    int tileNumber = (y * WorldTileDivisor) + x;

                    var          textureName = string.Format("tile{0}.png", tileNumber);
                    var          texture     = tileAtlas.TextureNamed(textureName);
                    SKSpriteNode tileNode    = SKSpriteNode.FromTexture(texture);

                    int xPos     = x * WorldTileSize - WorldCenter;
                    var yPos     = WorldSize - y * WorldTileSize - WorldCenter;
                    var position = new CGPoint(xPos, yPos);
                    tileNode.Position            = position;
                    tileNode.ZPosition           = -1;
                    tileNode.BlendMode           = SKBlendMode.Replace;
                    backgroundTiles [tileNumber] = tileNode;
                }
            }
            Console.WriteLine("Loaded all world tiles in {0} seconds", sw.Elapsed);
            sw.Stop();
        }
Exemple #9
0
 SKTexture[] TextureArrayFromAtlas(SKTextureAtlas atlas, string name, int row)
 {
     SKTexture[] textures = new SKTexture[8];
     for (int i = 0; i < 8; i++)
     {
         textures[i] = atlas.TextureNamed(String.Format("{0}-{1}-{2}", name, row, i + 1));
     }
     return(textures);
 }
        public Goblin(CGPoint position)
            : base(SKTextureAtlas.FromName("Goblin_Idle").TextureNamed("goblin_idle_0001.png"), position)
        {
            MovementSpeed = Velocity * (float)Random.NextDouble();
            SetScale(MinGoblinSize + (float)Random.NextDouble() * GoblinSizeVariance);
            ZPosition = -0.25f;
            Name      = "Enemy";

            // Make it AWARE!
            Intelligence = new ChaseAI(this);
        }
Exemple #11
0
        public static SKTexture[] LoadFramesFromAtlas(string atlasName, string baseFileName, int numberOfFrames)
        {
            var frames = new SKTexture[numberOfFrames];

            SKTextureAtlas atlas = SKTextureAtlas.FromName(atlasName);

            for (int i = 0; i < numberOfFrames; i++)
            {
                int       imageIndex = i + 1;           // because starts from one
                string    fileName   = string.Format("{0}{1:D4}.png", baseFileName, imageIndex);
                SKTexture texture    = atlas.TextureNamed(fileName);
                frames [i] = texture;
            }

            return(frames);
        }
        void Initialize(CGPoint position)
        {
            var atlas = SKTextureAtlas.FromName("Environment");

            ShadowBlob = new SKSpriteNode(atlas.TextureNamed("blobShadow.png"))
            {
                ZPosition = -1f
            };

            Position = position;

            Health         = 100f;
            MovementSpeed  = Velocity;
            Animated       = true;
            AnimationSpeed = 1f / 28f;

            ConfigurePhysicsBody();
        }
        public Boss(CGPoint position)
            : base(SKTextureAtlas.FromName("Boss_Idle").TextureNamed("boss_idle_0001.png"), position)
        {
            MovementSpeed  = Velocity * 0.35f;
            AnimationSpeed = 1f / 35f;

            ZPosition = -0.25f;
            Name      = "Boss";

            Attacking = false;

            // Make it AWARE!
            var intelligence = new ChaseAI(this);

            intelligence.ChaseRadius    = BossChaseRadius;
            intelligence.MaxAlertRadius = BossChaseRadius * 4f;
            Intelligence = intelligence;
        }
Exemple #14
0
        public static void LoadSharedAssetsOnce()
        {
                        #if __IOS__
            var whiteColor = UIColor.White;
                        #else
            NSColor whiteColor = null;
            new NSObject().InvokeOnMainThread(() => {
                whiteColor = NSColor.White;
            });
                        #endif

            SKTextureAtlas atlas = SKTextureAtlas.FromName("Environment");

            SKEmitterNode fire = GraphicsUtilities.EmitterNodeWithEmitterNamed("CaveFire");
            fire.ZPosition = 1;

            SKEmitterNode smoke = GraphicsUtilities.EmitterNodeWithEmitterNamed("CaveFireSmoke");

            var sKNode = new SKNode();
            sKNode.Add(fire);
            sKNode.Add(smoke);
            SKNode torch = sKNode;

            sharedCaveBase = SKSpriteNode.FromTexture(atlas.TextureNamed("cave_base.png"));

            // Add two torches either side of the entrance.
            torch.Position = new CGPoint(83, 83);
            sharedCaveBase.AddChild(torch);
            var torchB = (SKNode)torch.Copy();
            torchB.Position = new CGPoint(-83, 83);
            sharedCaveBase.AddChild(torchB);

            sharedCaveTop     = SKSpriteNode.FromTexture(atlas.TextureNamed("cave_top.png"));
            sharedDeathSplort = SKSpriteNode.FromTexture(atlas.TextureNamed("cave_destroyed.png"));

            sharedDamageEmitter = GraphicsUtilities.EmitterNodeWithEmitterNamed("CaveDamage");
            sharedDeathEmitter  = GraphicsUtilities.EmitterNodeWithEmitterNamed("CaveDeathSmoke");

            sharedDamageAction = SKAction.Sequence(new [] {
                SKAction.ColorizeWithColor(whiteColor, 1, 0),
                SKAction.WaitForDuration(0.25),
                SKAction.ColorizeWithColorBlendFactor(0, 0.1),
            });
        }
Exemple #15
0
        public CharacterSpriteComponent(string spriteAtlasFilename, GKEntity entity)
        {
            // Setup the idle actions
            SKTextureAtlas atlas = SKTextureAtlas.FromName(spriteAtlasFilename);

            idleNorthWestAction = SKAction.AnimateWithTextures(new SKTexture[] { atlas.TextureNamed(spriteAtlasFilename + "-1-0") }, 1.0);
            idleSouthEastAction = SKAction.AnimateWithTextures(new SKTexture[] { atlas.TextureNamed(spriteAtlasFilename + "-3-0") }, 1.0);

            // Setup the walking action
            SKTexture[] textArray = TextureArrayFromAtlas(atlas, spriteAtlasFilename, 1);
            walkNorthWestAction = SKAction.AnimateWithTextures(textArray, 0.1);
            textArray           = TextureArrayFromAtlas(atlas, spriteAtlasFilename, 3);
            walkSouthEastAction = SKAction.AnimateWithTextures(textArray, 0.1);

            Sprite                        = new EntityNode();
            Sprite.Texture                = atlas.TextureNamed(spriteAtlasFilename + "-1-0");
            Sprite.Size                   = new CoreGraphics.CGSize(64f, 64f);
            Sprite.AnchorPoint            = new CoreGraphics.CGPoint(0.5f, 0.0f);
            Sprite.UserInteractionEnabled = true;
            ((EntityNode)Sprite).Entity   = entity;
        }
Exemple #16
0
        public static Entity CreateItem(EntityModel model)
        {
            var item = new Entity {
                Name  = model.Name,
                Id    = model.Id,
                Model = model
            };

            if (atlas == null)
            {
                atlas = SKTextureAtlas.FromName("Items");
            }
            var spriteComp = new ItemSpriteComponent(atlas.TextureNamed(model.TextureName), item);

            item.AddComponent(spriteComp);

            var clickableComp = new ClickableComponent();

            item.AddComponent(clickableComp);

            var lookableComp = new LookableComponent();

            item.AddComponent(lookableComp);

            var collectableComp = new CollectibleComponent();

            item.AddComponent(collectableComp);

            var giveableComp = new GiveableComponent();

            item.AddComponent(giveableComp);

            var useableComp = new UseableComponent();

            item.AddComponent(useableComp);

            items [item.Id] = item;

            return(item);
        }
Exemple #17
0
        public void Empty()
        {
            TestRuntime.AssertSystemVersion(PlatformName.iOS, 7, 0, throwIfOtherPlatform: false);
            TestRuntime.AssertSystemVersion(PlatformName.TvOS, 9, 0, throwIfOtherPlatform: false);
            TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 9, throwIfOtherPlatform: false);
            TestRuntime.AssertSystemVersion(PlatformName.WatchOS, 3, 0, throwIfOtherPlatform: false);

            using (var atlas = new SKTextureAtlas()) {
                Assert.That(atlas.TextureNames, Is.Empty, "TextureNames");

                // this completionHandler is *NOT* optional -> crash if null
                SKTextureAtlas.PreloadTextures(new [] { atlas }, CrashAvoider);

                // this completionHandler is *NOT* optional -> crash if null
                atlas.Preload(CrashAvoider);

                // that returns a texture, calling 'MissingResource.png' (128 x 128)
                using (var texture = atlas.TextureNamed("ship")) {
                    Assert.That(texture.Handle, Is.Not.EqualTo(IntPtr.Zero), "valid");
                }
            }
        }
Exemple #18
0
        public void Empty()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                Assert.Ignore("Requires iOS7");
            }

            using (var atlas = new SKTextureAtlas()) {
                Assert.That(atlas.TextureNames, Is.Empty, "TextureNames");

                // this completionHandler is *NOT* optional -> crash if null
                SKTextureAtlas.PreloadTextures(new [] { atlas }, CrashAvoider);

                // this completionHandler is *NOT* optional -> crash if null
                atlas.Preload(CrashAvoider);

                // that returns a texture, calling 'MissingResource.png' (128 x 128)
                using (var texture = atlas.TextureNamed("ship")) {
                    Assert.That(texture.Handle, Is.Not.EqualTo(IntPtr.Zero), "valid");
                }
            }
        }
Exemple #19
0
 public Archer(CGPoint position, Player player)
     : base(SKTextureAtlas.FromName("Archer_Idle").TextureNamed("archer_idle_0001.png"), position, player)
 {
 }
 public Warrior(CGPoint position, Player player)
     : base(SKTextureAtlas.FromName("Warrior_Idle").TextureNamed("warrior_idle_0001.png"), position, player)
 {
 }