force_class.as

来自「这是《Flash MX编程与创意实现》的源代码」· AS 代码 · 共 87 行

AS
87
字号
/*
  Force Class v1.1
  Oct. 29, 2002
  (c) 2002 Robert Penner
  
  This is a custom object designed to provide an API
  for assigning physics forces to objects.
  Superclass of ElasticForce and others.
  
  Discussed in Chapter 11 of 
  Robert Penner's Programming Macromedia Flash MX
  
  http://www.robertpenner.com/profmx
  http://www.amazon.com/exec/obidos/ASIN/0072223561/robertpennerc-20
*/



_global.Force = function (x, y, life) {
    this.$value = new Vector (x, y);
    this.setLife (life);
};

var FP = Force.prototype;

////////// GETTER/SETTER METHODS

FP.setValue = function (x, y) {
    this.$value.reset (x, y);
};

FP.getValue = function () {
    return this.$value;
};

FP.setLife = function (life) {
    this.$life = (life == undefined) ? Infinity : life;
};

FP.getLife = function () {
    return this.$life;
};

FP.setParent = function (p) {
    this.$parent = p;
    this.parentPos = p.getPosition();
};

FP.getParent = function (p) {
    return this.$parent;
};


////////// PUBLIC METHODS

FP.live = function () {
    if (this.$life-- <= 0) {
        return false;
    } else {
        this.update();
        return true;
    }
};


////////// PRIVATE METHODS

// abstract method - meant to be overridden
FP.update = function () {
	// change force value here
};


/////////// GETTER/SETTER PROPERTIES

with (FP) {
    addProperty ("life", getLife, setLife);
    addProperty ("parent", getParent, setParent);
    addProperty ("value", getValue, null);
}


delete FP;

trace (">> Force class loaded");

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?