Position

Position is a point in space.

1D Position

The most basic kind of position is a 1D position. Chances are you'll only be using the concept of a 1D position while programming. 1D position is used for such things as a file pointer which points to a position in the file. Memory locations in the 6502 processor could be said to be indexed using a type of 1D position system.

2D Position

If the game space is 2D, then the object's position is kept track of by two measurements, x and y. What x and y are measured against is different depending on if the game takes place only on one screen or takes place in a "world" and is seen through a viewport. In both of these cases, three things remain constant :

  • x is always a horizontal measurement
  • y is always a vertical measurement
  • Pixel zero is always the top/left corner of something.

x is Always Horizontal

x is a horizontal measurement. If you increase the x position of a game object, you will move it right. If you decrease the x position, you will move it left.

y is Always Vertical

y is a vertical measurement. If you increase the y position of a game object, you will move it down. If you decrease the y position, you will move it up.

Together, x and y allow you to move a game object anywhere in 2d game space.

Pixel zero is always the top/left corner of something

Pixel zero is always the top/left corner of something.1 This is because pixel zero is the pixel where x = 0 and y = 0. In single screen games, pixel zero is at the top left corner of the screen. In scrolling games that take place on a larger playfield, pixel zero is at the top/left corner of the playfield (level, or "world".)

Therefore, x and y are always measurements from pixel zero.

SetFPS 60
Do
    Cls 0    
        ; draw a dot at 100 x, 200 y
        Dot 100, 200
    Sync
Loop

Positional Offsets

An offset is a measurement of "distance" from a given position. Because x and y are both measurements from pixel zero, they are positional offsets. A positional offset is added to the "root location" to attain its real location. In the case of x and y are both 100, the location of the game object would be 100x, 100y . (Because 100 + 0 = 100).

But let's say that the player controls a spaceship in your game and you want a (friendly) floating gun to be exactly 10 pixels to the right of the spaceship. You can achieve this by a positional offset that uses the x and y of the spaceship as the root position. For ten pixels to the right of the spaceship, the offset would be x = 10, y = 0.

Remember, this is the positional offset from the spaceship, not pixel zero. If you tried to display the gun at 10x, 0y, you would be displaying it at 10x, 0y from pixel zero. To get it's actual location in game space, you need to add it's root location to the positional offset. The formula is :

positionX = spaceshipX + gunOffsetX
positionY = spaceshipY + gunOffsetY
SetFPS 60
PositionX = 100
PositionY = 100

Do
    Cls 0    
        Circle PositionX, PositionY, 3, True
        ; draw a dot offset from the circle
        Dot PositionX + 10, PositionY
    Sync
Loop

Random Position

SetFPS 60
PositionX = RndRange(1, GetScreenWidth())
PositionY = RndRange(1, GetScreenHeight())

Do
    Cls 0    
        Circle PositionX, PositionY, 3, True
    Sync
Loop

Related Pages

Backlinks

These pages link back to this page. You may find them helpful.

Links

To Do

  • random location
  • setting the position
  • finding the x and y position of an instance
  • destroy at position with mouse
  • uses of previous position last loopin
page_revision: 21, last_edited: 1244442087|%e %b %Y, %H:%M %Z (%O ago)