Hi, recently, I’ve been having a pair of issues with Cocos Creator. First, gravity is incredibly slow when the player falls after coming in contact with the top of an object. In the past, I’ve been using cc.director.getPhysicsManager().gravity = cc.v2 (); to override the gravity issue, however, this was only a temporary fix (other non-player things are also affected) and I am unsure what is causing this.
Secondly, the cc.director.resume function is not working properly after many attempts to get it to work. The second issue generates a bunch of error messages to the browser console, namely the messages “The thing you want to instantiate is nil”, “TypeError: child is null”, and “TypeError: notifBox is undefined”, even when the correct resource has been dropped into the provided slot in Cocos Creator. I have posted the code below.
Thanks!
cc.Class({
extends: cc.Component,
properties: {
notifBoxPrefab: {
default: null,
type: cc.Prefab
},
okPrefab: {
default: null,
type: cc.Prefab
},
backPrefab: {
default: null,
type: cc.Prefab
},
textButtonPrefab: {
default: null,
type: cc.Prefab
},
textLabel: {
default: null,
type: cc.Label
},
},
// LIFE-CYCLE CALLBACKS:
onLoad: function () {},
loadLvlSelect: function (event) {
cc.director.loadScene('Lvl Select');
cc.director.preloadScene('Lvl One');
cc.director.preloadScene('Lvl Two');
cc.director.preloadScene('Lvl Three');
cc.director.preloadScene('Lvl Four');
cc.director.preloadScene('Test Lvl');
cc.director.preloadScene('P-A-L');
cc.director.preloadScene('Misc');
},
loadLvlOne: function (event) {
cc.director.loadScene('Lvl One');
},
loadLvlTwo: function (event) {
cc.director.loadScene('Lvl Two');
},
loadLvlThree: function (event) {
cc.director.loadScene('Lvl Three');
},
loadLvlFour: function (event) {
cc.director.loadScene('Lvl Four');
},
backToMain: function (event) {
cc.director.loadScene('Main Menu');
},
loadTestLvl: function (event) {
cc.director.loadScene('Test Lvl');
},
loadProjectiles: function (event) {
cc.director.loadScene('P-A-L');
},
loadMisc: function (event) {
cc.director.loadScene('Misc');
},
showNotifBox: function (event) {
var newNotif = cc.instantiate(this.notifBoxPrefab);
this.node.zIndex = 1;
this.node.addChild(newNotif);
newNotif.setPosition(cc.v2(20, 240));
var backButton = cc.instantiate(this.backPrefab);
this.node.zIndex = 2;
this.node.addChild(backButton);
backButton.setPosition(cc.v2(-265, 445));
},
closeNotifBox: function (event) {
this.node.destroy(this.notifBoxPrefab);
this.node.destroy(this.backPrefab);
},
pauseGame: function () {
cc.director.pause();
var newNotif = cc.instantiate(this.notifBoxPrefab);
this.node.zIndex = 1;
this.node.addChild(newNotif);
newNotif.setPosition(cc.v2(415, -260));
var newOK = cc.instantiate(this.okPrefab);
this.node.zIndex = 2;
this.node.addChild(newOK);
newOK.setPosition(cc.v2(605, -370));
//This button keeps relocating the other two prefabs above it
var newTButton = cc.instantiate(this.textButtonPrefab);
this.node.zIndex = 2;
this.node.addChild(newTButton);
newNotif.setPosition(cc.v2(415, -260));
},
runGame: function () {
var notifBox = notifBox.node.name === "newNotif";
//have also tried "var notifBox = this.notifBoxPrefab;"
if (notifBox.isValid == true) {
this.node.destroy(notifBox);
cc.director.resume();
}
},
// update (dt) {}
});