Cocos Creator version: 2.3.4 Demo download: https://files-cdn.cnblogs.com/files/gamedaybyday/cocos2.3.4_ccfollow.7z Let's first use the follow code that comes with cocoscreator, cc.follow. Use of CC.Follow1. Set the map adapter container leftNodeLet's say this is a horizontal parkour game. The map size is 1500x1500, so the height and width of leftNode are 1500x1500, and the widget is aligned to the lower left. 2. Set the map container mapThe map container is also 1500x1500. The difference from leftNode is that it does not have an adapter component widget. If you use a widget, you cannot move the map. This is why an extra layer of leftNode is used to adapt to the screen. There is a role in the map. (A normal cc.Button button) There are red buttons around the map to identify the map edges. Add the Follow.ts component to the map container and set the target role to Role. Role is a button cc.Button, and we treat it as a moving role here. The code of Follow.ts is as follows: const {ccclass, property} = cc._decorator; @ccclass export default class Follow extends cc.Component { @property(cc.Node) target:cc.Node = null; start () { var follow = cc.follow(this.target, cc.rect(0,0, 1500,1500)); this.node.runAction(follow); } } 3. Virtual joystick controls character movementVirtual joystick reference: https://www.cnblogs.com/gamedaybyday/p/13061387.html It doesn't matter if you don't know, as long as you can use other methods to control the character's movement and change the character's x and y. 4. Actual Demonstration EffectYou can see that when the character moves, the "camera" automatically follows the character and is limited to a range of 1500x1500, not exceeding the boundary where the red button is placed. Source code of CC.FollowThe source code is in CC.Action.js The above is the details of how to use cc.follow for camera following in CocosCreator. For more information about camera following in CocosCreator, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: A preliminary study on composite primary key and joint primary key in SQL statements
>>: Detailed explanation of the usage of two types of temporary tables in MySQL
Preface We all know that in Linux, "everythi...
Using the clear property to clear floats is a comm...
Being a web designer is not easy. Not only do you...
Table of contents 1. Installation 2. Import into ...
The offline installation method of MySQL_8.0.2 is...
meta is an auxiliary tag in the head area of htm...
Table of contents What is a listener in vue Usage...
Page domain relationship: The main page a.html bel...
Table of contents 1. Commonly used string functio...
Preface When the WeChat mini program project invo...
Differences between Docker and Docker Machine Doc...
In LINUX, periodic tasks are usually handled by t...
This is an important (and wonderful) topic for Li...
Table of contents Registering Components Adding C...
This article example shares the specific code of ...