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

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.

主站蜘蛛池模板: 凤阳县| 章丘市| 西充县| 福海县| 巴里| 正镶白旗| 金山区| 璧山县| 罗源县| 永清县| 莱州市| 新化县| 前郭尔| 夏津县| 晋州市| 九龙坡区| 河曲县| 邻水| 容城县| 池州市| 永修县| 海口市| 淳化县| 龙胜| 嘉祥县| 荆门市| 凌源市| 海淀区| 正蓝旗| 宁国市| 桦川县| 滦南县| 民县| 桐城市| 饶河县| 绥阳县| 泽库县| 梁河县| 方城县| 岳普湖县| 宁都县|