问答详情
源自:3-5 大鱼喂小鱼实特效(2)

draw绘制不出来

代码看了好几遍都是一样的但是就是打印不出来

提问者:蔬菜果酱 2016-07-02 21:34

个回答

  • 慕仔8415870
    2020-04-27 08:53:50

    halo.JS

    haloObj.prototype.born=function(x,y)

    {

    for(var i=0;i<this.num;i++)

    {

    if(!this.alive[i])

    {

    this.x[i]=x;

    this.y[i]=y;

    this.r[i]=10;

    this.alive[i]=true;


    }

    }

    }

    代码遗落了一个        “ !”字符

    if(!this.alive[i])           加上就好了“ !”字符

  • vanish_
    2017-01-26 11:56:26

    已解决,忘记改成初始化this.alive[i] == true

  • vanish_
    2017-01-26 11:52:06

    var haloObj = function()

    {

    this.x = [];

    this.y = [];

    this.alive = [];

    this.r = [];

    }

    haloObj.prototype.num = 5;

    haloObj.prototype.init = function()

    {

    for (var i = 0; i < this.num; i++)

    {

    this.x[i] = 0;

    this.y[i] = 0;

    this.alive[i] = false;

    this.r[i] = 0;

    }

    }

    haloObj.prototype.draw = function()

    {

    ctx1.save();

    ctx1.lineWidth = 2;

    ctx1.shadowBlur = 10;

    ctx1.shadowColor = "rgba(123,123,123,1)";

    for (var i = 0; i < this.num ;i++)

    {

    if (this.alive[i])

    {

    alert("123");

    this.r[i] += deltaTime * 0.05;

    if (this.r[i] > 100)

    {

    this.alive[i] = false;

    break;

    }

    var alpha = 1 - this.r[i] / 100;


    ctx1.beginPath();

    ctx1.arc(this.x[i], this.y[i], this.r[i], 0 , Math.PI *2);

    ctx1.closePath();

    ctx1.strokeStyle = "rgba(123,123,123,"+ alpha +")";

    ctx1.stroke();

    }

    }

    ctx1.restore();

    }

    haloObj.prototype.born = function(x, y)

    {

    for (var i = 0; i < this.num; i++)

    {

    if (this.alive[i])

    {

    this.x[i] = x;

    this.y[i] = y;

    this.r[i] = 10;

    this.alive[i] = true; 

    return;

    }

    }

    }



  • 尐调_
    2016-07-04 22:13:00

    这位同学,能把代码贴出来看一下吗?