Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Cocos2d html5无法将属性src设置为null_Javascript_Cocos2d X_Cocos2d Html5 - Fatal编程技术网

Javascript Cocos2d html5无法将属性src设置为null

Javascript Cocos2d html5无法将属性src设置为null,javascript,cocos2d-x,cocos2d-html5,Javascript,Cocos2d X,Cocos2d Html5,查看时获取主题错误: 请注意,我使用的是2.1.2测试版,因此我知道教程中会有不同之处。以下是我目前掌握的代码: (function() { var AppLayer = cc.LayerColor.extend({ init: function() { this._super(new cc.Color4B(0, 0, 0, 255)); var size = cc.Director.getInstance().getWinSize(); this

查看时获取主题错误:

请注意,我使用的是2.1.2测试版,因此我知道教程中会有不同之处。以下是我目前掌握的代码:

(function() {
  var AppLayer = cc.LayerColor.extend({
    init: function() {
      this._super(new cc.Color4B(0, 0, 0, 255));
      var size = cc.Director.getInstance().getWinSize();
      this._jetSprite = new JetSprite();
      this.setTouchEnabled(true);
      this.setKeyboardEnabled(true);
      this.setPosition(new cc.Point(0, 0));

      this.addChild(this._jetSprite);
      this._jetSprite.setPosition(new cc.Point(size.width / 2, size.height / 2));
      this._jetSprite.scheduleUpdate();
      this.schedule(this.update);
      return true;
    },
    _jetSprite: null,
    onEnter: function() {
      this._super();
    },
    onKeyDown: function(e) {
      this._jetSprite.handleKey(e);
    },
    onKeyUp: function() {

    },
    onTouchesEnded: function(pTouch, pEvent) {
      this._jetSprite.handleTouch(pTouch[0].getLocation());
    },
    onTouchesMoved: function(pTouch, pEvent) {
      this._jetSprite.handleTouchMove(pTouch[0].getLocation());
    },
    update: function(dt) {

    }
  });


  window.AppScene = cc.Scene.extend({
    onEnter: function() {
      this._super();
      var layer = new AppLayer();
      layer.init();
      this.addChild(layer);
    }
  });
})();

var JetSprite = cc.Sprite.extend({
  _currentRotation:0,
  ctor: function() {
    this.initWithFile("images/jet.png");
  },
  handleKey: function(e) {
    if(e == cc.KEY.left) {
      this._currentRotation--;
    }
    else if(e == cc.KEY.right) {
      this._currentRotation++;
    }

    if(this._currentRotation < 0) {
      this._currentRotation = 360;
    }
    if(this._currentRotation > 360) {
      this._currentRotation = 0;
    }
  },
  handleTouch: function(touchLocation) {
    if(touchLocation.x < 300) {
      this._currentRotation = 0;
    }
    else {
      this._currentRotation = 180;
    }
  },
  handleTouchMove: function(touchLocation) {
    var angle = Math.atan2(touchLocation.x - 300, touchLocation.y - 300);

    angle = angle * (180/Math.PI);
    this._currentRotation = angle;
  },
  update: function(dt) {
    this.setRotation(this._currentRotation);
  }
});

看起来我之前的教程缺了一行。ctor函数需要一个this.\u super(),以便正确初始化所有内容

var JetSprite = cc.Sprite.extend({
  _currentRotation:0,
  ctor: function() {
    this._super();
    this.initWithFile("images/jet.png");
  },
var JetSprite = cc.Sprite.extend({
  _currentRotation:0,
  ctor: function() {
    this._super();
    this.initWithFile("images/jet.png");
  },