Skip to main content
Inspiring
November 29, 2010
Question

Question about position.x

  • November 29, 2010
  • 1 reply
  • 313 views

I run a demo code,it extends Sprite,like follows:


public class Vehicle extends Sprite{
   protected var _position:Vector2D;
   public function Vehicle(){
     _position = new Vector2D();
    draw();
   }
   protected function draw():void{
     graphics.clear();
     graphics.lineStyle(0);
     graphics.moveTo(10, 0);
     graphics.lineTo(-10, 5);
     graphics.lineTo(-10, -5);
     graphics.lineTo(10, 0);
   }
   public function update():void{
      _position = _position.add(_velocity);
     x = position.x;
     y = position.y;
   }
}

I don't understand following code,because I only define _position and don't define position variable,why I can use position.x?
     x = position.x;
     y = position.y;

Any idea will be appreciated!

This topic has been closed for replies.

1 reply

Lee_Burrows
Participating Frequently
November 29, 2010

just make sure all references to _position / position are the same (ie: either name them all as _position, or all as position) and the code should work - as long as you have also defined _velocity