- Home /
 
It is not possible to invoke an expression of type 'SpriteManager[]'.
I'm trying to code a 2d platformer. I keep getting this error, when I try to change the [] to () it tells me unexpected token. I try with semicolen, and without. I'm not sure what the issue is, so here is the script.
 public var f_speed : float = 5.0;
 public var loopSprites : SpriteManager[];
 private var in_direction : int;
 
 
 function Start () : void {
     in_direction = 1;
 //initialization Sprite Manager
     for (var i : int = 0; i<loopSprites.length; i++) {
         loopSprites[i].init();
 }
 //Update main camera to the character position
 Camera.main.transform.position = new Vector3 (transform.position.x, transform.position.y, Camera.main.transform.position.z);
 }
 
 
 
 public function Update () : void {
     if (Input.GetButton("Horizontal")) {
         //walking
         in_direction = Input.GetAxis("Horizontal") < 0 ? -1: 1;
         rigidbody.velocity = new Vector3((in_direction*f_speed),
     rigidbody.velocity.y, 0);
         //reset stay animation frame back to the first frame
         loopSprites(0).resetFrame();
         //update walking animation while the character is walking
         loopSprites(1).updateAnimation(in_direction, renderer.material);
         } else {
         //stay
         //reset walking animation frame back to the first frame
         loopSprites(1).resetFrame();
         //update stay animation while the character is not walking
         loopSprites(0).updateAnimation(in_direction, renderer.material);
         }
     }
     
 public function LateUpdate() : void {
 //update main camera
     Camera.main.transform.position = new Vector3(transform.position.x, transform.position.y, Camera.main.transform.position.z);
 }    
     class SpriteManager {
         public var spriteTexture : Texture2D; //set texture use for a loop animation such as walking, stay, etc.
         public var in_framePerSec : int; //get frame per sec to calculate time
         public var in_gridx : int; //get max number of horizontal images
         public var in_gridy : int; //get max number oif vertical images
         private var f_timePercent : float;
         private var f_nextTime : float; //update time byte using frame persecond
         private var f_gridx : float;
         private var f_gridy : float;        
         private var in_curFrame : int;
         
         public function init () : void {
             f_timePercent = 1.0/in_framePerSec;
             f_nextTime = f_timePercent; //update time by using frame
             f_gridx = 1.0/in_gridx;
             f_gridy = 1.0/in_gridy;
             in_curFrame = 1;
         }
         
         public function updateAnimation (_direction : int, _material : Material) : void {
         //update material
         _material.mainTexture = spriteTexture;
         //update frame by time
         if (Time.time>f_nextTime) {
             f_nextTime = Time.time + f_timePercent;
             in_curFrame++;
             if (in_curFrame>in_framePerSec) {
                 in_curFrame = 1;
             }
         }
         _material.mainTextureScale - new Vector2 (_direction * f_gridx, f_gridx);
         var in_col : int = 0;
         if (in_gridy> 1) {
             //if there is more than one grid on the y-axis update the texture
         in_col= Mathf.Ceil(in_curFrame/in_gridx);
         }
             if(_direction == 1) { //right
             _material.mainTextureOffset = new Vector2(((in_curFrame%in_gridx)) * f_gridx, in_col*f_gridy);
                 }
             }
             
             public function resetFrame () :void {
                 in_curFrame = 1;
                 }
             }
         
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Bunny83 · Feb 23, 2013 at 01:09 AM
This is totally wrong:
 loopSprites(0).resetFrame();
 
               The normal brackets () are used to invoke a method but loopSprites is an array. You have to use the index brackets []:
 loopSprites[0].resetFrame();
 
              Your answer