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

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.

主站蜘蛛池模板: 清河县| 贡嘎县| 晋宁县| 克拉玛依市| 富阳市| 霸州市| 凯里市| 荆门市| 六安市| 城口县| 桐城市| 石林| 上蔡县| 靖江市| 沧州市| 泰来县| 綦江县| 谢通门县| 鄂托克前旗| 白沙| 和政县| 苏尼特左旗| 应城市| 广州市| 尼木县| 民县| 桃园县| 务川| 昌吉市| 曲麻莱县| 西和县| 扶绥县| 马关县| 普定县| 金阳县| 石狮市| 西乌珠穆沁旗| 都昌县| 芮城县| 达日县| 永胜县|