cocos creator “TypeError: Cannot set property ‘string‘ of null

在使用CocosCreator编程时遇到TypeError,因尝试对null对象设置string属性。开发者在更新函数中试图将计数器每600秒加到stepsLabel上,但可能漏掉了挂载步骤导致的错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

背景:
学习cocos creator时遇到"TypeError: Cannot set property 'string' of null" 错误。

具体代码如下:

    @property({ type: Label })
    public stepsLabel: Label | null = null;

	update(deltaTime: number) {
		this.stepsLabel.string = '' + Math.floor(this.count/600);
	}
原因:还是要注意的,我记得我当时有进行挂载的

在这里插入图片描述

import { _decorator, Component, Node, director, resources, instantiate, Vec3, math } from 'cc'; import { GameData } from './GameData'; import { A_guagouyidong } from './A_guagouyidong'; import { B_pengzhuangDefenxitong } from './B_pengzhuangDefenxitong'; import { ditu } from './C_ditu'; import { A_HUAHUAweizhi } from './A_HUAHUAweizhi'; import { zizhuandaishangwawa2 } from './zizhuandaishangwawa2'; import { fuhuoUI } from './fuhuoUI'; import { GameOverUI } from './GameOverUI'; const { ccclass, property } = _decorator; @ccclass('AA_GameManager') export class GameManager extends Component { @property(Node) clawNode: Node = null; // 爪子节点 @property(Node) collisionSystemNode: Node = null; // 碰撞系统节点 @property(Node) mapNode: Node = null; // 地图节点 @property(Node) flowerSpawnerNode: Node = null; // 花朵生成器节点 @property(Node) rotationComponentNode: Node = null; // 旋转组件节点 @property(Node) cameraFollowNode: Node = null; // 相机跟随节点 @property(Node) reviveUINode: Node = null; // 复活UI节点 @property(Node) gameOverUINode: Node = null; // 游戏结束UI节点 private isGameActive: boolean = false; private currentLevel: number = 1; onLoad() { this.initializeGame(); } /** * 初始化游戏 */ private initializeGame() { // 重置游戏数据 GameData.reset(); // 获取或初始化组件 if (!this.clawNode) this.clawNode = this.node.getChildByName('Claw'); if (!this.collisionSystemNode) this.collisionSystemNode = this.node.getChildByName('CollisionSystem'); if (!this.mapNode) this.mapNode = this.node.getChildByName('Map'); if (!this.flowerSpawnerNode) this.flowerSpawnerNode = this.node.getChildByName('FlowerSpawner'); if (!this.rotationComponentNode) this.rotationComponentNode = this.node.getChildByName('RotationComponent'); if (!this.cameraFollowNode) this.cameraFollowNode = this.node.getChildByName('CameraFollow'); if (!this.reviveUINode) this.reviveUINode = this.node.getChildByName('ReviveUI'); if (!this.gameOverUINode) this.gameOverUINode = this.node.getChildByName('GameOverUI'); // 初始化游戏状态 this.isGameActive = true; } /** * 开始游戏 */ public startGame() { if (!this.isGameActive) { this.isGameActive = true; // 重置所有游戏组件 this.resetGameComponents(); // 初始化UI if (this.reviveUINode) { const reviveUI = this.reviveUINode.getComponent(fuhuoUI); if (reviveUI) reviveUI.hide(); } if (this.gameOverUINode) { const gameOverUI = this.gameOverUINode.getComponent(GameOverUI); if (gameOverUI) gameOverUI.hide(); } // 开始游戏循环 this.scheduleOnce(() => { this.enableGameComponents(true); }, 0.1); } } /** * 重置游戏 */ public resetGame() { this.isGameActive = false; this.resetGameComponents(); GameData.reset(); // 延迟一点时间确保所有销毁操作完成 this.scheduleOnce(() => { this.startGame(); }, 0.2); } /** * 重置游戏组件 */ private resetGameComponents() { // 重置爪子 if (this.clawNode) { const clawMovement = this.clawNode.getComponent(A_guagouyidong); if (clawMovement) { clawMovement.stopMovement(); clawMovement.isFirstClick = true; } } // 重置碰撞系统 if (this.collisionSystemNode) { const collisionSystem = this.collisionSystemNode.getComponent(B_pengzhuangDefenxitong); if (collisionSystem) { collisionSystem.stopAllMovements(); } } // 重置地图 if (this.mapNode) { const mapComponent = this.mapNode.getComponent(ditu); if (mapComponent) { mapComponent.generateMap(); } } // 重置花朵生成器 if (this.flowerSpawnerNode) { const flowerSpawner = this.flowerSpawnerNode.getComponent(A_HUAHUAweizhi); if (flowerSpawner) { flowerSpawner.showFlowers(); } } // 重置旋转组件 if (this.rotationComponentNode) { const rotationComponent = this.rotationComponentNode.getComponent(zizhuandaishangwawa2); if (rotationComponent && rotationComponent.enabled) { rotationComponent.enabled = false; this.scheduleOnce(() => { rotationComponent.enabled = true; }, 0.2); } } } /** * 启用或禁用游戏组件 * @param enable 是否启用 */ private enableGameComponents(enable: boolean) { // 启用/禁用爪子移动 if (this.clawNode) { const clawMovement = this.clawNode.getComponent(A_guagouyidong); if (clawMovement) { if (enable) { clawMovement.resumeMovement(); } else { clawMovement.stopMovement(); } } } // 启用/禁用旋转组件 if (this.rotationComponentNode) { const rotationComponent = this.rotationComponentNode.getComponent(zizhuandaishangwawa2); if (rotationComponent) { rotationComponent.enabled = enable; } } // 启用/禁用碰撞系统 if (this.collisionSystemNode) { const collisionSystem = this.collisionSystemNode.getComponent(B_pengzhuangDefenxitong); if (collisionSystem) { // 碰撞系统本身会根据游戏状态处理 } } } /** * 游戏结束 * @param isSuccess 是否成功 */ public gameOver(isSuccess: boolean) { this.isGameActive = false; this.enableGameComponents(false); // 显示游戏结束UI if (this.gameOverUINode) { const gameOverUI = this.gameOverUINode.getComponent(GameOverUI); if (gameOverUI) { gameOverUI.show(GameData.getScore()); } } } /** * 返回主页 */ public goToHome() { // 这里可以添加返回主页的逻辑 // 例如加载主页场景 director.loadScene('HomeScene'); } /** * 下一关 */ public nextLevel() { this.currentLevel++; // 这里可以添加加载下一关的逻辑 // 例如重新初始化游戏或加载新场景 this.resetGame(); } /** * 暂停游戏 */ public pauseGame() { if (this.isGameActive) { this.isGameActive = false; this.enableGameComponents(false); } } /** * 恢复游戏 */ public resumeGame() { if (!this.isGameActive) { this.isGameActive = true; this.enableGameComponents(true); } } }。import { _decorator, Button, Component, director, resources } from 'cc'; import { GameManager } from './AA_GameManager'; const { ccclass, property } = _decorator; @ccclass('F_fanhuizhuye') export class F_fanhuizhuye extends Component { @property(GameManager) gameManager: GameManager = null; // 绑定 GameManager 节点 onLoad() { // 获取按钮组件并绑定点击事件 const button = this.node.getComponent(Button); if (button) { button.node.on(Button.EventType.CLICK, this.onClick, this); } } private onClick() { if (this.gameManager) { // 重置游戏 this.gameManager.resetGame(); } // 加载主页场景 director.loadScene('kaishiUI'); } onDestroy() { // 移除事件监听 const button = this.node.getComponent(Button); if (button) { button.node.off(Button.EventType.CLICK, this.onClick, this); } } } 。添加返回主页功能后,控制台出现 [PreviewInEditor] Cannot read property 'off' of null和 [Scene] Failed to set an indexed property on 'GamepadList': Indexed property setter is not supported.的错误,同时编辑器预览可以正常运行,返回主页后再正常进入游戏没问题(虽然控制台还是出现上面的两个错误提示),但是当用游览器预览和扫一扫二维码预览时,每单点击这个返回主页按钮就会出现错误了,出现这 [Browser Preview]Cannot read properties of null (reading 'off')/nTypeError: Cannot read properties of null (reading 'off')的错误,请问哪里出问题了,哪里需要修改。 [PreviewInEditor] Cannot read property 'off' of null TypeError: Cannot read property 'off' of null at huohuianniu.onDestroy (file:///C:/Users/Yao~~Yao/jiawawa/temp/programming/packer-driver/targets/editor/chunks/76/7658393ce2997f59351556cdfc5d77c033e6eac4.js:131:25) at eval (eval at tryCatchFunctor_EDITOR (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js), <anonymous>:4:10) at NodeActivator.eval (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:53508:42) at huohuianniu._onPreDestroy (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:51932:44) at huohuianniu._destroyImmediate (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:155559:119) at Node._onPreDestroyBase (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:57820:22) at Node.eval (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:53596:38) at Node._destroyImmediate (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:155559:119) at Node._onPreDestroyBase (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:57811:25) at Node.eval (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:53596:38)显示的错误时这些
06-12
--------- beginning of system 2025-07-14 19:01:46.868 1569-2215 ActivityManager system_server I Force stopping org.cocos2d.demo appid=10051 user=0: from pid 5432 --------- beginning of main 2025-07-14 19:01:46.869 2159-2159 ContextImpl com.android.coreservice W Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1531 android.content.ContextWrapper.startService:664 android.content.ContextWrapper.startService:664 com.android.coreservice.CoreBroadcastReceiver.onReceive:54 android.app.ActivityThread.handleReceiver:3424 2025-07-14 19:01:43.961 1569-1576 chatty system_server I uid=1000(system) FinalizerDaemon expire 46 lines 2025-07-14 19:01:43.961 1569-1576 System system_server W A resource failed to call close. 2025-07-14 19:01:46.870 1904-1904 CarrierSvcBindHelper com.android.phone D No carrier app for: 0 2025-07-14 19:01:46.935 1569-3446 ActivityManager system_server I Force stopping org.cocos2d.demo appid=10051 user=0: from pid 5445 2025-07-14 19:01:46.936 1904-1904 CarrierSvcBindHelper com.android.phone D No carrier app for: 0 2025-07-14 19:01:46.937 2159-2159 ContextImpl com.android.coreservice W Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1531 android.content.ContextWrapper.startService:664 android.content.ContextWrapper.startService:664 com.android.coreservice.CoreBroadcastReceiver.onReceive:54 android.app.ActivityThread.handleReceiver:3424 2025-07-14 19:01:46.959 1569-3446 ActivityManager system_server I START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=org.cocos2d.demo/org.cocos2dx.javascript.AppActivity} from uid 2000 2025-07-14 19:01:46.974 2159-2159 ContextImpl com.android.coreservice W Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1531 android.content.ContextWrapper.startService:664 android.content.ContextWrapper.startService:664 com.android.coreservice.CoreBroadcastReceiver.onReceive:45 android.app.ActivityThread.handleReceiver:3424 2025-07-14 19:01:46.979 1423-1423 allocator@2.0-s and...raphics.allocator@2.0-service I type=1400 audit(0.0:1117): avc: denied { ioctl } for path="/dev/fastpipe" dev="tmpfs" ino=7232 ioctlcmd=6867 scontext=u:r:hal_graphics_allocator_default:s0 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1 2025-07-14 19:01:46.998 5451-5451 nativebridge pid-5451 D PreInitializeNativeBridge name=zygote64 instruction_set=arm64 2025-07-14 19:01:46.999 1569-1586 ActivityManager system_server I Start proc 5451:org.cocos2d.demo/u0a51 for activity org.cocos2d.demo/org.cocos2dx.javascript.AppActivity 2025-07-14 19:01:47.014 5451-5451 nativebridge pid-5451 W Failed to bind-mount /data/local/cfg-nnayn/ as /proc/cpuinfo: Not a directory 2025-07-14 19:01:47.017 5451-5451 Zygote pid-5451 I seccomp disabled by setenforce 0 2025-07-14 19:01:47.018 5451-5451 rg.cocos2d.dem pid-5451 I Late-enabling -Xcheck:jni 2025-07-14 19:01:47.036 5451-5451 libnb pid-5451 V enter native_bridge2_initialize /data/user/0/org.cocos2d.demo/code_cache arm64 2025-07-14 19:01:47.036 5451-5451 houdini pid-5451 D [5451] Initialize library(version: 9.0.7a_z.38597 RELEASE)... successfully. ---------------------------- PROCESS STARTED (5451) for package org.cocos2d.demo ---------------------------- 2025-07-14 19:01:47.037 5451-5451 libnb pid-5451 V enter native_bridge2_isCompatibleWith 2 2025-07-14 19:01:47.139 2159-2159 ContextImpl com.android.coreservice W Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1531 android.content.ContextWrapper.startService:664 android.content.ContextWrapper.startService:664 com.android.coreservice.CoreBroadcastReceiver.onReceive:54 android.app.ActivityThread.handleReceiver:3424 2025-07-14 19:01:47.037 5451-5451 chatty org.cocos2d.demo I uid=10051(org.cocos2d.demo) identical 63 lines 2025-07-14 19:01:47.037 5451-5451 libnb org.cocos2d.demo V enter native_bridge2_isCompatibleWith 2 2025-07-14 19:01:47.157 5451-5451 libnb org.cocos2d.demo V enter native_bridge2_isCompatibleWith 3 2025-07-14 19:01:47.157 5451-5451 libnb org.cocos2d.demo V enter native_bridge3_isPathSupported /data/app/org.cocos2d.demo-DSE6AeZBhpmsfM8p5sz99g==/lib/arm64:/data/app/org.cocos2d.demo-DSE6AeZBhpmsfM8p5sz99g==/base.apk!/lib/arm64-v8a 2025-07-14 19:01:47.157 5451-5451 libnb org.cocos2d.demo V enter native_bridge2_isCompatibleWith 3 2025-07-14 19:01:47.157 5451-5451 libnb org.cocos2d.demo V enter native_bridge3_initAnonymousNamespace libandroid.so:libaaudio.so:libc.so:libcamera2ndk.so:libdl.so:libEGL.so:libGLESv1_CM.so:libGLESv2.so:libGLESv3.so:libicui18n.so:libicuuc.so:libjnigraphics.so:liblog.so:libmediandk.so:libm.so:libnativewindow.so:libneuralnetworks.so:libOpenMAXAL.so:libOpenSLES.so:libRS.so:libstdc++.so:libsync.so:libvulkan.so:libwebviewchromium_plat_support.so:libz.so, /data/app/org.cocos2d.demo-DSE6AeZBhpmsfM8p5sz99g==/lib/arm64:/data/app/org.cocos2d.demo-DSE6AeZBhpmsfM8p5sz99g==/base.apk!/lib/arm64-v8a 2025-07-14 19:01:47.157 5451-5451 libnb org.cocos2d.demo V enter native_bridge2_isCompatibleWith 3 2025-07-14 19:01:47.157 5451-5451 libnb org.cocos2d.demo V enter native_bridge3_isPathSupported /data/app/org.cocos2d.demo-DSE6AeZBhpmsfM8p5sz99g==/lib/arm64:/data/app/org.cocos2d.demo-DSE6AeZBhpmsfM8p5sz99g==/base.apk!/lib/arm64-v8a 2025-07-14 19:01:47.157 5451-5451 libnb org.cocos2d.demo V enter native_bridge2_isCompatibleWith 3 2025-07-14 19:01:47.157 5451-5451 libnb org.cocos2d.demo V enter native_bridge3_createNamespace classloader-namespace, (null), /data/app/org.cocos2d.demo-DSE6AeZBhpmsfM8p5sz99g==/lib/arm64:/data/app/org.cocos2d.demo-DSE6AeZBhpmsfM8p5sz99g==/base.apk!/lib/arm64-v8a, /data:/mnt/expand:/data/user/0/org.cocos2d.demo 2025-07-14 19:01:47.157 5451-5451 libnb org.cocos2d.demo V enter native_bridge2_isCompatibleWith 4 2025-07-14 19:01:47.157 5451-5451 libnb org.cocos2d.demo V enter native_bridge2_isCompatibleWith 3 2025-07-14 19:01:47.157 5451-5451 libnb org.cocos2d.demo V enter native_bridge3_linkNamespaces libandroid.so:libaaudio.so:libc.so:libcamera2ndk.so:libdl.so:libEGL.so:libGLESv1_CM.so:libGLESv2.so:libGLESv3.so:libicui18n.so:libicuuc.so:libjnigraphics.so:liblog.so:libmediandk.so:libm.so:libnativewindow.so:libneuralnetworks.so:libOpenMAXAL.so:libOpenSLES.so:libRS.so:libstdc++.so:libsync.so:libvulkan.so:libwebviewchromium_plat_support.so:libz.so 2025-07-14 19:01:47.164 1569-1576 System system_server W A resource failed to call close. 2025-07-14 19:01:47.164 1569-1576 chatty system_server I uid=1000(system) FinalizerDaemon identical 19 lines 2025-07-14 19:01:47.164 1569-1576 System system_server W A resource failed to call close. 2025-07-14 19:01:47.198 1721-2100 ziparchive com.android.systemui W Unable to open '/data/app/org.cocos2d.demo-qLW_1oeK0d6GzjNEfloC_Q==/base.apk': No such file or directory 2025-07-14 19:01:47.198 1721-2100 ndroid.systemu com.android.systemui E Failed to open APK '/data/app/org.cocos2d.demo-qLW_1oeK0d6GzjNEfloC_Q==/base.apk' I/O error 2025-07-14 19:01:47.198 1721-2100 ResourcesManager com.android.systemui E failed to add asset path /data/app/org.cocos2d.demo-qLW_1oeK0d6GzjNEfloC_Q==/base.apk 2025-07-14 19:01:47.198 1721-2100 PackageManager com.android.systemui W Failure retrieving resources for org.cocos2d.demo 2025-07-14 19:01:47.198 1721-2100 ziparchive com.android.systemui W Unable to open '/data/app/org.cocos2d.demo-qLW_1oeK0d6GzjNEfloC_Q==/base.apk': No such file or directory 2025-07-14 19:01:47.198 1721-2100 ndroid.systemu com.android.systemui E Failed to open APK '/data/app/org.cocos2d.demo-qLW_1oeK0d6GzjNEfloC_Q==/base.apk' I/O error 2025-07-14 19:01:47.198 1721-2100 ResourcesManager com.android.systemui E failed to add asset path /data/app/org.cocos2d.demo-qLW_1oeK0d6GzjNEfloC_Q==/base.apk 2025-07-14 19:01:47.198 1721-2100 PackageManager com.android.systemui W Failure retrieving resources for org.cocos2d.demo 2025-07-14 19:01:47.198 1721-2100 ziparchive com.android.systemui W Unable to open '/data/app/org.cocos2d.demo-qLW_1oeK0d6GzjNEfloC_Q==/base.apk': No such file or directory 2025-07-14 19:01:47.198 1721-2100 ndroid.systemu com.android.systemui E Failed to open APK '/data/app/org.cocos2d.demo-qLW_1oeK0d6GzjNEfloC_Q==/base.apk' I/O error 2025-07-14 19:01:47.198 1721-2100 ResourcesManager com.android.systemui E failed to add asset path /data/app/org.cocos2d.demo-qLW_1oeK0d6GzjNEfloC_Q==/base.apk 2025-07-14 19:01:47.198 1721-2100 PackageManager com.android.systemui W Failure retrieving resources for org.cocos2d.demo 2025-07-14 19:01:47.198 1721-2100 ziparchive com.android.systemui W Unable to open '/data/app/org.cocos2d.demo-qLW_1oeK0d6GzjNEfloC_Q==/base.apk': No such file or directory 2025-07-14 19:01:47.198 1721-2100 ndroid.systemu com.android.systemui E Failed to open APK '/data/app/org.cocos2d.demo-qLW_1oeK0d6GzjNEfloC_Q==/base.apk' I/O error 2025-07-14 19:01:47.198 1721-2100 ResourcesManager com.android.systemui E failed to add asset path /data/app/org.cocos2d.demo-qLW_1oeK0d6GzjNEfloC_Q==/base.apk 2025-07-14 19:01:47.198 1721-2100 PackageManager com.android.systemui W Failure retrieving resources for org.cocos2d.demo 2025-07-14 19:01:47.198 1721-2100 ziparchive com.android.systemui W Unable to open '/data/app/org.cocos2d.demo-qLW_1oeK0d6GzjNEfloC_Q==/base.apk': No such file or directory 2025-07-14 19:01:47.198 1721-2100 ndroid.systemu com.android.systemui E Failed to open APK '/data/app/org.cocos2d.demo-qLW_1oeK0d6GzjNEfloC_Q==/base.apk' I/O error 2025-07-14 19:01:47.198 1721-2100 ResourcesManager com.android.systemui E failed to add asset path /data/app/org.cocos2d.demo-qLW_1oeK0d6GzjNEfloC_Q==/base.apk 2025-07-14 19:01:47.198 1721-2100 PackageManager com.android.systemui W Failure retrieving resources for org.cocos2d.demo 2025-07-14 19:01:47.224 5451-5451 Cocos2dxActivity org.cocos2d.demo D Cocos2dxActivity onCreate: org.cocos2dx.javascript.AppActivity@f1c691f, savedInstanceState: null 2025-07-14 19:01:47.260 5451-5451 libnb org.cocos2d.demo V enter native_bridge2_isCompatibleWith 3 2025-07-14 19:01:47.260 5451-5451 libnb org.cocos2d.demo V enter native_bridge3_loadLibraryExt /data/app/org.cocos2d.demo-DSE6AeZBhpmsfM8p5sz99g==/lib/arm64/libcocos2djs.so, 2, 0x3 2025-07-14 19:01:47.512 5451-5451 libnb org.cocos2d.demo V native_bridge3_loadLibraryExt: 0x763877d4eac0 2025-07-14 19:01:47.513 5451-5451 libnb org.cocos2d.demo V enter native_bridge2_getTrampoline JNI_OnLoad, trampoline_addr 0x76388e6af000 2025-07-14 19:01:47.513 5451-5451 JniHelper org.cocos2d.demo D JniHelper::setJavaVM(0x76388ede6928), pthread_self() = 129987584391496 2025-07-14 19:01:47.513 5451-5451 main org.cocos2d.demo D cocos_jni_env_init 2025-07-14 19:01:47.513 5451-5451 Cocos2dxHelper org.cocos2d.demo D isSupportLowLatency:true 2025-07-14 19:01:47.515 5451-5451 Cocos2dxHelper org.cocos2d.demo D sampleRate: 48000, framesPerBuffer: 1024 2025-07-14 19:01:47.515 5451-5451 libnb org.cocos2d.demo V enter native_bridge2_getTrampoline Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetAudioDeviceInfo, trampoline_addr 0x76388e6af020 2025-07-14 19:01:47.515 5451-5451 JniImp org.cocos2d.demo D nativeSetAudioDeviceInfo: sampleRate: 48000, bufferSizeInFrames: 1024 2025-07-14 19:01:47.516 5451-5451 libnb org.cocos2d.demo V enter native_bridge2_getTrampoline Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetApkPath, trampoline_addr 0x76388e6af040 2025-07-14 19:01:47.517 5451-5451 libnb org.cocos2d.demo V enter native_bridge2_getTrampoline Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetContext, trampoline_addr 0x76388e6af060 2025-07-14 19:01:47.520 5451-5451 libnb org.cocos2d.demo V enter native_bridge2_getTrampoline Java_org_cocos2dx_lib_Cocos2dxActivity_getGLContextAttrs, trampoline_addr 0x76388e6af080 2025-07-14 19:01:47.521 5451-5451 OpenGLRenderer org.cocos2d.demo D Skia GL Pipeline 2025-07-14 19:01:47.522 5451-5451 SDKWrapper org.cocos2d.demo W project.json 中不存在 serviceClassPath 字段 2025-07-14 19:01:47.523 5451-5451 Cocos2dxActivity org.cocos2d.demo D model=ASUS_AI2401_A 2025-07-14 19:01:47.523 5451-5451 Cocos2dxActivity org.cocos2d.demo D product=ASUS_AI2401_A 2025-07-14 19:01:47.523 5451-5451 Cocos2dxActivity org.cocos2d.demo D isEmulator=false 2025-07-14 19:01:47.546 5451-5451 Cocos2dxActivity org.cocos2d.demo D onResume() 2025-07-14 19:01:47.599 5451-5451 libnb org.cocos2d.demo V enter native_bridge2_getTrampoline Java_org_cocos2dx_lib_Cocos2dxGLSurfaceView_nativeOnSizeChanged, trampoline_addr 0x76388e6af0a0 2025-07-14 19:01:47.599 5451-5480 <no-tag> org.cocos2d.demo I fastpipe: Connect success 2025-07-14 19:01:47.601 5451-5480 <no-tag> org.cocos2d.demo I fastpipe: Connect success 2025-07-14 19:01:47.601 5451-5480 HostConnection org.cocos2d.demo D HostRPC::connect sucess: app=org.cocos2d.demo, pid=5451, tid=5480, this=0x7638888262c0 2025-07-14 19:01:47.602 5451-5480 HostConnection org.cocos2d.demo D queryAndSetGLESMaxVersion select gles-version: 3.1 hostGLVersion:46 process:org.cocos2d.demo 2025-07-14 19:01:47.604 5451-5480 ConfigStore org.cocos2d.demo I android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0 2025-07-14 19:01:47.604 5451-5480 ConfigStore org.cocos2d.demo I android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0 2025-07-14 19:01:47.604 5451-5480 OpenGLRenderer org.cocos2d.demo I Initialized EGL, version 1.4 2025-07-14 19:01:47.604 5451-5480 OpenGLRenderer org.cocos2d.demo D Swap behavior 1 2025-07-14 19:01:47.605 5451-5478 <no-tag> org.cocos2d.demo I fastpipe: Connect success 2025-07-14 19:01:47.605 5451-5478 HostConnection org.cocos2d.demo D HostRPC::connect sucess: app=org.cocos2d.demo, pid=5451, tid=5478, this=0x76387a5f7b00 2025-07-14 19:01:47.610 5451-5480 EGL_emulation org.cocos2d.demo D eglCreateContext: 0x76389273ba80: maj 3 min 1 rcv 4 2025-07-14 19:01:47.610 5451-5478 HostConnection org.cocos2d.demo D queryAndSetGLESMaxVersion select gles-version: 3.1 hostGLVersion:46 process:org.cocos2d.demo 2025-07-14 19:01:47.617 5451-5478 EGL_emulation org.cocos2d.demo D eglCreateContext: 0x76389273bf00: maj 3 min 1 rcv 4 2025-07-14 19:01:47.638 5451-5478 vndksupport org.cocos2d.demo D Loading /vendor/lib64/hw/android.hardware.graphics.mapper@2.0-impl.so from current namespace instead of sphal namespace. 2025-07-14 19:01:47.639 5451-5480 eglCodecCommon org.cocos2d.demo E glUtilsParamSize: unknow param 0x000082da 2025-07-14 19:01:47.639 5451-5480 eglCodecCommon org.cocos2d.demo E glUtilsParamSize: unknow param 0x000082e5 2025-07-14 19:01:47.640 5451-5478 vndksupport org.cocos2d.demo D Loading /vendor/lib64/hw/gralloc.default.so from current namespace instead of sphal namespace. 2025-07-14 19:01:47.642 5451-5480 HostConnection org.cocos2d.demo D ExtendedRCEncoderContext GL_VERSION return OpenGL ES 3.1 v1 2025-07-14 19:01:47.644 5451-5480 eglCodecCommon org.cocos2d.demo E glUtilsParamSize: unknow param 0x00008c29 2025-07-14 19:01:47.645 5451-5480 eglCodecCommon org.cocos2d.demo E glUtilsParamSize: unknow param 0x000087fe 2025-07-14 19:01:47.666 5451-5478 libnb org.cocos2d.demo V enter native_bridge2_getTrampoline Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit, trampoline_addr 0x76388e6af0c0 2025-07-14 19:01:47.666 5451-5478 main org.cocos2d.demo D cocos_android_app_init 2025-07-14 19:01:47.667 5451-5478 HostConnection org.cocos2d.demo D ExtendedRCEncoderContext GL_VERSION return OpenGL ES 3.1 v1 2025-07-14 19:01:47.671 5451-5480 EGL_emulation org.cocos2d.demo E tid 5480: eglSurfaceAttrib(1493): error 0x3009 (EGL_BAD_MATCH) 2025-07-14 19:01:47.671 5451-5480 OpenGLRenderer org.cocos2d.demo W Failed to set EGL_SWAP_BEHAVIOR on surface 0x76387a0f6180, error=EGL_BAD_MATCH 2025-07-14 19:01:47.672 5451-5478 JniImp org.cocos2d.demo D nativeInit: 1440, 2560, 2025-07-14 19:01:47.686 5451-5478 jswrapper org.cocos2d.demo D Initializing V8, version: 8.0.426.16 2025-07-14 19:01:47.709 5451-5451 Cocos2dxActivity org.cocos2d.demo D onWindowFocusChanged() hasFocus=true 2025-07-14 19:01:47.548 2159-2159 ContextImpl com.android.coreservice W Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1531 android.content.ContextWrapper.startService:664 android.content.ContextWrapper.startService:664 com.android.coreservice.CoreBroadcastReceiver.onReceive:54 android.app.ActivityThread.handleReceiver:3424 2025-07-14 19:01:47.712 2159-2159 ContextImpl com.android.coreservice W Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1531 android.content.ContextWrapper.startService:664 android.content.ContextWrapper.startService:664 com.android.coreservice.CoreBroadcastReceiver.onReceive:70 android.app.ActivityThread.handleReceiver:3424 2025-07-14 19:01:47.747 1569-1576 System system_server W A resource failed to call close. 2025-07-14 19:01:47.747 1569-1576 chatty system_server I uid=1000(system) FinalizerDaemon identical 25 lines 2025-07-14 19:01:47.747 1569-1576 System system_server W A resource failed to call close. 2025-07-14 19:01:47.775 5451-5478 jswrapper org.cocos2d.demo D libuv version: 1.13.1 2025-07-14 19:01:47.780 5451-5488 jswrapper org.cocos2d.demo D Debugger listening..., visit [ devtools://devtools/bundled/js_app.html?v8only=true&ws=0.0.0.0:6086/00010002-0003-4004-8005-000600070008 ] in chrome browser to debug! 2025-07-14 19:01:47.780 5451-5488 jswrapper org.cocos2d.demo D For help see https://nodejs.org/en/docs/inspector 2025-07-14 19:01:48.368 5451-5478 jswrapper org.cocos2d.demo D JS: Enable batch GL commands optimization! 2025-07-14 19:01:49.262 5451-5478 NetworkSecurityConfig org.cocos2d.demo D No Network Security Config specified, using platform default 2025-07-14 19:01:49.264 5451-5478 rg.cocos2d.dem org.cocos2d.demo W Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (light greylist, reflection) 2025-07-14 19:01:49.264 5451-5478 rg.cocos2d.dem org.cocos2d.demo W Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (light greylist, reflection) 2025-07-14 19:01:49.264 5451-5478 rg.cocos2d.dem org.cocos2d.demo W Accessing hidden method Ldalvik/system/CloseGuard;->warnIfOpen()V (light greylist, reflection) 2025-07-14 19:01:49.269 5451-5478 cocos2d-x org.cocos2d.demo D find in flash memory dirPath(/data/user/0/org.cocos2d.demo/files/temp) 2025-07-14 19:01:49.322 5451-5478 jswrapper org.cocos2d.demo E ScriptEngine::onGetStringFromFile stream not found, possible missing file. 2025-07-14 19:01:49.322 5451-5478 jswrapper org.cocos2d.demo E ScriptEngine::runScript script stream, buffer is empty! 2025-07-14 19:01:49.322 5451-5478 jswrapper org.cocos2d.demo E [ERROR] Failed to invoke require, location: C:/ProgramData/cocos/editors/Creator/2.4.13/resources/cocos2d-x/cocos/scripting/js-bindings/manual/jsb_global.cpp:299 2025-07-14 19:01:49.362 5451-5478 jswrapper org.cocos2d.demo E ScriptEngine::evalString catch exception: 2025-07-14 19:01:49.382 5451-5478 jswrapper org.cocos2d.demo E ERROR: Uncaught ReferenceError: self is not defined, location: src/assets/_plugs/lib/gravityengine.mg.cocoscreator.min.dbb97.js:0:0 STACK: [0]anonymous@src/assets/_plugs/lib/gravityengine.mg.cocoscreator.min.dbb97.js:2 [1]anonymous@src/assets/_plugs/lib/gravityengine.mg.cocoscreator.min.dbb97.js:3 [2]anonymous@jsb-adapter/jsb-engine.js:2975 [3]download@jsb-adapter/jsb-engine.js:2984 [4]downloadScript@jsb-adapter/jsb-engine.js:2971 [5]a@src/cocos2d-jsb.28d62.js:16668 [6]anonymous@src/cocos2d-jsb.28d62.js:16678 [7]retry@src/cocos2d-jsb.28d62.js:18111 [8]download@src/cocos2d-jsb.28d62.js:16663 [9]load@src/cocos2d-jsb.28d62.js:17318 [10]94.e.exports@src/cocos2d-jsb.28d62.js:17134 [11]_flow@src/cocos2d-jsb.28d62.js:17579 [12]async@src/cocos2d-jsb.28d62.js:17574 [13]anonymous@src/cocos2d-jsb.28d62.js:17261 [14]forEach@src/cocos2d-jsb.28d62.js:18189 [15]94.e.exports@src/cocos2d-jsb.28d62.js:17244 [16]_flow@src/cocos2d-jsb.28d62.js:17579 [17]anonymous@src/cocos2d-jsb.28d62.js:17586 [18]98.e.exports@src/cocos2d-jsb.2 2025-07-14 19:01:49.382 5451-5478 debug info org.cocos2d.demo D Uncaught Exception: - location : (see stack) - msg : Uncaught ReferenceError: self is not defined - detail : [0]anonymous@src/assets/_plugs/lib/gravityengine.mg.cocoscreator.min.dbb97.js:2 [1]anonymous@src/assets/_plugs/lib/gravityengine.mg.cocoscreator.min.dbb97.js:3 [2]anonymous@jsb-adapter/jsb-engine.js:2975 [3]download@jsb-adapter/jsb-engine.js:2984 [4]downloadScript@jsb-adapter/jsb-engine.js:2971 [5]a@src/cocos2d-jsb.28d62.js:16668 [6]anonymous@src/cocos2d-jsb.28d62.js:16678 [7]retry@src/cocos2d-jsb.28d62.js:18111 [8]download@src/cocos2d-jsb.28d62.js:16663 [9]load@src/cocos2d-jsb.28d62.js:17318 [10]94.e.exports@src/cocos2d-jsb.28d62.js:17134 [11]_flow@src/cocos2d-jsb.28d62.js:17579 [12]async@src/cocos2d-jsb.28d62.js:17574 [13]anonymous@src/cocos2d-jsb.28d62.js:17261 [14]forEach@src/cocos2d-jsb.28d62.js:18189 [15]94.e.exports@src/cocos2d-jsb.28d62.js:17244 [16]_flow@src/cocos2d-jsb.28d62.js:17579 [17]anonymous@src/cocos2d-jsb.28d62.js:17586 [18]98.e.exports@src/cocos2d-jsb.28d62.js:17642 [19] 2025-07-14 19:01:49.383 5451-5478 jswrapper org.cocos2d.demo D JS: [ERROR]: (see stack) Uncaught ReferenceError: self is not defined [0]anonymous@src/assets/_plugs/lib/gravityengine.mg.cocoscreator.min.dbb97.js:2 [1]anonymous@src/assets/_plugs/lib/gravityengine.mg.cocoscreator.min.dbb97.js:3 [2]anonymous@jsb-adapter/jsb-engine.js:2975 [3]download@jsb-adapter/jsb-engine.js:2984 [4]downloadScript@jsb-adapter/jsb-engine.js:2971 [5]a@src/cocos2d-jsb.28d62.js:16668 [6]anonymous@src/cocos2d-jsb.28d62.js:16678 [7]retry@src/cocos2d-jsb.28d62.js:18111 [8]download@src/cocos2d-jsb.28d62.js:16663 [9]load@src/cocos2d-jsb.28d62.js:17318 [10]94.e.exports@src/cocos2d-jsb.28d62.js:17134 [11]_flow@src/cocos2d-jsb.28d62.js:17579 [12]async@src/cocos2d-jsb.28d62.js:17574 [13]anonymous@src/cocos2d-jsb.28d62.js:17261 [14]forEach@src/cocos2d-jsb.28d62.js:18189 [15]94.e.exports@src/cocos2d-jsb.28d62.js:17244 [16]_flow@src/cocos2d-jsb.28d62.js:17579 [17]anonymous@src/cocos2d-jsb.28d62.js:17586 [18]98.e.exports@src/cocos2d-jsb.28d62.js:17642 [19]_flow@src/cocos2d-jsb.28d62.js:17579 2025-07-14 19:01:49.384 5451-5478 jswrapper org.cocos2d.demo E ScriptEngine::evalString script src/assets/_plugs/lib/gravityengine.mg.cocoscreator.min.dbb97.js, failed! 2025-07-14 19:01:49.384 5451-5478 jswrapper org.cocos2d.demo E [ERROR] Failed to invoke require, location: C:/ProgramData/cocos/editors/Creator/2.4.13/resources/cocos2d-x/cocos/scripting/js-bindings/manual/jsb_global.cpp:299 2025-07-14 19:01:49.428 5451-5478 libnb org.cocos2d.demo V enter native_bridge2_getTrampoline Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnSurfaceChanged, trampoline_addr 0x76388e6af0e0 2025-07-14 19:01:49.429 5451-5478 libnb org.cocos2d.demo V enter native_bridge2_getTrampoline Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeRender, trampoline_addr 0x76388e6af100 2025-07-14 19:01:49.652 5451-5478 libnb org.cocos2d.demo V enter native_bridge2_getTrampoline Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnResume, trampoline_addr 0x76388e6af120 2025-07-14 19:01:49.667 5451-5478 renderer org.cocos2d.demo D (626): Device caps: maxVextexTextures: 32, maxFragUniforms: 1024, maxTextureUints: 32, maxVertexAttributes: 16, maxDrawBuffers: 1, maxColorAttatchments: 1 2025-07-14 19:01:49.856 1569-1583 system_server system_server W Failed to determine oat file name for dex location /data/app/org.cocos2d.demo-DSE6AeZBhpmsfM8p5sz99g==/base.apk: Dalvik cache directory does not exist 2025-07-14 19:01:49.856 1569-1583 ActivityManager system_server I Displayed org.cocos2d.demo/org.cocos2dx.javascript.AppActivity: +2s896ms 2025-07-14 19:01:49.865 1436-1436 surfaceflinger surfaceflinger I type=1400 audit(0.0:1139): avc: denied { read write } for path="/dev/fastpipe" dev="tmpfs" ino=7232 scontext=u:r:hal_graphics_composer_default:s0 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1 2025-07-14 19:01:49.904 1436-1524 SurfaceFlinger surfaceflinger W Attempting to set client state on removed layer: Splash Screen org.cocos2d.demo#0 2025-07-14 19:01:49.904 1436-1524 SurfaceFlinger surfaceflinger W Attempting to destroy on removed layer: Splash Screen org.cocos2d.demo#0 2025-07-14 19:01:49.937 5451-5478 jswrapper org.cocos2d.demo D JS: Cocos Creator v2.4.13 2025-07-14 19:01:50.037 5451-5478 jswrapper org.cocos2d.demo D JS: 平板 宽度=750 高度=1333.3333333333335 2025-07-14 19:01:50.041 5451-5478 jswrapper org.cocos2d.demo D JS: 平板 宽度 适配后 宽度=750.375 高度=1334 2025-07-14 19:01:50.249 5451-5478 jswrapper org.cocos2d.demo D JS: 【YPSDK】 设置 登录回调 成功 2025-07-14 19:01:50.250 5451-5478 jswrapper org.cocos2d.demo D JS: [game-logger] UIManager open view: UI_Entry 2025-07-14 19:01:50.428 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:01:51.176 5451-5478 chatty org.cocos2d.demo I uid=10051(org.cocos2d.demo) GLThread 168 identical 11 lines 2025-07-14 19:01:51.246 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:01:51.245 1433-1433 ldinit ldinit I type=1400 audit(0.0:1140): avc: denied { read } for name="partitions" dev="proc" ino=4026532050 scontext=u:r:ldinit:s0 tcontext=u:object_r:proc:s0 tclass=file permissive=1 2025-07-14 19:01:51.245 1433-1433 ldinit ldinit I type=1400 audit(0.0:1140): avc: denied { open } for path="/proc/partitions" dev="proc" ino=4026532050 scontext=u:r:ldinit:s0 tcontext=u:object_r:proc:s0 tclass=file permissive=1 2025-07-14 19:01:51.330 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:01:59.903 5451-5478 chatty org.cocos2d.demo I uid=10051(org.cocos2d.demo) GLThread 168 identical 95 lines 2025-07-14 19:01:59.976 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:00.001 1569-1583 memtrack system_server E Couldn't load memtrack module 2025-07-14 19:02:00.001 1569-1583 android.os.Debug system_server W failed to get memory consumption info: -1 2025-07-14 19:02:00.048 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:00.149 5451-5478 chatty org.cocos2d.demo I uid=10051(org.cocos2d.demo) GLThread 168 identical 1 line 2025-07-14 19:02:00.216 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:00.256 5451-5478 jswrapper org.cocos2d.demo D JS: [ERROR]: 10s后,仍然未登录成功,直接进入游戏 2025-07-14 19:02:00.266 5451-5478 jswrapper org.cocos2d.demo D JS: Load game config success: [object Object] 2025-07-14 19:02:00.267 5451-5478 jswrapper org.cocos2d.demo D JS: 游戏本地配置加载成功 6 2025-07-14 19:02:00.281 5451-5478 jswrapper org.cocos2d.demo D JS: Load remote config success: [object Object] 2025-07-14 19:02:00.282 5451-5478 jswrapper org.cocos2d.demo D JS: 远程配置加载成功 13 2025-07-14 19:02:00.300 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:00.368 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:00.436 5451-5494 rg.cocos2d.dem org.cocos2d.demo W Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setAlpnProtocols([B)V (light greylist, reflection) 2025-07-14 19:02:00.436 5451-5497 rg.cocos2d.dem org.cocos2d.demo W Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setAlpnProtocols([B)V (light greylist, reflection) 2025-07-14 19:02:00.436 5451-5493 rg.cocos2d.dem org.cocos2d.demo W Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setAlpnProtocols([B)V (light greylist, reflection) 2025-07-14 19:02:00.436 5451-5502 rg.cocos2d.dem org.cocos2d.demo W Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setAlpnProtocols([B)V (light greylist, reflection) 2025-07-14 19:02:00.442 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:00.486 5451-5493 rg.cocos2d.dem org.cocos2d.demo W Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->getAlpnSelectedProtocol()[B (light greylist, reflection) 2025-07-14 19:02:00.512 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:00.578 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:00.582 5451-5478 libnb org.cocos2d.demo V enter native_bridge2_getTrampoline Java_org_cocos2dx_lib_Cocos2dxDownloader_nativeOnProgress, trampoline_addr 0x76388e6af140 2025-07-14 19:02:00.583 5451-5478 libnb org.cocos2d.demo V enter native_bridge2_getTrampoline Java_org_cocos2dx_lib_Cocos2dxDownloader_nativeOnFinish, trampoline_addr 0x76388e6af160 2025-07-14 19:02:00.675 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:00.824 5451-5478 chatty org.cocos2d.demo I uid=10051(org.cocos2d.demo) GLThread 168 identical 2 lines 2025-07-14 19:02:00.908 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:01.080 5451-5478 jswrapper org.cocos2d.demo D JS: [game-logger] load excel done 20 2025-07-14 19:02:01.083 5451-5478 jswrapper org.cocos2d.demo D JS: 游戏数据表加载成功 799 2025-07-14 19:02:01.085 5451-5478 jswrapper org.cocos2d.demo D JS: [ERROR]: 初始化数据 2025-07-14 19:02:01.092 5451-5478 jswrapper org.cocos2d.demo D JS: [ERROR]: [game-logger] load user data error: [object Object] 2025-07-14 19:02:01.121 5451-5478 jswrapper org.cocos2d.demo D JS: Loaded main bundle [object Object] 2025-07-14 19:02:01.122 5451-5478 jswrapper org.cocos2d.demo D JS: Common分包下载 28 2025-07-14 19:02:01.144 5451-5478 jswrapper org.cocos2d.demo D JS: Loaded main bundle [object Object] 2025-07-14 19:02:01.145 5451-5478 jswrapper org.cocos2d.demo D JS: Home分包下载 22 2025-07-14 19:02:01.162 5451-5478 debug info org.cocos2d.demo D Uncaught Exception: - location : - msg : unhandledRejectedPromise - detail : TypeError: Cannot read property 'userUid' of null stacktrace: [0]406.window.__awaiter@src/cocos2d-jsb.28d62.js:71530 [1]t.onInitWhiteName@assets/main/index.0a7c4.jsc:16936 [2]t._loadGame@assets/main/index.0a7c4.jsc:16756 [3]anonymous@assets/main/index.0a7c4.jsc:16771 2025-07-14 19:02:01.162 5451-5478 jswrapper org.cocos2d.demo D JS: [ERROR]: unhandledRejectedPromise TypeError: Cannot read property 'userUid' of null stacktrace: [0]406.window.__awaiter@src/cocos2d-jsb.28d62.js:71530 [1]t.onInitWhiteName@assets/main/index.0a7c4.jsc:16936 [2]t._loadGame@assets/main/index.0a7c4.jsc:16756 [3]anonymous@assets/main/index.0a7c4.jsc:16771 2025-07-14 19:02:01.188 5451-5478 jswrapper org.cocos2d.demo D JS: [game-logger] auto release all resources: ["UI_Entry"] 2025-07-14 19:02:01.323 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:01.479 5451-5478 jswrapper org.cocos2d.demo D JS: 登陆时间 1752490921479 2025-07-14 19:02:01.482 5451-5478 jswrapper org.cocos2d.demo D JS: [game-logger] 发送埋点 _uma.custom.gameProgress 章节1_0波 2025-07-14 19:02:01.484 5451-5478 jswrapper org.cocos2d.demo D JS: [game-logger] UIManager open view: UI_GameView 2025-07-14 19:02:01.535 5451-5478 AudioPlayerProvider org.cocos2d.demo I deviceSampleRate: 48000, bufferSizeInFrames: 192 2025-07-14 19:02:01.535 5451-5478 AudioPlayerProvider org.cocos2d.demo D Android API level: 28 2025-07-14 19:02:01.535 5451-5478 AudioMixerController org.cocos2d.demo V In the constructor of AudioMixerController! 2025-07-14 19:02:01.535 5451-5478 <no-tag> org.cocos2d.demo D PlayerBase::PlayerBase() 2025-07-14 19:02:01.535 5451-5478 <no-tag> org.cocos2d.demo D TrackPlayerBase::TrackPlayerBase() 2025-07-14 19:02:01.536 5451-5478 libOpenSLES org.cocos2d.demo I Emulating old channel mask behavior (ignoring positional mask 0x3, using default mask 0x3 based on channel count of 2) 2025-07-14 19:02:01.536 1434-5232 AudioFlinger audioserver W createTrack_l(): mismatch between requested flags (00000104) and output flags (00000002) 2025-07-14 19:02:01.536 1434-5232 AudioFlinger audioserver D Client defaulted notificationFrames to 960 for frameCount 2052 2025-07-14 19:02:01.537 5451-5478 AudioTrack org.cocos2d.demo W AUDIO_OUTPUT_FLAG_FAST denied by server; frameCount 0 -> 2052 2025-07-14 19:02:01.538 1707-2033 bt_btif com.android.bluetooth E register_notification_rsp: Avrcp device is not connected, handle: 0x0 2025-07-14 19:02:01.538 1707-2033 chatty com.android.bluetooth I uid=1002(bluetooth) BluetoothAvrcpH identical 4 lines 2025-07-14 19:02:01.538 1707-2033 bt_btif com.android.bluetooth E register_notification_rsp: Avrcp device is not connected, handle: 0x0 2025-07-14 19:02:01.535 1413-1413 writer android.hardware.audio@2.0-service I type=1400 audit(0.0:1143): avc: denied { ioctl } for path="/dev/fastpipe" dev="tmpfs" ino=7232 ioctlcmd=6869 scontext=u:r:hal_audio_default:s0 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1 2025-07-14 19:02:01.538 1413-2919 audio_hw_hal android.hardware.audio@2.0-service D raw_start_output_stream, stream=0xf5f1b000, sampleRate=48000, channel=2, bps=16, bufSize=4096 2025-07-14 19:02:01.539 5451-5478 AudioEngineImpl org.cocos2d.demo V play2d, _audioPlayers.size=0 2025-07-14 19:02:01.539 5451-5478 AudioPlayerProvider org.cocos2d.demo V (@assets/assets/game/native/c1/c1e23d2f-b7dc-44d4-91a4-8774e9abf939.261eb.mp3) file size: 179648 2025-07-14 19:02:01.540 5451-5478 UrlAudioPlayer org.cocos2d.demo V Current UrlAudioPlayer instance count: 1 2025-07-14 19:02:01.540 5451-5478 UrlAudioPlayer org.cocos2d.demo V UrlAudioPlayer::prepare: @assets/assets/game/native/c1/c1e23d2f-b7dc-44d4-91a4-8774e9abf939.261eb.mp3, SL_DATALOCATOR_ANDROIDFD, 98, 6980012, 179648 2025-07-14 19:02:01.540 5451-5478 <no-tag> org.cocos2d.demo D PlayerBase::PlayerBase() 2025-07-14 19:02:01.540 5451-5478 <no-tag> org.cocos2d.demo D TrackPlayerBase::TrackPlayerBase() 2025-07-14 19:02:01.541 1452-2087 NuPlayerDriver mediaserver D NuPlayerDriver(0xf4419800) created, clientPid(5451) 2025-07-14 19:02:01.542 1452-5511 GenericSource mediaserver D FileSource remote 2025-07-14 19:02:01.535 1413-1413 writer android.hardware.audio@2.0-service W type=1300 audit(0.0:1143): arch=40000003 syscall=54 per=8 success=yes exit=0 a0=6 a1=80046869 a2=f5f0f020 a3=f5f0f020 items=0 ppid=1 auid=4294967295 uid=1041 gid=1005 euid=1041 suid=1041 fsuid=1041 egid=1005 sgid=1005 fsgid=1005 tty=(none) ses=4294967295 exe="/system/vendor/bin/hw/android.hardware.audio@2.0-service" subj=u:r:hal_audio_default:s0 key=(null) 2025-07-14 19:02:01.544 1452-5510 NuPlayerDriver mediaserver D notifyListener_l(0xf4419800), (1, 0, 0, -1), loop setting(0, 0) 2025-07-14 19:02:01.535 1362-1362 auditd pid-1362 W type=1327 audit(0.0:1143): proctitle="/vendor/bin/hw/android.hardware.audio@2.0-service" 2025-07-14 19:02:01.545 1452-2087 NuPlayerDriver mediaserver D start(0xf4419800), state is 4, eos is 0 2025-07-14 19:02:01.545 1452-5510 GenericSource mediaserver I start 2025-07-14 19:02:01.547 1452-5514 OMXClient mediaserver I IOmx service obtained 2025-07-14 19:02:01.547 1458-1458 OMXMaster media.codec I makeComponentInstance(OMX.google.mp3.decoder) in omx@1.0-service process 2025-07-14 19:02:01.548 1458-1458 OMXNodeInstance media.codec E setConfig(0xf4f2c120:google.mp3.decoder, ConfigPriority(0x6f800002)) ERROR: Undefined(0x80001001) 2025-07-14 19:02:01.548 1452-5514 ACodec mediaserver I codec does not support config priority (err -2147483648) 2025-07-14 19:02:01.548 1458-1458 OMXNodeInstance media.codec E getConfig(0xf4f2c120:google.mp3.decoder, ConfigAndroidVendorExtension(0x6f100004)) ERROR: Undefined(0x80001001) 2025-07-14 19:02:01.549 1452-5514 MediaCodec mediaserver I MediaCodec will operate in async mode 2025-07-14 19:02:01.549 1410-1410 AshmemAllocator android.hidl.allocator@1.0-service W ashmem_create_region(8192) returning hidl_memory(0x76391702c100, 8192) 2025-07-14 19:02:01.550 1410-1410 chatty android.hidl.allocator@1.0-service I uid=1000(system) allocator@1.0-s identical 2 lines 2025-07-14 19:02:01.550 1410-1410 AshmemAllocator android.hidl.allocator@1.0-service W ashmem_create_region(8192) returning hidl_memory(0x76391702c100, 8192) 2025-07-14 19:02:01.551 1410-1410 AshmemAllocator android.hidl.allocator@1.0-service W ashmem_create_region(9216) returning hidl_memory(0x76391702c100, 9216) 2025-07-14 19:02:01.551 1410-1410 chatty android.hidl.allocator@1.0-service I uid=1000(system) allocator@1.0-s identical 2 lines 2025-07-14 19:02:01.552 1410-1410 AshmemAllocator android.hidl.allocator@1.0-service W ashmem_create_region(9216) returning hidl_memory(0x76391702c100, 9216) 2025-07-14 19:02:01.553 1434-5232 AudioFlinger audioserver W createTrack_l(): mismatch between requested flags (00000008) and output flags (00000002) 2025-07-14 19:02:01.553 1434-5232 AudioFlinger audioserver D Client defaulted notificationFrames to 3760 for frameCount 11280 2025-07-14 19:02:01.554 1452-5510 NuPlayerDriver mediaserver D notifyListener_l(0xf4419800), (6, 0, 0, -1), loop setting(0, 1) 2025-07-14 19:02:01.597 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:01.617 5451-5478 jswrapper org.cocos2d.demo D JS: 背景底图时间差 133 2025-07-14 19:02:01.675 1434-1539 AudioFlinger audioserver D mixer(0xf3483640) throttle end: throttle time(10) 2025-07-14 19:02:01.774 1434-1539 AudioFlinger audioserver D mixer(0xf3483640) throttle end: throttle time(10) 2025-07-14 19:02:01.817 1452-5510 NuPlayerDriver mediaserver D notifyListener_l(0xf4419800), (211, 0, 0, 20), loop setting(0, 1) 2025-07-14 19:02:02.016 5451-5478 jswrapper org.cocos2d.demo D JS: [game-logger] 格子保底数量: 1 2025-07-14 19:02:02.018 5451-5478 jswrapper org.cocos2d.demo D JS: [game-logger] 触发格子保底: 0 2025-07-14 19:02:02.020 5451-5478 chatty org.cocos2d.demo I uid=10051(org.cocos2d.demo) GLThread 168 identical 1 line 2025-07-14 19:02:02.021 5451-5478 jswrapper org.cocos2d.demo D JS: [game-logger] 触发格子保底: 0 2025-07-14 19:02:02.075 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:02.075 1452-5510 NuPlayerDriver mediaserver D notifyListener_l(0xf4419800), (211, 0, 0, 20), loop setting(0, 1) 2025-07-14 19:02:02.203 5451-5478 AudioEngineImpl org.cocos2d.demo V play2d, _audioPlayers.size=1 2025-07-14 19:02:02.203 5451-5478 AudioPlayerProvider org.cocos2d.demo V (@assets/assets/game/native/92/921f296e-e66d-4abd-89b5-5278346f0cd6.d3c80.mp3) file size: 3305 2025-07-14 19:02:02.204 5451-5478 AudioPlayerProvider org.cocos2d.demo V FileInfo (0x763874c2e030), Waiting preload (@assets/assets/game/native/92/921f296e-e66d-4abd-89b5-5278346f0cd6.d3c80.mp3) to finish ... 2025-07-14 19:02:02.204 5451-5506 AudioPlayerProvider org.cocos2d.demo V AudioPlayerProvider::preloadEffect: (@assets/assets/game/native/92/921f296e-e66d-4abd-89b5-5278346f0cd6.d3c80.mp3) 2025-07-14 19:02:02.204 5451-5506 AudioDecoderProvider org.cocos2d.demo V url:@assets/assets/game/native/92/921f296e-e66d-4abd-89b5-5278346f0cd6.d3c80.mp3, extension:.mp3 2025-07-14 19:02:02.204 5451-5506 AudioDecoderMp3 org.cocos2d.demo V Create AudioDecoderMp3 2025-07-14 19:02:02.205 5451-5506 mp3reader org.cocos2d.demo V skipped ID3 tag, new starting offset is 172 (0x00000000000000ac) 2025-07-14 19:02:02.205 5451-5506 mp3reader org.cocos2d.demo V subsequent header is fff38064 2025-07-14 19:02:02.205 5451-5506 mp3reader org.cocos2d.demo V found subsequent frame #2 at 380 2025-07-14 19:02:02.205 5451-5506 mp3reader org.cocos2d.demo V subsequent header is fff38264 2025-07-14 19:02:02.205 5451-5506 mp3reader org.cocos2d.demo V found subsequent frame #3 at 588 2025-07-14 19:02:02.205 5451-5506 mp3reader org.cocos2d.demo V subsequent header is fff38264 2025-07-14 19:02:02.205 5451-5506 mp3reader org.cocos2d.demo V found subsequent frame #4 at 797 2025-07-14 19:02:02.245 5451-5506 AudioDecoderMp3 org.cocos2d.demo I Original audio info: numChannels: 2, sampleRate: 22050, bitPerSample: 16, containerSize: 16, channelMask: 3, endianness: 2, numFrames: 8640, duration: 0.391837, total size: 34560 2025-07-14 19:02:02.245 5451-5506 AudioDecoder org.cocos2d.demo D Decoding (@assets/assets/game/native/92/921f296e-e66d-4abd-89b5-5278346f0cd6.d3c80.mp3) to pcm data wasted 40.580002ms 2025-07-14 19:02:02.245 5451-5506 AudioDecoder org.cocos2d.demo V Resample: 22050 --> 48000 2025-07-14 19:02:02.245 5451-5506 AudioResampler org.cocos2d.demo V resampler load 0 -> 6 MHz due to delta +6 MHz from quality 2 2025-07-14 19:02:02.245 5451-5506 AudioResampler org.cocos2d.demo V Create cubic Resampler 2025-07-14 19:02:02.245 5451-5506 AudioDecoder org.cocos2d.demo V resample() 18808 output frames 2025-07-14 19:02:02.247 5451-5506 AudioDecoder org.cocos2d.demo V outFrames: 18808 2025-07-14 19:02:02.247 5451-5506 AudioDecoder org.cocos2d.demo V resample() complete 2025-07-14 19:02:02.247 5451-5506 AudioDecoder org.cocos2d.demo V reset() complete 2025-07-14 19:02:02.247 5451-5506 AudioResampler org.cocos2d.demo V resampler load 6 -> 0 MHz due to delta -6 MHz from quality 2 2025-07-14 19:02:02.252 5451-5506 AudioDecoder org.cocos2d.demo V pcm buffer size: 75232 2025-07-14 19:02:02.254 5451-5506 AudioDecoder org.cocos2d.demo D Resampling (@assets/assets/game/native/92/921f296e-e66d-4abd-89b5-5278346f0cd6.d3c80.mp3) wasted 8.943000ms 2025-07-14 19:02:02.254 5451-5506 AudioDecoder org.cocos2d.demo I Audio channel count is 2, no need to interleave 2025-07-14 19:02:02.254 5451-5506 AudioDecoder org.cocos2d.demo D Interleave (@assets/assets/game/native/92/921f296e-e66d-4abd-89b5-5278346f0cd6.d3c80.mp3) wasted 0.104000ms 2025-07-14 19:02:02.254 5451-5506 AudioPlayerProvider org.cocos2d.demo V decode succeed 2025-07-14 19:02:02.254 5451-5506 AudioPlayerProvider org.cocos2d.demo V preload (@assets/assets/game/native/92/921f296e-e66d-4abd-89b5-5278346f0cd6.d3c80.mp3) callback count: 1 2025-07-14 19:02:02.254 5451-5506 AudioPlayerProvider org.cocos2d.demo V FileInfo (0x763874c2e030), Set isSucceed flag: 1, path: @assets/assets/game/native/92/921f296e-e66d-4abd-89b5-5278346f0cd6.d3c80.mp3 2025-07-14 19:02:02.254 5451-5478 AudioPlayerProvider org.cocos2d.demo V FileInfo (0x763874c2e030), Waitup preload (@assets/assets/game/native/92/921f296e-e66d-4abd-89b5-5278346f0cd6.d3c80.mp3) ... 2025-07-14 19:02:02.254 5451-5506 AudioDecoder org.cocos2d.demo V ~AudioDecoder() 0x7638889762f0 2025-07-14 19:02:02.255 5451-5478 PcmAudioPlayer org.cocos2d.demo V PcmAudioPlayer constructor: 0x76387a63e020 2025-07-14 19:02:02.255 5451-5478 AssetFd org.cocos2d.demo V ~AssetFd: 11 2025-07-14 19:02:02.255 5451-5478 PcmAudioPlayer org.cocos2d.demo V PcmAudioPlayer (0x76387a63e020) play, url: @assets/assets/game/native/92/921f296e-e66d-4abd-89b5-5278346f0cd6.d3c80.mp3 2025-07-14 19:02:02.301 5451-5478 jswrapper org.cocos2d.demo D JS: [game-logger] 1334 2025-07-14 19:02:02.332 1452-5510 NuPlayerDriver mediaserver D notifyListener_l(0xf4419800), (211, 0, 0, 20), loop setting(0, 1) 2025-07-14 19:02:02.409 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:02.590 1452-5510 NuPlayerDriver mediaserver D notifyListener_l(0xf4419800), (211, 0, 0, 20), loop setting(0, 1) 2025-07-14 19:02:02.617 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:02.636 5451-5478 chatty org.cocos2d.demo I uid=10051(org.cocos2d.demo) GLThread 168 identical 1 line 2025-07-14 19:02:02.660 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:02.677 5451-5507 AudioMixerController org.cocos2d.demo V Play over ... 2025-07-14 19:02:02.677 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:02.677 5451-5507 AudioMixerController org.cocos2d.demo V Doesn't have enough tracks: 1, 1 2025-07-14 19:02:02.680 5451-5478 AudioEngineImpl org.cocos2d.demo V Removing player id=1, state:5 2025-07-14 19:02:02.680 5451-5478 PcmAudioPlayer org.cocos2d.demo V In the destructor of PcmAudioPlayer (0x76387a63e020) 2025-07-14 19:02:02.680 5451-5478 Track org.cocos2d.demo V ~Track(): 0x7638705f4880 2025-07-14 19:02:02.690 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:02.774 5451-5478 chatty org.cocos2d.demo I uid=10051(org.cocos2d.demo) GLThread 168 identical 7 lines 2025-07-14 19:02:02.787 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:02.789 1411-1411 healthd healthd I type=1400 audit(0.0:1144): avc: denied { read } for name="present" dev="sysfs" ino=6625 scontext=u:r:healthd:s0 tcontext=u:object_r:sysfs:s0 tclass=file permissive=1 2025-07-14 19:02:02.789 1411-1411 healthd healthd I type=1400 audit(0.0:1144): avc: denied { open } for path="/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A03:00/PNP0C0A:00/power_supply/BAT0/present" dev="sysfs" ino=6625 scontext=u:r:healthd:s0 tcontext=u:object_r:sysfs:s0 tclass=file permissive=1 2025-07-14 19:02:02.789 1411-1411 healthd healthd W type=1300 audit(0.0:1144): arch=c000003e syscall=257 success=yes exit=9 a0=ffffff9c a1=763917028360 a2=a0000 a3=0 items=0 ppid=1 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 exe="/system/bin/healthd" subj=u:r:healthd:s0 key=(null) 2025-07-14 19:02:02.797 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:02.823 5451-5478 chatty org.cocos2d.demo I uid=10051(org.cocos2d.demo) GLThread 168 identical 2 lines 2025-07-14 19:02:02.834 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 2025-07-14 19:02:02.848 1452-5510 NuPlayerDriver mediaserver D notifyListener_l(0xf4419800), (211, 0, 0, 20), loop setting(0, 1) 2025-07-14 19:02:02.848 5451-5478 HostConnection org.cocos2d.demo D glGetError exceeded. 解决问题了吗
07-15
// MonsterController.ts import { _decorator, Component, find, Node, ProgressBar, sp, Vec3 } from 'cc'; const { ccclass, property } = _decorator; import { GameManager } from './GameManager'; import { EquipmentManager } from './EquipmentManager'; @ccclass('MonsterController') export class MonsterController extends Component { // 状态属性 public isMove: boolean = false; // 是否行走 public isAttack: boolean = false; // 是否攻击 public isStand: boolean = true; // 是否静止(默认状态) public isDie: boolean = false; // 是否死亡 // 体型属性(单位:像素) @property({ type: Number, tooltip: "怪兽的碰撞半径(像素)" }) public MonsterSize: number = 40; // 默认值40像素 // 血量属性 private _hp: number = 100; // 当前血量 private _maxHp: number = 100; // 最大血量 // Spine动画组件引用 private spineComponent: sp.Skeleton | null = null; // 血条组件引用 private healthBar: ProgressBar | null = null; // 动画名称配置 private animationNames = { move: "move", stand: "m_stand_1", attack: "m_attack_1_a", // 攻击动画 die: "die" }; //怪兽默认攻击力 public attackDamage: number = 10; // 攻击相关属性 private attackTimer: number = 0; // 攻击动画计时器 private isAttackLocked: boolean = false; // 是否处于攻击锁定状态 private attackAnimationDuration: number = 1; // 默认攻击动画时长 private damageTriggerTime: number = 0.5; // 默认伤害触发时间点 protected onLoad(): void { // 获取Spine动画组件 this.spineComponent = this.node.getComponent(sp.Skeleton); if (!this.spineComponent) { console.warn(`[${this.node.name}] No sp.Skeleton component found!`); } // 获取血条组件 const healthBarNode = this.node.getChildByName('HealthBar'); if (healthBarNode) { this.healthBar = healthBarNode.getComponent(ProgressBar); if (!this.healthBar) { console.warn(`[${this.node.name}] HealthBar node found but no ProgressBar component!`); } } else { console.warn(`[${this.node.name}] HealthBar node not found!`); } // 初始播放站立动画 this.playAnimation(this.animationNames.stand); // 初始更新血条 this.updateHealthBar(); // 根据怪兽类型设置攻击参数 this.setAttackParameters(); } /** * 根据怪兽类型设置攻击参数 */ private setAttackParameters() { // 提取怪兽类型(名称前缀) const monsterType = this.node.name.split('_')[0]; // 设置攻击参数 switch(monsterType) { case 'baishe': // 白蛇 this.attackAnimationDuration = 0.9667; this.damageTriggerTime = 0.5333; break; case 'yuren': // 鱼人 this.attackAnimationDuration = 0.9667; this.damageTriggerTime = 0.5667; break; case 'langren': // 狼人 this.attackAnimationDuration = 1.0; this.damageTriggerTime = 0.3667; break; case 'baixiong': // 白熊 this.attackAnimationDuration = 1.0; this.damageTriggerTime = 0.5667; break; case 'moshou': // 魔兽 this.attackAnimationDuration = 1.0; this.damageTriggerTime = 0.5667; break; case 'wugong': // 蜈蚣 this.attackAnimationDuration = 1.0; this.damageTriggerTime = 0.6; break; case 'yezhu': // 野猪 this.attackAnimationDuration = 0.5; this.damageTriggerTime = 0.4; break; default: // 使用默认值 break; } console.log(`[${this.node.name}] attack params: duration=${this.attackAnimationDuration}, trigger=${this.damageTriggerTime}`); } // 切换状态的方法 public setState(newState: 'move' | 'attack' | 'stand' | 'die') { // 如果当前状态相同,不重复设置 if ((newState === 'move' && this.isMove) || (newState === 'attack' && this.isAttack) || (newState === 'stand' && this.isStand) ) { return; } this.isMove = false; this.isAttack = false; this.isStand = false; this.isDie = false; // 设置新状态 switch(newState) { case 'move': this.isMove = true; this.playAnimation(this.animationNames.move, true); break; case 'attack': this.isAttack = true; this.isAttackLocked = true; this.attackTimer = 0; // 播放一次攻击动画 this.playAnimation(this.animationNames.attack, false); break; case 'stand': this.isStand = true; this.playAnimation(this.animationNames.stand, true); break; case 'die': this.isDie = true; this.playAnimation(this.animationNames.die, false); // 1秒后销毁节点并获得装备 setTimeout(() => { // 提取怪兽类型(名称前缀) const monsterType = this.node.name.split('_')[0]; // 获取装备管理器 const equipmentManager = find("Canvas/UI/Equips")?.getComponent(EquipmentManager); if (equipmentManager) { // 在怪物死亡位置生成装备 equipmentManager.dropEquipment(monsterType, this.node.worldPosition); } setTimeout(() => { if (this.node && this.node.isValid) { this.node.destroy(); }}, 500); }, 1000); break; } console.log(`[${this.node.name}] state changed to: ${newState}`); console.log(`[${this.node.name}] 怪兽的新状态是: ${newState}`); } /** * 播放指定动画 * @param animationName 动画名称 * @param loop 是否循环播放 */ private playAnimation(animationName: string, loop: boolean = true) { if (!this.spineComponent) return; // 检查动画是否存在 if (!this.spineComponent.findAnimation(animationName)) { console.warn(`[${this.node.name}] Animation '${animationName}' not found!`); return; } // 播放动画 this.spineComponent.setAnimation(0, animationName, loop); console.log(`[${this.node.name}] playing animation: ${animationName}${loop ? " (looping)" : ""}`); } // 设置体型大小 public setMonsterSize(size: number) { this.MonsterSize = size; console.log(`[${this.node.name}] size set to: ${size}px`); } // 设置初始血量 public setMaxHp(maxHp: number) { this._maxHp = maxHp; this._hp = maxHp; console.log(`[${this.node.name}] max HP set to: ${maxHp}`); // 更新血条 this.updateHealthBar(); } // 更新血条显示 private updateHealthBar() { if (!this.healthBar) return; // 计算血量百分比 (0-1) const hpRatio = this._hp / this._maxHp; // 设置进度条值 this.healthBar.progress = hpRatio; console.log(`[${this.node.name}] HealthBar updated: ${hpRatio * 100}%`); } /** * 受到伤害 - 修改为立即减少血量 * @param damage 伤害值 */ public takeDamage(damage: number) { // 如果已死亡,忽略伤害 if (this.isDie) return; // +++ 立即减少血量 +++ this._hp = Math.max(0, this._hp - damage); // 更新血条 this.updateHealthBar(); console.log(`[${this.node.name}] took ${damage} damage, HP: ${this._hp}/${this._maxHp}`); if (this._hp <= 0) { // 血量耗尽,死亡 this.setState('die'); // 通知游戏管理器增加经验值 this.notifyGameManager(); } } /** * 通知游戏管理器增加经验值 */ private notifyGameManager() { // 获取游戏管理器 const gameManager = find("Canvas")?.getComponent(GameManager); if (gameManager) { // 提取怪兽类型(名称前缀) const monsterType = this.node.name.split('_')[0]; // 通知游戏管理器增加经验值 gameManager.addExperience(monsterType); } } // 获取当前血量百分比(0-1) public getHpRatio(): number { return this._hp / this._maxHp; } // 获取当前血量 public getCurrentHp(): number { return this._hp; } // 获取最大血量 public getMaxHp(): number { return this._maxHp; } // 设置怪兽攻击力 public setAttackDamage(damage: number) { this.attackDamage = damage; console.log(`[${this.node.name}] attack damage set to: ${damage}`); } // 添加冻结状态 public isFrozen: boolean = false; // 更新方法 update(deltaTime: number) { // 如果被冻结,不执行任何更新 if (this.isFrozen) return; // 处理攻击锁定状态 if (this.isAttackLocked) { this.attackTimer += deltaTime; // 检查是否到达伤害触发时间点 if (this.attackTimer >= this.damageTriggerTime && !this.damageTriggered) { this.triggerAttackDamage(); this.damageTriggered = true; } // 检查攻击动画是否结束 if (this.attackTimer >= this.attackAnimationDuration) { this.isAttackLocked = false; this.damageTriggered = false; // 攻击结束,切换为站立状态 this.setState('stand'); } } } private damageTriggered: boolean = false; /** * 触发攻击伤害 */ private triggerAttackDamage() { // 获取游戏管理器 const gameManager = find("Canvas")?.getComponent(GameManager); if (gameManager) { // 对英雄造成伤害 gameManager.takeHeroDamage(this.attackDamage); } } }// MonsterController.ts import { _decorator, Component, find, Node, ProgressBar, sp, Vec3 } from 'cc'; const { ccclass, property } = _decorator; import { GameManager } from './GameManager'; import { EquipmentManager } from './EquipmentManager'; @ccclass('MonsterController') export class MonsterController extends Component { // 状态属性 public isMove: boolean = false; // 是否行走 public isAttack: boolean = false; // 是否攻击 public isStand: boolean = true; // 是否静止(默认状态) public isDie: boolean = false; // 是否死亡 // 体型属性(单位:像素) @property({ type: Number, tooltip: "怪兽的碰撞半径(像素)" }) public MonsterSize: number = 40; // 默认值40像素 // 血量属性 private _hp: number = 100; // 当前血量 private _maxHp: number = 100; // 最大血量 // Spine动画组件引用 private spineComponent: sp.Skeleton | null = null; // 血条组件引用 private healthBar: ProgressBar | null = null; // 动画名称配置 private animationNames = { move: "move", stand: "m_stand_1", attack: "m_attack_1_a", // 攻击动画 die: "die" }; //怪兽默认攻击力 public attackDamage: number = 10; // 攻击相关属性 private attackTimer: number = 0; // 攻击动画计时器 private isAttackLocked: boolean = false; // 是否处于攻击锁定状态 private attackAnimationDuration: number = 1; // 默认攻击动画时长 private damageTriggerTime: number = 0.5; // 默认伤害触发时间点 protected onLoad(): void { // 获取Spine动画组件 this.spineComponent = this.node.getComponent(sp.Skeleton); if (!this.spineComponent) { console.warn(`[${this.node.name}] No sp.Skeleton component found!`); } // 获取血条组件 const healthBarNode = this.node.getChildByName('HealthBar'); if (healthBarNode) { this.healthBar = healthBarNode.getComponent(ProgressBar); if (!this.healthBar) { console.warn(`[${this.node.name}] HealthBar node found but no ProgressBar component!`); } } else { console.warn(`[${this.node.name}] HealthBar node not found!`); } // 初始播放站立动画 this.playAnimation(this.animationNames.stand); // 初始更新血条 this.updateHealthBar(); // 根据怪兽类型设置攻击参数 this.setAttackParameters(); } /** * 根据怪兽类型设置攻击参数 */ private setAttackParameters() { // 提取怪兽类型(名称前缀) const monsterType = this.node.name.split('_')[0]; // 设置攻击参数 switch(monsterType) { case 'baishe': // 白蛇 this.attackAnimationDuration = 0.9667; this.damageTriggerTime = 0.5333; break; case 'yuren': // 鱼人 this.attackAnimationDuration = 0.9667; this.damageTriggerTime = 0.5667; break; case 'langren': // 狼人 this.attackAnimationDuration = 1.0; this.damageTriggerTime = 0.3667; break; case 'baixiong': // 白熊 this.attackAnimationDuration = 1.0; this.damageTriggerTime = 0.5667; break; case 'moshou': // 魔兽 this.attackAnimationDuration = 1.0; this.damageTriggerTime = 0.5667; break; case 'wugong': // 蜈蚣 this.attackAnimationDuration = 1.0; this.damageTriggerTime = 0.6; break; case 'yezhu': // 野猪 this.attackAnimationDuration = 0.5; this.damageTriggerTime = 0.4; break; default: // 使用默认值 break; } console.log(`[${this.node.name}] attack params: duration=${this.attackAnimationDuration}, trigger=${this.damageTriggerTime}`); } // 切换状态的方法 public setState(newState: 'move' | 'attack' | 'stand' | 'die') { // 如果当前状态相同,不重复设置 if ((newState === 'move' && this.isMove) || (newState === 'attack' && this.isAttack) || (newState === 'stand' && this.isStand) ) { return; } this.isMove = false; this.isAttack = false; this.isStand = false; this.isDie = false; // 设置新状态 switch(newState) { case 'move': this.isMove = true; this.playAnimation(this.animationNames.move, true); break; case 'attack': this.isAttack = true; this.isAttackLocked = true; this.attackTimer = 0; // 播放一次攻击动画 this.playAnimation(this.animationNames.attack, false); break; case 'stand': this.isStand = true; this.playAnimation(this.animationNames.stand, true); break; case 'die': this.isDie = true; this.playAnimation(this.animationNames.die, false); // 1秒后销毁节点并获得装备 setTimeout(() => { // 提取怪兽类型(名称前缀) const monsterType = this.node.name.split('_')[0]; // 获取装备管理器 const equipmentManager = find("Canvas/UI/Equips")?.getComponent(EquipmentManager); if (equipmentManager) { // 在怪物死亡位置生成装备 equipmentManager.dropEquipment(monsterType, this.node.worldPosition); } setTimeout(() => { if (this.node && this.node.isValid) { this.node.destroy(); }}, 500); }, 1000); break; } console.log(`[${this.node.name}] state changed to: ${newState}`); console.log(`[${this.node.name}] 怪兽的新状态是: ${newState}`); } /** * 播放指定动画 * @param animationName 动画名称 * @param loop 是否循环播放 */ private playAnimation(animationName: string, loop: boolean = true) { if (!this.spineComponent) return; // 检查动画是否存在 if (!this.spineComponent.findAnimation(animationName)) { console.warn(`[${this.node.name}] Animation '${animationName}' not found!`); return; } // 播放动画 this.spineComponent.setAnimation(0, animationName, loop); console.log(`[${this.node.name}] playing animation: ${animationName}${loop ? " (looping)" : ""}`); } // 设置体型大小 public setMonsterSize(size: number) { this.MonsterSize = size; console.log(`[${this.node.name}] size set to: ${size}px`); } // 设置初始血量 public setMaxHp(maxHp: number) { this._maxHp = maxHp; this._hp = maxHp; console.log(`[${this.node.name}] max HP set to: ${maxHp}`); // 更新血条 this.updateHealthBar(); } // 更新血条显示 private updateHealthBar() { if (!this.healthBar) return; // 计算血量百分比 (0-1) const hpRatio = this._hp / this._maxHp; // 设置进度条值 this.healthBar.progress = hpRatio; console.log(`[${this.node.name}] HealthBar updated: ${hpRatio * 100}%`); } /** * 受到伤害 - 修改为立即减少血量 * @param damage 伤害值 */ public takeDamage(damage: number) { // 如果已死亡,忽略伤害 if (this.isDie) return; // +++ 立即减少血量 +++ this._hp = Math.max(0, this._hp - damage); // 更新血条 this.updateHealthBar(); console.log(`[${this.node.name}] took ${damage} damage, HP: ${this._hp}/${this._maxHp}`); if (this._hp <= 0) { // 血量耗尽,死亡 this.setState('die'); // 通知游戏管理器增加经验值 this.notifyGameManager(); } } /** * 通知游戏管理器增加经验值 */ private notifyGameManager() { // 获取游戏管理器 const gameManager = find("Canvas")?.getComponent(GameManager); if (gameManager) { // 提取怪兽类型(名称前缀) const monsterType = this.node.name.split('_')[0]; // 通知游戏管理器增加经验值 gameManager.addExperience(monsterType); } } // 获取当前血量百分比(0-1) public getHpRatio(): number { return this._hp / this._maxHp; } // 获取当前血量 public getCurrentHp(): number { return this._hp; } // 获取最大血量 public getMaxHp(): number { return this._maxHp; } // 设置怪兽攻击力 public setAttackDamage(damage: number) { this.attackDamage = damage; console.log(`[${this.node.name}] attack damage set to: ${damage}`); } // 添加冻结状态 public isFrozen: boolean = false; // 更新方法 update(deltaTime: number) { // 如果被冻结,不执行任何更新 if (this.isFrozen) return; // 处理攻击锁定状态 if (this.isAttackLocked) { this.attackTimer += deltaTime; // 检查是否到达伤害触发时间点 if (this.attackTimer >= this.damageTriggerTime && !this.damageTriggered) { this.triggerAttackDamage(); this.damageTriggered = true; } // 检查攻击动画是否结束 if (this.attackTimer >= this.attackAnimationDuration) { this.isAttackLocked = false; this.damageTriggered = false; // 攻击结束,切换为站立状态 this.setState('stand'); } } } private damageTriggered: boolean = false; /** * 触发攻击伤害 */ private triggerAttackDamage() { // 获取游戏管理器 const gameManager = find("Canvas")?.getComponent(GameManager); if (gameManager) { // 对英雄造成伤害 gameManager.takeHeroDamage(this.attackDamage); } } }有一段报错Uncaught TypeError: Cannot read properties of null (reading 'name') at MonsterController.ts:162:51
最新发布
07-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值