GDP Functions


Position

Rotation

Scale

Collision

Appearance

Timers

Animation

Attributes

Miscellaneous

Position

.x() .y() and .z()

The functions .x(), .y(), and .z() will seperate a position into its components. These functions can also change the position of an object. Each function can take in an integer as a parameter, which will become the object's new position on its respective axis. Of note is that within the GDP, and in most development applications, the x and y axis are set up differently than one may originally think. The origin lies on the top left of the screen, and while x does increase rightward, y increases downward. The z axis refers to the layer an item is on. In other words, it is used to manage whether something is displayed in front of, or behind something.

xComp = position.x();    
//sets 'xComp' to the x value of 'position' using the .x() function
object.y(10);
//moves the 'object' to the y coordinate of 10, using the .y() function

See Further:

  1. Coordinate Collector
  2. XY Explanation

getPointerPos()

The function .getPointerPos() will return the mouse cursor's position. This position contains both x and y components. Further, this position can be stored into a variable, and separated into these components. The function takes no parameters.

var pos = getPointerPos();    
//calls the getPointerPos() function, and stores the returned position into the
//'pos' variable
xComp = pos.x();
yComp = pos.y();
//stores the x and y components of the 'pos' variable into 'xComp' and 'yComp' 
//This is done through .x() and .y() functions

See Further:

  1. Coordinate Collector
  2. Star Spinner

moveX() and moveY()

The functions moveX() and moveY() can be used to move an object along an axis. The function can take in two parameters, the first being the object, the second being the speed. The speed can be negative or positive, depending on the desired direction. If a speed parameter is not given, then either .speedX() or .speedY() will be called as a default speed for the object.

moveX(object,10);    
//moves 'object' with a speed of 10 along the x axis
moveY(object);
//moves 'object' with a speed of speedY() along the y axis

See Further:

  1. Side Wall Bounce
  2. Rain Catcher Part 1

.moveForward()

The function .moveForward() will move an object in the direction it is facing. Of note is that this function only works if the object is pointing in one of the eight main cardinal directions. The function takes in one parameter, a speed.

object.moveForward(10);    
//moves the 'object' forward with a speed of 10

See Further:

  1. Rain Catcher Part 6
  2. Color Picker

.moveForwardByRotation()

The function .moveForwardByRotation() will move an object in the direction it is facing. Unlike .moveForward(), this function moves the object in any direction that it is facing. The function takes in one parameter, a speed.

object.moveForwardByRotation(10);    
//moves the 'object' forward with a speed of 10
//'object' moves forward in the precise direction it is facing

See Further:

  1. Rain Catcher Part 6
  2. Color Picker

.moveTo()

The function .moveTo will move an object to a given position or object. The function can take two parameters, in the form of an x and y coordinate, or one parameter, the destination object.

object.moveTo(25,50);    
//moves the 'object' to the coordinate (25,50)
object.moveTo(object2);
//moves the 'object' to 'object2'

See Further:

  1. Ninja Snacks
  2. Shuriken Toss Part 1

.speedX() and .speedY()

The functions .speedX() and .speedY() contain an object's default speed value. Other functions, such as moveX() and moveY(), will use the speed contained within the corresponding speed function, if no parameter is passed through. speedX() and speedY() take in a single parameter as a speed.

object.speedX(10);
//sets the x speed of 'object' to 10

See Further:

  1. Side Wall Bounce
  2. Laser Beam Pointer

.findDistance()

The function .findDistance() will return the distance between two objects. The function takes just one parameter, the object which the distance to is being found.

var dis = object.findDistance(object2);    
//sets variable 'dis' to the distance between 'object' and 'object2'

See Further:

  1. Measurements
  2. Ninja Puzzle