public IntroLayer() { CCSize windowSize = CCDirector.SharedDirector.WinSize; CCSprite tmp = new CCSprite("goblins"); tmp.SetPosition(windowSize.Width / 2, windowSize.Height / 2); AddChild(tmp); String name = @"Content/goblins"; skeletonNode = new CCSkeletonAnimation(name + ".json", name + ".atlas", 1.0f); if (name == "goblins") skeletonNode.setSkin("goblin"); skeletonNode.NodeToWorldTransform(); skeletonNode.setSlotsToSetupPose(); skeletonNode.updateWorldTransform(); skeletonNode.AddAnimation(0, "walk", true, 4); skeletonNode.SetAnimation(0, "walk", true); skeletonNode.Start += Start; skeletonNode.End += End; skeletonNode.Complete += Complete; skeletonNode.Event += Event; skeletonNode.findSlot("head"); skeletonNode.SetPosition(windowSize.Width / 2, windowSize.Height / 2); AddChild(skeletonNode); }
public BackgroundLayer() { // Load the background image into a sprite var backgroundImage = new CCSprite("Images/Background"); // Get the dimensions of the game window var screenSize = CCDirector.SharedDirector.WinSize; // Set the position of the background sprite to the center of the screen backgroundImage.SetPosition(screenSize.Width / 2, screenSize.Height / 2); // Add the background sprite to the layer AddChild(backgroundImage, 0); }
/// <summary> /// Creates a new sprite and adds it to the sprite list & screen. /// </summary> internal void CreateSprite() { // Get the dimensions of the game window var winSize = CCDirector.SharedDirector.WinSize; // Get the new number of sprites on the screen and setup an id & image for the sprite (cycles between the 3 available images) var numSprites = _sprites.Count + 1; var spriteId = "sprite" + numSprites; var spriteImage = "Images/Sprite" + ((numSprites % 3) + 1); // Create a new instance of the sprite, then setup the position, velocity, & zorder var newSprite = new CCSprite(spriteImage); newSprite.SetPosition(_rand.Next(150, (int)(winSize.Width - 150f)), _rand.Next(150, (int)(winSize.Height - 150f))); // Add the new sprite to the sprite list _sprites.Add(spriteId, newSprite); // Add the sprite to the layer AddChild(newSprite); // Set the active sprite to the newly added sprite _curSpriteNumber = numSprites - 1; SetActiveSprite(true); }