0

New to JS, and web programming.

I have an image moving in the horizontal axis on a canvas. WHen the image gets to a certain point I want it to stop, scale and then rotate. The method i'm using causes an infinite loop and I can't see why.

Here's the method being called

 while(this.getScale()<= this.mScale * 5)
        this.mScale += 0.5;

 while(this.getRotation() <= 360)
        this.mRotation += 5;

this.mX += 10; 

 if(this.goingRight){
        this.mX += 5;
    }
    else
        this.mX -=5;

And here's where it's called

update()
...
if(this.mX >400 && this.mX < 403)
        this.rotateAndScale();

I'm from a C#/C++ background so this in my eyes should have the effect of halting the execution of the sprite moving left or right until it's been scaled and rotated.

Get rotation:

Sprite.prototype.getRotation = function(){
    return this.mRotation;
};

Cheers for your time!

4

1 回答 1

2

您还没有发布this.getScale();的定义 但是,我猜这只是return this.mScale..?如果是这样,

while(this.getScale()<= this.mScale * 5)
    this.mScale += 0.5;

永远不会终止 - 条件永远不会变为假

于 2013-11-07T22:55:22.303 回答