I can not get a parameter of a Function void

0

I would like to get Coorxcen, I gave it return Coorxcen, but I get an error that it's a void function, how could Coorxcen get?

public LadriMoviEntity(World world, Texture pared, float CoorXcen, float CoorYcen){
    this.world= world;
    this.texture= pared;
    float mediBase=1.5f;// la mediBase es la mitad del objeto
    float mediAltu=0.3f;
    BodyDef def= new BodyDef();
    def.position.set(CoorXcen,CoorYcen);// posicion tomando en cuenta el punto medio
    def.type=BodyDef.BodyType.KinematicBody;// es estatico el objeto
    body = world.createBody(def);

    PolygonShape rectangulo= new PolygonShape();
    rectangulo.setAsBox(mediBase, mediAltu); // tamaño de espiritu , esto se multiplica por 2
    fixture= body.createFixture(rectangulo, 1);
    fixture.setUserData("piso");
    rectangulo.dispose();

    setSize(3 * PIXELS_IN_METER, 0.6f * PIXELS_IN_METER);// tamaño real

    return CoorXcen;
}
    
asked by Hans Leo Quiroz Marroquin 23.05.2016 в 03:13
source

1 answer

4

Assuming that LadriMoviEntity is not a class constructor you can specify the type of return in this case float, you can see this example:

public float LadriMoviEntity(World world, Texture pared, float CoorXcen, float CoorYcen){

    ..//
    return CoorXcen;
}
  

Yes, that uses ... The return Coorxcen, but it marks me as if it were   a void .... And I would like to extract that parameter

I do not understand the comment very well but I will try to clarify something more the answer:

If you want to get some type of return you have to indicate the one you want, in this case it is float so we add:

public float   <--- añades float que es el tipo de retorno

and also add the return:

return CoorXcen; <--- añades return

you could use it in this way for example, somewhere in your code:

..//
float coor_x_cen = tuObjeto.LadriMoviEntity(...); //si usas un objeto.
..//

On the other hand I do not really know what you want to do with Box2d, nor did you tell me if LadriMoviEntity is the class constructor, but you say you want Coorxcen but you have it when you call LadriMoviEntity since you pass it as a parameter and it does not change at any time so, as you spend it you can use it from where you call LadriMoviEntity without having to use the return because it is not modified.

But if LadriMoviEntity is a class constructor you could create some get and set to check that value for example something like this:

float coorXcen;

public LadriMoviEntity(World world, Texture pared, float CoorXcen, float CoorYcen){

    ..//
    this.coorXcen = CoorXcen;        
}

public float getCoorXcen(){
   return this.coorXcen;
}

in another part of your code where you have access to the object and want to use it:

..//
float coor_x_cen = tuObjeto.getCoorXcen(); //si usas un objeto.
..//
    
answered by 23.05.2016 в 03:28