@magicgamestudios wrote:
Hi I've a scene with this code
cc.Class({
extends: cc.Component,properties: { btnStarGameNode: { default: null, type: cc.Node }, btnSettingsNode: { default: null, type: cc.Node }, buttonAudio: { default: null, url: cc.AudioClip }, backgroundMusic: { default: null, url: cc.AudioClip }, playerPrefab: { default: null, type: cc.Prefab } }, // use this for initialization onLoad: function () { var scene = cc.director.getScene(); cc.audioEngine.playMusic(this.backgroundMusic, true); cc.audioEngine.setMusicVolume(0.2); var player = cc.instantiate(this.playerPrefab); player.parent = scene; player.setPosition(cc.p(0, 0)); player.zIndex = 10; player.getComponent() player.playIdle();
}
This is the prefab script
cc.Class({
extends: cc.Component,properties: { // main character's jump height jumpHeight: 200, // main character's jump duration jumpDuration: 0, // maximal movement speed maxMoveSpeed: 0, // acceleration accel: 0, animation: { default:[], type: cc.Animation } }, // use this for initialization onLoad: function () { }, playIdle: function() { var anim = this.animation; anim.play('idle'); } // called every frame, uncomment this function to activate update callback // update: function (dt) { // },
});
How can I access to prefab properties from scene. I try player.jumpHeight and player.getComponent('jumpHeight'). I try access a method playIdle from gamescene player.playIdle(); but return an error "playIdle is not a function"
Posts: 2
Participants: 2