DisplayObject

DisplayObject is the base class for all display objects in Next2D Player.

Properties

Read-only Properties

PropertyTypeDescription
instanceIdnumberUnique instance ID of DisplayObject
isSpritebooleanReturns whether Sprite functions are possessed
isInteractivebooleanReturns whether InteractiveObject functions are possessed
isContainerEnabledbooleanReturns whether the display object has container functionality
isTimelineEnabledbooleanReturns whether the display object has MovieClip functionality
isShapebooleanReturns whether the display object has Shape functionality
isVideobooleanReturns whether the display object has Video functionality
isTextbooleanReturns whether the display object has Text functionality
concatenatedMatrixMatrixCombined transformation matrix up to root level
dropTargetDisplayObject | nullDisplay object over which the sprite is being dragged or dropped
loaderInfoLoaderInfo | nullLoading information for the file to which this display object belongs
mouseXnumberX coordinate of the mouse relative to the DisplayObject’s reference point (pixels)
mouseYnumberY coordinate of the mouse relative to the DisplayObject’s reference point (pixels)
rootMovieClip | Sprite | nullThe root DisplayObjectContainer of the DisplayObject

Read-write Properties

PropertyTypeDescription
namestringName. Used by getChildByName() (default: "")
startFramenumberStart frame (default: 1)
endFramenumberEnd frame (default: 0)
isMaskbooleanIndicates whether the DisplayObject is set as a mask (default: false)
parentSprite | MovieClip | nullThe DisplayObjectContainer parent of this DisplayObject
alphanumberAlpha transparency value (0.0-1.0, default: 1.0)
blendModestringBlend mode to use (default: BlendMode.NORMAL)
filtersArray | nullArray of filter objects associated with the display object
heightnumberHeight of the display object (in pixels)
widthnumberWidth of the display object (in pixels)
colorTransformColorTransformColorTransform of the display object
matrixMatrixMatrix of the display object
rotationnumberRotation angle of the DisplayObject instance (in degrees)
scale9GridRectangle | nullCurrently active scaling grid
scaleXnumberHorizontal scale value of the object applied from the reference point
scaleYnumberVertical scale value of the object applied from the reference point
visiblebooleanWhether the display object is visible (default: true)
xnumberX coordinate relative to the local coordinates of the parent DisplayObjectContainer
ynumberY coordinate relative to the local coordinates of the parent DisplayObjectContainer

Methods

MethodReturn TypeDescription
getBounds(targetDisplayObject)RectangleReturns a rectangle that defines the area of the display object relative to the coordinate system of the specified DisplayObject
globalToLocal(point)PointConverts the point object from Stage (global) coordinates to the display object’s (local) coordinates
localToGlobal(point)PointConverts the point object from the display object’s (local) coordinates to Stage (global) coordinates
hitTestObject(targetDisplayObject)booleanEvaluates a DisplayObject’s drawing range to see if it overlaps or intersects
hitTestPoint(x, y, shapeFlag)booleanEvaluates the display object to see if it overlaps or intersects with the point specified by x and y parameters
getLocalVariable(key)anyGet a value from the local variable space of the class
setLocalVariable(key, value)voidStore values in the local variable space of the class
hasLocalVariable(key)booleanDetermines if there is a value in the local variable space of the class
deleteLocalVariable(key)voidRemove values from the local variable space of the class
getGlobalVariable(key)anyGet a value from the global variable space
setGlobalVariable(key, value)voidSave values to global variable space
hasGlobalVariable(key)booleanDetermines if there is a value in the global variable space
deleteGlobalVariable(key)voidRemove values from global variable space
clearGlobalVariable()voidClear all values in the global variable space
remove()voidRemoves the parent-child relationship

Blend Modes

ConstantDescription
BlendMode.NORMALNormal display
BlendMode.ADDAdditive
BlendMode.MULTIPLYMultiply
BlendMode.SCREENScreen
BlendMode.DARKENDarken
BlendMode.LIGHTENLighten
BlendMode.DIFFERENCEDifference
BlendMode.OVERLAYOverlay
BlendMode.HARDLIGHTHard light
BlendMode.INVERTInvert
BlendMode.ALPHAAlpha
BlendMode.ERASEErase

Usage Example

const { Sprite } = next2d.display;
const { BlurFilter } = next2d.filters;

const sprite = new Sprite();

// Position and size
sprite.x = 100;
sprite.y = 200;
sprite.scaleX = 1.5;
sprite.scaleY = 1.5;
sprite.rotation = 30;

// Display control
sprite.alpha = 0.8;
sprite.visible = true;
sprite.blendMode = "add";

// Filters
sprite.filters = [
    new BlurFilter(4, 4)
];

// Add to stage
stage.addChild(sprite);

Coordinate Transformation Example

const { Point } = next2d.geom;

// Convert global coordinates to local coordinates
const globalPoint = new Point(100, 100);
const localPoint = displayObject.globalToLocal(globalPoint);

// Convert local coordinates to global coordinates
const localPos = new Point(0, 0);
const globalPos = displayObject.localToGlobal(localPos);

Collision Detection Example

// Detection with bounding box
const hit1 = displayObject.hitTestPoint(100, 100, false);

// Detection with actual shape
const hit2 = displayObject.hitTestPoint(100, 100, true);

// Collision detection with another DisplayObject
if (obj1.hitTestObject(obj2)) {
    console.log("Collision detected");
}

Variable Operations Example

// Local variable operations
displayObject.setLocalVariable("score", 100);
const score = displayObject.getLocalVariable("score");
if (displayObject.hasLocalVariable("score")) {
    displayObject.deleteLocalVariable("score");
}

// Global variable operations
displayObject.setGlobalVariable("gameState", "playing");
const state = displayObject.getGlobalVariable("gameState");
displayObject.clearGlobalVariable(); // Clear all