Flash利用材质和遮照创建真实的小球动画(3) yspeed = 0;xspeed = 0;friction = 0.95;_root.attachMovie("ball", "ball", 1, {_x:250, _y:175});ball.texture.setMask(ball.ball_itself);ball.onEnterFrame = function() { if (Key.isDown(Key.LEFT)) { xspeed -= power; } if (Key.isDown(Key.RIGHT)) { xspeed += power; } if (Key.isDown(Key.UP)) { yspeed -= power; } if (Key.isDown(Key.DOWN)) { yspeed += power; } xspeed *= friction; yspeed *= friction; this._y += yspeed; this._x += xspeed; this.texture._y += yspeed; this.texture._x += xspeed; if (this.texture._x>158) { this.texture._x -= 188; } if (this.texture._x<-158) { this.texture._x += 188; } if (this.texture._y>158) { this.texture._y -= 188; } if (this.texture._y<-158) { this.texture._y += 188; }};
效果如下: