public override void TouchesBegan(NSSet touches, UIEvent evt) { // Called when a touch begins // control player motion var moveRight = SKAction.RepeatActionForever(SKAction.MoveBy(75.0f, 0, 2.0f)); var moveLeft = SKAction.RepeatActionForever(SKAction.MoveBy(-75.0f, 0, 2.0f)); base.TouchesBegan(touches, evt); var touch = (UITouch)touches.AnyObject; playerMove(touch); // detects left and right screen taps, moves player accordingly void playerMove(UITouch location) { if (touch.LocationInNode(this).X > (Frame.Width / 2)) { playerObject.RunAction(moveRight); } if (touch.LocationInNode(this).X < (Frame.Width / 2)) { playerObject.RunAction(moveLeft); } Console.WriteLine(touch.LocationInNode(this)); } }
public override void TouchesBegan(NSSet touches, UIEvent evt) { // Called when a touch begins foreach (var touch in touches) { UITouch touchc = touches.AnyObject as UITouch; // Check click var locationc = touchc.LocationInNode(this); var checkX = touchc.LocationInView(View).X; var checkY = touchc.LocationInView(View).Y; // other coordinate system //var checkX = ((UITouch)touchc).LocationInNode(this).X; //var checkY = ((UITouch)touchc).LocationInNode(this).Y; // Get Sprite Node at current location var nodeAtLocation = GetNodeAtPoint(locationc); if (nodeAtLocation.Name == "cancelSpark") { ReleaseInfoText(); } else { if (nodeAtLocation.Name != "infoNode" && nodeAtLocation.Name != "infoLabel") { // If the info button is clicked change background if (nodeAtLocation.Name == "info" || nodeAtLocation.Name == "navSprite") { infoTouch = true; // Activate information background if (switchInfo == false) { //setInfoText(); container.Alpha = 1f; switchInfo = true; SKAction seqTextureInfo = SKAction.SetTexture(SKTexture.FromImageNamed(("inforeverse"))); infoSprite.RunAction((seqTextureInfo)); } // Deactivate information background else { container.Alpha = 0f; switchInfo = false; SKAction seqTextureInfoNormal = SKAction.SetTexture(SKTexture.FromImageNamed(("info"))); infoSprite.RunAction((seqTextureInfoNormal)); } } } } } }
// Remove the Info Text (fade out) private void ReleaseInfoText() { SKAction actionOut = SKAction.FadeOutWithDuration(0.2); infoLabel1.RemoveAllActions(); infoLabel2.RemoveAllActions(); infoLabel3.RemoveAllActions(); infoLabel4.RemoveAllActions(); infoLabel5.RemoveAllActions(); infoLabel6.RemoveAllActions(); infoLabel7.RemoveAllActions(); infoNode.RemoveAllActions(); infoNode2.RemoveAllActions(); infoNode3.RemoveAllActions(); cancelSpark.RemoveAllActions(); teatimeSprite.RemoveAllActions(); infoLabel1.RunAction(actionOut); infoLabel2.RunAction(actionOut); infoLabel3.RunAction(actionOut); infoLabel4.RunAction(actionOut); infoLabel5.RunAction(actionOut); infoLabel6.RunAction(actionOut); infoLabel7.RunAction(actionOut); infoNode.RunAction(actionOut); infoNode2.RunAction(actionOut); infoNode3.RunAction(actionOut); cancelSpark.RunAction(actionOut); teatimeSprite.RunAction(actionOut); }
public override void TouchesBegan(MonoTouch.Foundation.NSSet touches, MonoTouch.UIKit.UIEvent evt) { foreach (UITouch touch in touches) { var location = touch.LocationInNode (this); if (_nbPictures+1 > _maxPictures) { var tab = _kaloos.ToArray (); RemoveChildren (tab); _kaloos.Clear (); _nbPictures = 0; } _nbPictures++; string currentPicture = _pictures[_nbPictures % 3]; var sprite = new SKSpriteNode (currentPicture) { Position = location, }; _kaloos.Add(sprite); var rotation = (float)Math.PI; double sec = 1; var action = SKAction.RotateByAngle (rotation,sec); sprite.RunAction (SKAction.RepeatActionForever (action)); AddChild (sprite); } }
public void ShowScanAction() { var size = base.Size; _scanText1 = new SKLabelNode("AppleSDGothicNeo-Regular") { Text = "Move your phone", FontSize = 30, Position = new CGPoint(size.Width / 2, 100), Color = UIColor.White, }; AddChild(_scanText1); _scanText2 = new SKLabelNode("AppleSDGothicNeo-Regular") { Text = "to find a surface", FontSize = 30, Position = new CGPoint(size.Width / 2, 70), Color = UIColor.White, }; AddChild(_scanText2); _phone = SKSpriteNode.FromImageNamed("phone_scaled"); _phone.Position = new CGPoint(size.Width / 2, 190); var circle = UIBezierPath.FromRoundedRect(new CGRect(new CGPoint(size.Width / 2 - 20, 190), new CGSize(40, 40)), 20); var moveAlongPath = SKAction.RepeatActionForever(SKAction.FollowPath(circle.CGPath, false, false, 2.0)); _phone.RunAction(moveAlongPath); AddChild(_phone); ScanActionShowing = true; ScanActionFinished = false; }
void animateobstacle4() { var textures = Enumerable.Range(1, 4).Select( (i) => SKTexture.FromImageNamed(String.Format("trash-{0}", i))).ToArray(); obstacleflame4 = SKAction.RepeatActionForever(SKAction.AnimateWithTextures(textures, 0.1)); obstacle4.RunAction(obstacleflame4); }
void animateEnemy() { var textures = Enumerable.Range(1, 4).Select( (i) => SKTexture.FromImageNamed(String.Format("walker-{0}", i))).ToArray(); enemyAnimate = SKAction.RepeatActionForever(SKAction.AnimateWithTextures(textures, 0.1)); enemy.RunAction(enemyAnimate); }
public void nodeScaling(SKSpriteNode scaled) { var up = SKAction.ScaleBy(0.8f, 0.9f); //var down = SKAction.ScaleBy (0.8f, 0.5f); var seq = SKAction.Sequence(new SKAction[] { up, up.ReversedAction }); //({up,down}); var fort = SKAction.RepeatActionForever(seq); scaled.RunAction(fort); }
/// <summary> /// Подсвечивание выбранного камешка заменой текстуры в спрайте /// </summary> /// <param name="gem">Камешек на подстветку.</param> private void ShowSelectionIndicator(Gem gem) { // Открепляем спрайт от родителя, если он есть if (selectedSprite.Parent != null) { selectedSprite.RemoveFromParent(); } SKSpriteNode sprite = gem.Sprite; SKTexture texture = SKTexture.FromImageNamed(gem.GetSelectedSpriteName()); selectedSprite.Size = new CGSize(gemCellWidth, gemCellHeight); selectedSprite.RunAction(SKAction.SetTexture(texture)); // "Подсветка" добавляется в качестве потомка к основному спрайту камешка sprite.AddChild(selectedSprite); selectedSprite.Alpha = 1.0f; }
public Pipe(CGPoint position, bool isRotated = false) { Sprite = new SKSpriteNode("Pipe") { Position = position, XScale = 0.5f, YScale = 1.5f }; Sprite.PhysicsBody = SKPhysicsBody.Create(Sprite.Texture, Sprite.Size); Sprite.PhysicsBody.AffectedByGravity = false; Sprite.PhysicsBody.CategoryBitMask = (uint)PhysicsCategoryEnum.Pipe; Sprite.PhysicsBody.UsesPreciseCollisionDetection = true; Sprite.RunAction(SKAction.RepeatActionForever(SKAction.MoveBy(-100, 0, 1))); if (isRotated) { Sprite.RunAction(SKAction.RotateByAngle(NMath.PI, 0)); } }
// definition of player walking animation void animatePlayer() { var textures = Enumerable.Range(1, 4).Select( (i) => SKTexture.FromImageNamed(String.Format("Stumbler-{0}", i))).ToArray(); playerAnimate = SKAction.RepeatActionForever(SKAction.AnimateWithTextures(textures, 0.1)); playerObject.RunAction(playerAnimate); }
void ShowEndScreen() { gameIsComplete = true; // Add confettis SCNMatrix4 particlePosition = SCNMatrix4.CreateTranslation(0f, 8f, 0f); GameView.Scene.AddParticleSystem(confetti, particlePosition); // Congratulation title SKSpriteNode congrat = SKSpriteNode.FromImageNamed("Images/congratulations.png"); congrat.Position = new CGPoint(GameView.Bounds.Width / 2, GameView.Bounds.Height / 2); SKScene overlay = GameView.OverlayScene; congrat.XScale = congrat.YScale = 0; congrat.Alpha = 0; congrat.RunAction(SKAction.Group(new [] { SKAction.FadeInWithDuration(0.25), SKAction.Sequence(new [] { SKAction.ScaleTo(.55f, 0.25), SKAction.ScaleTo(.3f, 0.1), }) })); // Panda Image SKSpriteNode congratPanda = SKSpriteNode.FromImageNamed("Images/congratulations_pandaMax.png"); congratPanda.Position = new CGPoint(GameView.Bounds.Width / 2f, GameView.Bounds.Height / 2f - 90f); congratPanda.AnchorPoint = new CGPoint(.5f, 0f); congratPanda.XScale = congratPanda.YScale = 0f; congratPanda.Alpha = 0; congratPanda.RunAction(SKAction.Sequence(new [] { SKAction.WaitForDuration(.5f), SKAction.Sequence(new [] { SKAction.ScaleTo(.5f, 0.25), SKAction.ScaleTo(.4f, 0.1) }) })); overlay.AddChild(congratPanda); overlay.AddChild(congrat); // Stop music GameView.Scene.RootNode.RemoveAllAudioPlayers(); // Play the congrat sound. GameView.Scene.RootNode.AddAudioPlayer(SCNAudioPlayer.FromSource(victoryMusic)); // Animate the camera forever DispatchQueue.MainQueue.DispatchAfter(new DispatchTime(DispatchTime.Now, 1 * NanoSecondsPerSeond), () => { cameraYHandle.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0f, -1f, 0f, 3.0))); cameraXHandle.RunAction(SCNAction.RotateTo(-(float)Math.PI / 4f, 0f, 0f, 5.0)); }); }
void AddAnimatedAnchor () { SKSpriteNode animatedSprite = new SKSpriteNode ("Art/rocket.png") { Position = new CGPoint (Scene.Frame.GetMidX () + 200, Scene.Frame.GetMidY ()), AnchorPoint = CGPoint.Empty }; Scene.AddChild (animatedSprite); AddAnchorDotToSprite (animatedSprite); animatedSprite.RunAction (NewAnimateAnchorAction ()); }
public void Action(SKScene sceen, CGPoint location) { node.Position = location; sceen.AddChild(node); // 繰り返しの場合 //SKAction* forever = [SKAction repeatActionForever: walk]; //[walker runAction:forever]; node.RunAction(action, () => { node.RemoveFromParent(); }); }
private void MoveToUpFromCenterClear() { spriteTopBg.RemoveAllActions(); spriteTop.RemoveAllActions(); spriteBelowBg.RemoveAllActions(); spriteBelow.RemoveAllActions(); navSpriteTop.RemoveAllActions(); navLabelTop.RemoveAllActions(); navSpriteBottom.RemoveAllActions(); navLabelBottom.RemoveAllActions(); SKAction actionTop = SKAction.MoveToY((View.Frame.Height * 1.5f) - 60, 0.2); SKAction actionBelow = SKAction.MoveToY((View.Frame.Height / 2) - 60, 0.2); SKAction actionBelowLabel = SKAction.MoveToY(View.Frame.Height - 100, 0.2); SKAction actionTopLabel = SKAction.MoveToY(View.Frame.Height - 40, 0.2); spriteTopBg.RunAction(actionTop); spriteTop.RunAction(actionTop); spriteBelowBg.RunAction(actionBelow); spriteBelow.RunAction(actionBelow); navSpriteTop.RunAction(actionTopLabel); navLabelTop.RunAction(actionTopLabel); navSpriteBottom.RunAction(actionBelowLabel); navLabelBottom.RunAction(actionBelowLabel); gameMode = 1; }
void AddAnimatedAnchor() { SKSpriteNode animatedSprite = new SKSpriteNode("Art/rocket.png") { Position = new CGPoint(Scene.Frame.GetMidX() + 200, Scene.Frame.GetMidY()), AnchorPoint = CGPoint.Empty }; Scene.AddChild(animatedSprite); AddAnchorDotToSprite(animatedSprite); animatedSprite.RunAction(NewAnimateAnchorAction()); }
public override void TouchesBegan(MonoTouch.Foundation.NSSet touches, MonoTouch.UIKit.UIEvent evt) { foreach (UITouch touch in touches) { var location = touch.LocationInNode (this); var sprite = new SKSpriteNode ("Spaceship") { Position = location, }; var action = SKAction.RotateByAngle ((float)Math.PI, 1); sprite.RunAction (SKAction.RepeatActionForever (action)); AddChild (sprite); } }
/// <summary> /// Анимация перемещения камешков /// </summary> /// <param name="swap">Объект с камешками на обмен</param> /// <param name="swapIsValid">Индикатор того, что своп возможен</param> public void Animate(Swap swap, bool swapIsValid) { SKSpriteNode spriteA = swap.GemA.Sprite; SKSpriteNode spriteB = swap.GemB.Sprite; // Спрайт А "приподнимаем", чтобы создать впечатление, что он пролетает над камешком В spriteA.ZPosition = 100; spriteB.ZPosition = 90; // Анимация камешка А SKAction moveA = SKAction.MoveTo(spriteB.Position, Properties.SwapAnimationDuration / 1000f); moveA.TimingMode = SKActionTimingMode.EaseOut; //Анимация камешка B SKAction moveB = SKAction.MoveTo(spriteA.Position, Properties.SwapAnimationDuration / 1000f); moveB.TimingMode = SKActionTimingMode.EaseOut; if (swapIsValid) { spriteA.RunAction(moveA); spriteB.RunAction(moveB); // Проигрываем звук обмена RunAction(swapSound); } else { spriteA.RunAction(SKAction.Sequence(moveA, moveB)); spriteB.RunAction(SKAction.Sequence(moveB, moveA)); // Проигрываем звук ошибки RunAction(errorSound); } }
public override void TouchesBegan(Foundation.NSSet touches, UIEvent evt) { foreach (UITouch touch in touches) { var location = touch.LocationInNode(this); var sprite = new SKSpriteNode("Spaceship") { Position = location, }; var action = SKAction.RotateByAngle((float)Math.PI, 1); sprite.RunAction(SKAction.RepeatActionForever(action)); AddChild(sprite); } }
/// <summary> /// Анимация падения камешков на пустые места /// </summary> /// <param name="gemLists">Списки камешков перемещенных в модели, столбцами</param> public void AnimateFallingGemsIn(List <GemList> gemLists) { foreach (GemList gems in gemLists) { foreach (Gem gem in gems) { CGPoint newPosition = GetPositionFromRowAndColumn(gem.Row, gem.Column); SKSpriteNode sprite = gem.Sprite; SKAction action = SKAction.MoveTo(newPosition, Properties.FallAnimationDuration / 1000f); action.TimingMode = SKActionTimingMode.EaseOut; sprite.RunAction(action); } } }
void updateHUDFor(Player player, HUDState state, string message = null) { int playerIndex = players.IndexOf(player); SKSpriteNode avatar = hudAvatars [playerIndex]; avatar.RunAction(SKAction.Sequence(new [] { SKAction.FadeAlphaTo(1f, 1), SKAction.FadeAlphaTo(0.2f, 1), SKAction.FadeAlphaTo(1f, 1) })); SKLabelNode label = hudLabels [playerIndex]; float heartAlpha = 1f; switch (state) { case HUDState.Local: label.Text = "ME"; break; case HUDState.Connecting: heartAlpha = 0.25f; label.Text = message ?? "AVAILABLE"; break; case HUDState.Disconnected: avatar.Alpha = 0.5f; heartAlpha = 0.1f; label.Text = "NO PLAYER"; break; case HUDState.Connected: label.Text = message ?? "CONNECTED"; break; default: throw new NotImplementedException(); } for (int i = 0; i < player.LivesLeft; i++) { SKSpriteNode heart = hudLifeHeartArrays [playerIndex] [i]; heart.Alpha = heartAlpha; } }
void RunNextStep(SKSpriteNode sprite) { if (currentWalk.Count == 0) { return; } List <SKAction> actions = new List <SKAction> (); // Pull the next step off the queue actions.Add(currentWalk.Dequeue()); actions.Add(SKAction.Run(() => { RunNextStep(sprite); })); sprite.RunAction(SKAction.Sequence(actions.ToArray())); }
public override void MouseDown(NSEvent theEvent) { // Called when a mouse click occurs var location = theEvent.LocationInNode(this); SKSpriteNode sprite = SKSpriteNode.FromImageNamed("person"); //var sprite = SKSpriteNode.FromImageNamed(NSBundle.MainBundle.PathForResource("Spaceship", "png")); sprite.Position = location; sprite.SetScale(10); var action = SKAction.MoveBy(2, 2, 0.1); sprite.RunAction(SKAction.RepeatActionForever(action)); //sprite.RunAction(SKAction.RepeatActionForever(action)); AddChild(sprite); }
/// <summary> /// Анимация бонуса Бомба /// </summary> /// <param name="bomb">Бомба.</param> public void AnimateBomb(Gem bomb) { CGSize initialSize = new CGSize(gemCellWidth, gemCellHeight); CGSize newSize = new CGSize(gemCellWidth * (Properties.BombBlastRadius * 2 + 1), gemCellHeight * (Properties.BombBlastRadius * 2 + 1)); CGPoint initialPosition = GetPositionFromRowAndColumn(bomb.Row, bomb.Column); SKSpriteNode sprite = SKSpriteNode.FromImageNamed("bomb_blast"); sprite.Size = initialSize; sprite.Position = initialPosition; sprite.ZPosition = 110; SKAction resizeSprite = SKAction.ResizeTo(newSize, Properties.LineDestructionDuration / 1000f); gemLayer.AddChild(sprite); sprite.RunAction(SKAction.Sequence(resizeSprite, SKAction.RemoveFromParent())); }
protected override void CreateSceneContents() { base.CreateSceneContents (); SKTexture[] walkFrames = LoadFrames ("Art/warrior_walk_", 28); SKSpriteNode sprite = new SKSpriteNode (walkFrames [0]) { Position = new PointF (Scene.Frame.GetMidX (), Scene.Frame.GetMidY ()) }; Scene.AddChild (sprite); //Cycle through the frame var animation = SKAction.AnimateWithTextures (walkFrames, 1.0f / 28, true, false); sprite.RunAction (SKAction.RepeatActionForever (animation)); Scene.AddDescription ("This sprite is animating through a series of texture images.", new PointF (Scene.Frame.GetMidX (), 100)); }
public override void TouchesBegan(NSSet touches, UIEvent evt) { // Called when a touch begins foreach (UITouch touch in touches) { var location = touch.LocationInNode(this); var sprite = new SKSpriteNode("Spaceship") { Position = location, XScale = 0.5f, YScale = 0.5f }; var action = SKAction.RotateByAngle(NMath.PI, 1.0); sprite.RunAction(SKAction.RepeatActionForever(action)); AddChild(sprite); } }
public override void TouchesBegan(NSSet touches, UIEvent evt) { // Called when a touch begins foreach (var touch in touches) { var location = ((UITouch)touch).LocationInNode (this); var sprite = new SKSpriteNode ("Spaceship") { Position = location, XScale = 0.4f, YScale = 0.4f }; var action = SKAction.RotateByAngle ((float)Math.PI, 1.0); sprite.RunAction (SKAction.RepeatActionForever (action)); AddChild (sprite); } }
public override void PerformDeath() { RemoveAllActions(); SKSpriteNode splort = (SKSpriteNode)deathSplort.Copy(); splort.ZPosition = -1; splort.ZRotation = (float)(Random.NextDouble() * Math.PI); splort.Position = Position; splort.Alpha = 0.5f; CharacterScene.AddNode(splort, WorldLayer.Ground); splort.RunAction(SKAction.FadeOutWithDuration(10)); base.PerformDeath(); PhysicsBody.CollisionBitMask = 0; PhysicsBody.ContactTestBitMask = 0; PhysicsBody.CategoryBitMask = 0; PhysicsBody = null; }
protected override void CreateSceneContents () { base.CreateSceneContents (); SKTexture texture = SKTexture.FromImageNamed ("Art/stretchable_image.png"); SKAction resizeSpritesAction = GetResizeAction (texture); SKSpriteNode defaultSprite = new SKSpriteNode (texture); defaultSprite.Position = new CGPoint (Scene.Frame.GetMidX () - 192, Scene.Frame.GetMidY ()); defaultSprite.AddDescription ("Resized with default stretching", new CGPoint (0, -128)); Scene.AddChild (defaultSprite); defaultSprite.RunAction (resizeSpritesAction); SKSpriteNode customSprite = new SKSpriteNode (texture); customSprite.Position = new CGPoint (Scene.Frame.GetMidX () + 192, Scene.Frame.GetMidY ()); customSprite.CenterRect = new CGRect (12.0f / 28.0f, 12.0f / 28.0f, 4.0f / 28.0f, 4.0f / 28.0f); customSprite.AddDescription ("Resized with custom stretching", new CGPoint (0, -128)); Scene.AddChild (customSprite); customSprite.RunAction (resizeSpritesAction); }
protected override void CreateSceneContents() { base.CreateSceneContents(); SKTexture[] walkFrames = LoadFrames("Art/warrior_walk_", 28); SKSpriteNode sprite = new SKSpriteNode(walkFrames [0]) { Position = new CGPoint(Scene.Frame.GetMidX(), Scene.Frame.GetMidY()) }; Scene.AddChild(sprite); //Cycle through the frame var animation = SKAction.AnimateWithTextures(walkFrames, 1.0f / 28, true, false); sprite.RunAction(SKAction.RepeatActionForever(animation)); Scene.AddDescription("This sprite is animating through a series of texture images.", new CGPoint(Scene.Frame.GetMidX(), 100)); }
public Player(nfloat width, nfloat height) { Sprite = new SKSpriteNode("Bird") { XScale = 0.1f, YScale = 0.1f, Position = new CGPoint(width / 2.5, height / 2) }; var action = SKAction.MoveBy(0, GRAVITY, 1); Sprite.RunAction(SKAction.RepeatActionForever(action)); Sprite.PhysicsBody = SKPhysicsBody.Create(Sprite.Texture, Sprite.Size); Sprite.PhysicsBody.AffectedByGravity = false; Sprite.PhysicsBody.UsesPreciseCollisionDetection = true; Sprite.PhysicsBody.CategoryBitMask = (uint)PhysicsCategoryEnum.Player; Sprite.PhysicsBody.CollisionBitMask = (uint)(PhysicsCategoryEnum.Player | PhysicsCategoryEnum.Pipe); Sprite.PhysicsBody.ContactTestBitMask = (uint)(PhysicsCategoryEnum.Player | PhysicsCategoryEnum.Pipe);; Sprite.PhysicsBody.Mass = 0.1f; }
/// <summary> /// Анимация разрушения цепочек /// </summary> /// <param name="chains">Список цепочек на разрушение.</param> public void AnimateTheDstructionOf(List <GemList> chains) { // маркер проверки на наличие в разрушенных цепочках разрушителя // если был разрушитель - звук разрушения будет другой bool hadDestroyers = false; bool hadBombs = false; if (chains == null) { return; } foreach (GemList chain in chains) { foreach (Gem gem in chain) { SKSpriteNode sprite = gem.Sprite; SKAction sprtieAction = SKAction.FadeAlphaTo(0.0f, Properties.DestructionAnimationDuration / 1000f); sprite.RunAction(SKAction.Sequence(sprtieAction, SKAction.RemoveFromParent())); AnimateScore(chain); hadDestroyers |= gem.IsALineDestroyer; hadBombs |= gem.IsABomb; } } if (hadBombs) { RunAction(explosionSound); } else if (hadDestroyers) { RunAction(destroySound); } else { RunAction(dingSound); } }
protected override void CreateSceneContents() { base.CreateSceneContents(); SKTexture texture = SKTexture.FromImageNamed("Art/stretchable_image.png"); SKAction resizeSpritesAction = GetResizeAction(texture); SKSpriteNode defaultSprite = new SKSpriteNode(texture); defaultSprite.Position = new PointF(Scene.Frame.GetMidX() - 192, Scene.Frame.GetMidY()); defaultSprite.AddDescription("Resized with default stretching", new PointF(0, -128)); Scene.AddChild(defaultSprite); defaultSprite.RunAction(resizeSpritesAction); SKSpriteNode customSprite = new SKSpriteNode(texture); customSprite.Position = new PointF(Scene.Frame.GetMidX() + 192, Scene.Frame.GetMidY()); customSprite.CenterRect = new RectangleF(12.0f / 28.0f, 12.0f / 28.0f, 4.0f / 28.0f, 4.0f / 28.0f); customSprite.AddDescription("Resized with custom stretching", new PointF(0, -128)); Scene.AddChild(customSprite); customSprite.RunAction(resizeSpritesAction); }
void AddAnimatedSprite() { SKSpriteNode animatedSprite = (SKSpriteNode)(template as NSObject).Copy(); animatedSprite.Position = new CGPoint(925, 384); Scene.AddChild(animatedSprite); Scene.AddDescription("Animated Color Blending", new CGPoint(animatedSprite.Position.X, animatedSprite.Position.Y - 90)); animatedSprite.RunAction(SKAction.RepeatActionForever(SKAction.Sequence( SKAction.WaitForDuration(1.0), SKAction.ColorizeWithColor(UIColor.Red, 1.0f, 1.0f), SKAction.WaitForDuration(1.0), SKAction.ColorizeWithColor(UIColor.Green, 1.0f, 1.0f), SKAction.WaitForDuration(1.0), SKAction.ColorizeWithColor(UIColor.Blue, 1.0f, 1.0f), SKAction.WaitForDuration(1.0), SKAction.ColorizeWithColor(UIColor.Yellow, 1.0f, 1.0f), SKAction.WaitForDuration(1.0), SKAction.ColorizeWithColorBlendFactor(0.0f, 1.0f) ))); }
void UpdateCurrentSpot() { currentSpot?.RemoveFromParent (); currentSpot = GetSpriteForCell(CurrentX, CurrentY); var action = SKAction.RepeatActionForever ( SKAction.Sequence ( SKAction.ScaleBy (2f, 0.6), SKAction.ScaleBy (0.5f, 0.6) )); currentSpot.RunAction (action); AddChild (currentSpot); }
// definition of sidewalk scrolling action public void Scroll(SKSpriteNode sidewalk) { walkAnimate = SKAction.RepeatActionForever(SKAction.MoveBy(0.0f, -.09f, 0.0003f)); sidewalk.RunAction(walkAnimate); }
public override void DidMoveToView(SKView view) { road1 = new SKSpriteNode("road") { XScale = 0.7f, YScale = 0.7f, Position = new CGPoint(roadx, 89), ZPosition = 0.3f }; roadhalf = (road1.Frame.Height / 2) - 1; road1.Position = new CGPoint(roadx, roadhalf); road2 = new SKSpriteNode("road") { XScale = 0.7f, YScale = 0.7f, Position = new CGPoint(roadx, roadhalf + (road1.Frame.Bottom)), ZPosition = 0.3f }; road3 = new SKSpriteNode("road") { XScale = 0.7f, YScale = 0.7f, Position = new CGPoint(roadx, roadhalf + (road2.Frame.Bottom)), ZPosition = 0.3f }; road4 = new SKSpriteNode("road") { XScale = 0.7f, YScale = 0.7f, Position = new CGPoint(roadx, roadhalf + (road3.Frame.Bottom)), ZPosition = 0.3f }; road5 = new SKSpriteNode("road") { XScale = 0.7f, YScale = 0.7f, Position = new CGPoint(roadx, roadhalf + (road4.Frame.Bottom)), ZPosition = 0.3f }; road6 = new SKSpriteNode("road") { XScale = 0.7f, YScale = 0.7f, Position = new CGPoint(roadx, roadhalf + (road5.Frame.Bottom)), ZPosition = 0.3f }; Console.WriteLine(road1.Frame); building1 = new SKSpriteNode("Building") { XScale = 1.0f, YScale = 1.0f, Position = new CGPoint(buildx, 0), ZPosition = 0.3f }; buildhalf = (building1.Frame.Height / 2) - 1; building2 = new SKSpriteNode("Building") { XScale = 1.0f, YScale = 1.0f, Position = new CGPoint(buildx, buildhalf + (building1.Frame.Bottom)), ZPosition = 0.3f }; building3 = new SKSpriteNode("Building") { XScale = 1.0f, YScale = 1.0f, Position = new CGPoint(buildx, buildhalf + (building2.Frame.Bottom)), ZPosition = 0.3f }; building4 = new SKSpriteNode("Building") { XScale = 1.0f, YScale = 1.0f, Position = new CGPoint(0 + 327, (65 / 2) + (building3.Frame.Bottom)), ZPosition = 0.3f }; building5 = new SKSpriteNode("Building") { XScale = 1.0f, YScale = 1.0f, Position = new CGPoint(buildx, buildhalf + (building4.Frame.Bottom)), ZPosition = 0.3f }; building6 = new SKSpriteNode("Building") { XScale = 1.0f, YScale = 1.0f, Position = new CGPoint(buildx, buildhalf + (building5.Frame.Bottom)), ZPosition = 0.3f }; building7 = new SKSpriteNode("Building") { XScale = 1.0f, YScale = 1.0f, Position = new CGPoint(buildx, buildhalf + (building6.Frame.Bottom)), ZPosition = 0.3f }; building8 = new SKSpriteNode("Building") { XScale = 1.0f, YScale = 1.0f, Position = new CGPoint(buildx, buildhalf + (building7.Frame.Bottom)), ZPosition = 0.3f }; building9 = new SKSpriteNode("Building") { XScale = 1.0f, YScale = 1.0f, Position = new CGPoint(buildx, buildhalf + (building8.Frame.Bottom)), ZPosition = 0.3f }; building10 = new SKSpriteNode("Building") { XScale = 1.0f, YScale = 1.0f, Position = new CGPoint(buildx, buildhalf + (building9.Frame.Bottom)), ZPosition = 0.3f }; building11 = new SKSpriteNode("Building") { XScale = 1.0f, YScale = 1.0f, Position = new CGPoint(buildx, buildhalf + (building10.Frame.Bottom)), ZPosition = 0.3f }; building12 = new SKSpriteNode("Building") { XScale = 1.0f, YScale = 1.0f, Position = new CGPoint(buildx, buildhalf + (building11.Frame.Bottom)), ZPosition = 0.3f }; building13 = new SKSpriteNode("Building") { XScale = 1.0f, YScale = 1.0f, Position = new CGPoint(buildx, buildhalf + (building12.Frame.Bottom)), ZPosition = 0.3f }; building14 = new SKSpriteNode("Building") { XScale = 1.0f, YScale = 1.0f, Position = new CGPoint(buildx, buildhalf + (building13.Frame.Bottom)), ZPosition = 0.3f }; // Setup player character playerObject = new SKSpriteNode("Stumbler-1") { XScale = 1.6f, YScale = 1.6f, Position = new CGPoint(Frame.Width / 2, Frame.Height / 4), ZPosition = 0.1f }; // sidewalk sprites, set up to overlap to remove gaps 4 at top 1 at bottom sidewalk1 = new SKSpriteNode("Sidewalk") { XScale = 1.0f, YScale = 1.0f, Position = new CGPoint(Frame.Width / 2, Frame.Bottom - sidehalf), ZPosition = 0.0f }; sidewalk2 = new SKSpriteNode("Sidewalk") { XScale = 1.0f, YScale = 1.0f, Position = new CGPoint(Frame.Width / 2, sidewalk1.Frame.Top - sidehalf), ZPosition = 0.0f }; sidewalk3 = new SKSpriteNode("Sidewalk") { XScale = 1.0f, YScale = 1.0f, Position = new CGPoint(Frame.Width / 2, sidewalk2.Frame.Top - sidehalf), ZPosition = 0.0f }; // definition of player walking animation void animatePlayer() { var textures = Enumerable.Range(1, 4).Select( (i) => SKTexture.FromImageNamed(String.Format("Stumbler-{0}", i))).ToArray(); playerAnimate = SKAction.RepeatActionForever(SKAction.AnimateWithTextures(textures, 0.1)); playerObject.RunAction(playerAnimate); } // definition of sidewalk scrolling action void Scroll(SKSpriteNode node) { walkAnimate = SKAction.RepeatActionForever(SKAction.MoveBy(0.0f, -0.1f, 0.0007f)); node.RunAction(walkAnimate); } // calls to add sprites to scene AddChild(road1); AddChild(road2); AddChild(road3); AddChild(road4); AddChild(road5); AddChild(road6); AddChild(sidewalk1); AddChild(sidewalk2); AddChild(sidewalk3); AddChild(building1); AddChild(building2); AddChild(building3); AddChild(building4); AddChild(building5); AddChild(building6); AddChild(building7); AddChild(building8); AddChild(building9); AddChild(building10); AddChild(building11); AddChild(building12); AddChild(building13); AddChild(building14); AddChild(playerObject); // calls to animation for sprites Scroll(sidewalk1); Scroll(sidewalk2); Scroll(sidewalk3); Scroll(road1); Scroll(road2); Scroll(road3); Scroll(road4); Scroll(road5); Scroll(road6); Scroll(building1); Scroll(building2); Scroll(building3); Scroll(building4); Scroll(building5); Scroll(building6); Scroll(building7); Scroll(building8); Scroll(building9); Scroll(building10); Scroll(building11); Scroll(building12); Scroll(building13); Scroll(building14); animatePlayer(); //Console.WriteLine(Frame.Bottom); }