官术网_书友最值得收藏!

Pushing Pierre forward

This style of game usually moves the world forward at a constant speed. Rather than applying force or impulse, we can manually set a constant velocity for Pierre during every update. Open the Player.swift file and add this code at the bottom of the update function:

// Set a constant velocity to the right: 
self.physicsBody?.velocity.dx = 200 

Run the project. Our protagonist penguin will move forward, past the swarm of bees and through the world. This works well, but you will quickly notice that the ground runs out as Pierre moves forward, as shown in this screenshot:

Pushing Pierre forward

Recall that our ground is only as wide as the screen width multiplied by six. Rather than extending the ground further, we will move the ground's position at well-timed intervals. Since the ground is made up of repeating tiles, there are many opportunities to jump its position forward seamlessly. We simply need to figure out when the player has travelled the correct distance.

主站蜘蛛池模板: 策勒县| 军事| 勃利县| 香港| 阿勒泰市| 益阳市| 泽普县| 二手房| 怀安县| 四平市| 安远县| 额敏县| 盐津县| 泰安市| 娱乐| 田林县| 黑水县| 高唐县| 合肥市| 常山县| 轮台县| 遵义市| 郴州市| 康马县| 嘉定区| 剑川县| 衡东县| 朝阳区| 肇庆市| 宜君县| 马鞍山市| 息烽县| 石家庄市| 扶绥县| 遂溪县| 富平县| 晋中市| 巴林左旗| 哈尔滨市| 聊城市| 永春县|