Pass width and height of canvas to constructor of class
<p>I need to pass the value of the canvas width and height to the cunstructor of the a Player class when I create that object in the constructor of the GameSurfaceView class below. The problem is that I can't get hold of any value of the canvas width and height at that time!? The only way, so far for me, is that I can get the width and height of the canvas inside the Run() method, but then it's to late because the object i already cretated.</p>

<p>I came up with and idea to pass a reference of the GameSurfaceView to a second constructor of the Player class, so I could pass and get the value that way from the canvas, but I guess, there will be no value at that moment either, when the object is created!</p>

<p>Please, ask if my question is unclear. Below is the main part of the code I'm using. I'm also using a MainActivity class to create an object of the class below. Help and suggestions are preciated! Thanks!</p>

<pre><code>public class GameSurfaceView extends SurfaceView implements Runnable {
SurfaceHolder surfaceHolder;
Canvas canvas;
int screenWidth, screenHeight;

// Constructor
public GameSurfaceView(Context context) {
super(context);
surfaceHolder = getHolder();

// Create player sprite object
player = new Player(texturePlayer, xPlayer, yPlayer);       
}

// Create player sprite object alternative 2
player = new Player(this, texturePlayer, xPlayer, yPlayer);     
}

@Override
public void run() {

canvas = surfaceHolder.lockCanvas();

screenWidth = canvas.getWidth();
screenHeight = canvas.getHeight();

// Do the drawing to screen here
surfaceHolder.unlockCanvasAndPost(canvas);  
}
}
</code></pre>
