PDA

View Full Version : SetOriginX


Paul Fielder
10-16-2006, 08:27 PM
How does SetOriginX and OriginX work?
do they work on the screen?

I have been using the game API drawn a rectangle on the screen then attempted to move it with SetOriginX but nothing moves, a simple example would be advantagious.

PointOfLight
10-16-2006, 10:37 PM
I've uploaded a quick example. Sorry about the messiness of the code, but this is kind of my "test bed" for GameAPI functions. The important thing to see out of this is to run the program from a PC and press the left shift key. If you search for "left shift" in the code, you will see that the SetOriginX and SetOriginY are assigned random values each time you press shift. The plane moves around the screen, but the rectangle does not. I guess what I mean to show by this is that sprites are affected by the SetOrigin commands, but regular drawing objects are always relative to the upper left corner of the screen.

Here's the code: http://www.csdatasol.net/Downloads/Strategy_Game.zip.

[Edit]

Paul, I kind of blew the example I sent. You'll see that the rectangle now (at least somewhat) follows the screen movement. To get it back to the original example, set x$ and y$ to 0 before calling the G_DRAWRECT function.

kornalius
10-16-2006, 11:45 PM
Yep, screen functions are not relative to the origin. The easiest solution is to get the screen origins and add them to the positions of the rectangle.

Example:

SetOriginX(10);
SetOriginY(-20);

Rectangle(20 + OriginX, 20 + OriginY, 100 + OriginX, 100 + OriginY);

This will draw a rectangle at 20,20,100,100 that will be relative to the screen location.

kornalius
10-16-2006, 11:46 PM
In the GameAPI I could add some relative drawing functions if need be like:

RelRectangle
RelLineTo
RelSetPixel
etc...

Let me know.

PointOfLight
10-17-2006, 01:56 AM
If we want to use SetOriginX / SetOriginY, I think it's okay to have to adjust the drawing funcitons manually. While having a variety of functions is nice, too many functions are hard to keep track of.