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
The problems and solutions encountered when deplo...
1. Call the parent component method directly thro...
Table of contents 1. Install Docker 2. Create a c...
Preface Recently, I have been busy dealing with s...
1. Under 800*600, if the width of the web page is...
Table of contents 1. Use the a tag to preview or ...
Preface When we write code, we occasionally encou...
Docker underlying technology: The two core techno...
Table of contents 1. Introduction 2. Customize ta...
Recently, when using Apple.com/Ebay.com/Amazon.co...
Table of contents Oracle Isolation Levels MySQL I...
1 Download the MySQL 5.6 version compressed packa...
This article mainly introduces the detailed proce...
This post focuses on a super secret Flutter proje...
Table of contents 1. Where is the slowness? 2. Ha...