简体   繁体   中英

How to slow the speed of my sprite in spriteKit swift?

I am creating a small game using spriteKit, my sprites are falling from from up to down in a high speed, i want to manage the time. I know there is a way, SKaction can do this. but i do not know how to implement this function.

this is my Code:

    var item: SKSpriteNode?;    
    item!.zPosition = 3;
    item!.anchorPoint = CGPoint(x: 0.5, y: 0.5);
    item!.position.x = randomBetweenNumbers(firstNum: minX+10, secondNum: maxX+10);
    item!.position.y = 500;

This is running perfectly, but speed of my falling sprites is very high for me, but when i am trying this, this give me error. type of SKaction is not assign to type CGFLoat. an

item!.position.y = SKAction.move(to: CGPoint(x:0,y:500), duration: (2));

So please help me here, how to handle this.

You can use physics to move your objects if need be, but if you have no need for physics or collision detection using physics it may not be necessary. Your error is occurring because you cannot apply an SKAction to property that expects a CGFloat. If you want to use an SKAction to move the object you run it like so...

item!.run(SKAction.move(to: CGPoint(x:0,y:500), duration: (2)));

With sprite-kit , image it's a real world, so if you want to slow down the falling, you need to set gravity , with a "lighter" gravity , item will fall slower.

Spritekit tutorial

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM