CodePlexProject Hosting for Open Source Software

Points represent single pixels on the screen as x/y co-ordinates. The top-left pixel of your browser window is at (0,0). A pixel immediatly below it is at (0,1).

Like most things in the LDK engine, points are represented by objects. The point object is refreshingly simple. It holds only 2 variables, x and y. There are no methods associated with the point object. To create a custom point, use the following constructer:

myPoint=new point(x,y);

Where x and y are the co-ordinates you wish to store. For example, if you wanted myPoint to be the top-left of the screen, you would use new point(0,0).

The rectangle object, rect, is a little more complicated. There are only 4 variables but a whole host of methods. Luckily most of them are very similar. A rect can be represented by 2 points, with 2 right-angled lines drawn between them. Basically these two points are called x1,y1 and x2,y2. These are the 4 variables required to make a rect. Therefore the constructor is:

myRectangle=new rect(x1,y1,x2,y2);

A 10X10 rect at the top-left of the screen would be represented by new point(0,0,10,10). Note that the second two variables are NOT the size of the rect - they are a second set of co-ordinates.

The functions getTop, getBottom, getLeft and getRight return the topmost, bottommost, leftmost and rightmost points on a rectangle respectivly. getWidth and getHeight return the width and height. If you multiply these two together you'll get the area of the rectangle. The function getCentre returns the point at the centre of the rectangle. Finally, the function translate(xV,yV) takes the X and Y parts of a vector as inputs and moves the rectangle by that vector. It has no return value.

After you have created a scene, co-ordinates are no longer relative to the page but to that scene. For instance, a co-ordinate that used to be at the top-left of the page will now be at the top-left of the scene. If you had a co-ordinate at the centre of the page, that will not necessarily be at the centre of the scene. This is because if that co-ordinate was at, say (400,300), then it would be located 400 pixels across and 300 pixels along from the top-left. This might not be the centre of your scene!

Last edited Dec 13, 2009 at 10:05 PM by larztheloser, version 1