• ig.Entity

ig.

EntityExtended

new EntityExtended()

Enhanced entity that is the core of Impact++.
- entity animations can be added dynamically and handle inheritance far more flexibly with ig.EntityExtended#animSettings
- entities update is now opt-in using ig.EntityExtended#performance and ig.EntityExtended#frozen Tip: your entities should be a descendant of this to utilize Impact++ properly.

Author:
  • Collin Hover - collinhover.com
Source:

activateCallback :function

Function called on activate.
- do not use this for predefined entity classes, override activate instead

Source:

activateContext :Object

Context to execute activate callback function in.
- do not use this for predefined entity classes, override activate instead

Source:

activated :Boolean

Whether entity's activate has been triggered,
- set to true to have an entity activate on init

Default Value:
  • false
Source:

<readonly> added :Boolean

Whether entity has been added to game world.

Default Value:
  • false
Source:

alpha :Number

Entity alpha. IMPORTANT: applied to animations automatically on draw.

Default Value:
  • 1
Source:

alwaysToggleActivate :Boolean

Whether entity's activate should override deactivate.

Default Value:
  • false
Source:

angle :Number

Angle of rotation in radians.

Default Value:
  • 0
Source:

animationType :Number

Type of animation from ig.EntityExtended#animationTypes.
- used when creating animations from ig.EntityExtended#animSettings

Default Value:
  • 0
Source:

animationTypes :Array

Types of animation.
- used when creating animations from ig.EntityExtended#animSettings

Default Value:
  • null
Source:

animFrameTime :Number

Default frame time in seconds for animations when not defined in ig.EntityExtended#animSettings.
- used when creating animations from ig.EntityExtended#animSettings

Default Value:
  • 1
Source:

animInit :String

Name of animation to play when entity is ready and after spawned.

Source:

animSequenceCount :Number

Default sequence frame count for animations when not defined in ig.EntityExtended#animSettings.
- used when creating animations from ig.EntityExtended#animSettings

Default Value:
  • 1
Source:

animSettings :Object

Animation settings used to automatically create and add animations on initialization.
- use this instead of hardcoding animations into ig.EntityExtended#init for better inheritance!

Default Value:
  • null
Source:
Example
// previous method of adding animations
// this would likely be hardcoded into the init method
this.addAnim( 'idleX', 0.25, [0,1] );
// new (and improved?) method of adding animations
// which would be defined in the class properties
// properties match the parameters passed to ig.AnimationExtended#init
animSettings: {
		 // note here the directional animation name
	// animations in Impact++ are directional and based on flip and facing
	// so if an entity can flip X
	// you should have animations for X
	// i.e. "idleX"
	// but if an entity can flip X and Y
	// you should have animations for both X and Y
	// i.e. "idleX" and "idleY"
	// if an entity cannot flip X and Y
	// you should have animations for Up, Down, Left, and Right
	// i.e. "idleUp", "idleDown", "idleLeft", "idleRight"
     idleX: {
         // sequence frames 0 and 1
         sequence: [0,1],
         // quarter second per frame
         frameTime: 0.25,
         // play only once
         once: true,
         // do not play immediately
         stop: true
         // play animation in reverse
         reverse: true
     }
}
// then to easily change the sequence in a descendant class
// while retaining the original properties
animSettings: {
     idleX: {
         sequence: [3,4,5,6]
     }
}

animSheetHeight :Number

Tile height of dynamic animation sheet. IMPORTANT: use this for dynamically / run-time created entity types, not classes.

Default Value:
  • 0
Source:

animSheetPath :String

Path to dynamic animation sheet.
- created on init
- automatically prepends shared base media directory from ig.CONFIG.PATH_TO_MEDIA IMPORTANT: use this for dynamically / run-time created entity types, not classes.

Source:

animSheetWidth :Number

Tile width of dynamic animation sheet. IMPORTANT: use this for dynamically / run-time created entity types, not classes.

Default Value:
  • 0
Source:

animTileOffset :Number

Default tile offset, within animation sheet, to start animation when not defined in ig.EntityExtended#animSettings.
- used when creating animations from ig.EntityExtended#animSettings

Default Value:
  • 0
Source:

bounciness :Number

How bouncy entity is in collisions, between 0 and 1.

Source:
See:

canDieInstantly :Boolean

Whether entity can skip death animation if it dies while off screen.

Default Value:
  • true
Source:

canFlipX :Boolean

Whether entity can flip animations vertically and set facing on x.

Source:

canFlipY :Boolean

Whether entity can flip animations vertically and set facing on y.

Source:

<readonly> changed :Boolean

Whether entity has changed since last update.

Default Value:
  • false
Source:

checkAgainst :Bitflag|Number

Entities to check against, expanded for more flexibility and specificity. IMPORTANT: for an entity to avoid being ignored in checks, it must either collide, checkAgainst, or have a type!

Default Value:
  • none
Source:
See:

<readonly> checking :Boolean

Whether entity is checking against another entity matching ig.Entity#checkAgainst flag.

Default Value:
  • false
Source:

climbable :Boolean

Whether entity is climbable.

Default Value:
  • false
Source:

climbableStairs :Boolean

Whether entity is climbable as stairs. IMPORTANT: has no effect unless ig.EntityExtended#climbable is true.

Default Value:
  • false
Source:

collides :Bitflag|Number

How entity should collide with other entities.
- this does not affect whether entity collides with collision map, only how it collides with other entities IMPORTANT: for an entity to avoid being ignored in checks, it must either collide, checkAgainst, or have a type!

Default Value:
  • never
Source:
See:
  • ig.Entity

collidesChanges :Boolean

Whether an entity may change its ig.EntityExtended#collides property during gameplay. IMPORTANT: this forces an entity to be included in collision checks, even if it does not collide, checkAgainst, or have a type

Default Value:
  • false
Source:

collidingWithEntitiesBelow :Boolean

Whether entity is colliding with one or more entities below.

Default Value:
  • false
Source:

collidingWithMap :Boolean

Whether entity is colliding with a wall, floor, ceiling, etc in collision map.

Default Value:
  • false
Source:

<readonly> collisionMapResult :Object

Entity's result from colliding with ig.GameExtended#collisionMap.
- created on init

Source:

controllable :Boolean

Whether entity has control of itself and can move. IMPORTANT: uncontrollable entities update but do not move or change!

Default Value:
  • true
Source:

<readonly> currentAnim :ig.AnimationExtended

Currently displaying animation.
- defers to ig.EntityExtended#overridingAnim

Default Value:
  • null
Source:

deactivateCallback :function

Function called on deactivate.
- do not use this for predefined entity classes, override activate instead

Source:

deactivateContext :Object

Context to execute deactivate callback function in.
- do not use this for predefined entity classes, override activate instead

Source:

<readonly> dieing :Boolean

Whether entity is in the process of dieing.

Default Value:
  • false
Source:

<readonly> dieingSilently :Boolean

Whether entity is in the process of dieing without effects or animation.

Default Value:
  • false
Source:

diffuse :Number

How much light is blocked when ig.EntityExtended#opaque.

Source:

facing :Vector2|Object

Facing direction of entity based on velocity and look at.

Default Value:
  • right
Source:

fixed :Boolean

Whether is fixed in screen vs inside world space.
- this is particularly useful for UI elements IMPORTANT: fixed elements cannot have dynamic performance!

Default Value:
  • false
Source:

flip :Boolean

Whether entity is flipped. IMPORTANT: flip is now an object with x and y boolean values!

Source:

friction :Vector2|Object

Friction of entity

Source:
See:

frozen :Boolean

Whether entity should skip updating.

Default Value:
  • false
Source:

gravityFactor :Number

Percent of gravity to apply, between 0 and 1.

Source:
See:

grounded :Boolean

Whether entity is grounded.

Source:
See:

group :Bitflag|Number

Group of entities to avoid checking against and colliding with. Tip: as the group property is a bitflag, it can be any combination of groups!

Default Value:
  • none
Source:
See:

<readonly> hasGravity :Boolean

Whether entity has gravity.
- set automatically during update

Source:

health :Number

Health statistic.
- someone once asked me how I died, so I told them that my health reached 0

Source:

healthMax :Number

Max health statistic.

Source:

<readonly> hidden :Boolean

Whether entity is hidden and cannot be seen by other entities. Set via ig.EntityExtended#setHidden.

Default Value:
  • false
Source:

highPerformance :Boolean

Whether entity is high performance, i.e. skips a lot of checks and adds/removals to increase speed at the loss of flexibility and functionality. IMPORTANT: high performance entities don't check, don't collide, and are not interactive!

Default Value:
  • false
Source:

hollow :Boolean

Whether entity only casts shadows from edges when ig.EntityExtended#opaque.

Default Value:
  • true
Source:

ignoreSystemScale :Boolean

Whether entity elements should ignore system scale.

Default Value:
  • ig.CONFIG.ENTITY.IGNORE_SYSTEM_SCALE
Source:

<readonly> intersecting :Boolean

Whether entity is intersecting another entity.

Default Value:
  • false
Source:

invulnerable :Boolean

Whether entity blocks all incoming damage.

Default Value:
  • false
Source:

layerName :String

Layer to be added to upon instantiation.

Default Value:
  • entities
Source:

linkedTo :ig.EntityExtended

Another entity that this entity is linked to.

Default Value:
  • null
Source:

<readonly> managed :Boolean

Whether entity is currently being managed by ig.GameExtended#playerManager.

Default Value:
  • false
Source:

maxVel :Vector2|Object

Max velocity of entity

Source:
See:

minBounceVelocity :Number

Minimum velocity to bounce.

Source:
See:

<readonly> movedTo :Boolean

Whether entity has moved to currently moving to entity.

Default Value:
  • true
Source:

<readonly> moving :Boolean

Whether entity is moving.

Default Value:
  • false
Source:

<readonly> movingTo :ig.EntityExtended|Vector2|Object

Whether entity is moving to another entity.

Default Value:
  • null
Source:

<readonly> movingToOnce :Boolean

Whether entity should move to another entity and stop moving.

Default Value:
  • false
Source:

<readonly> movingToTweening :Boolean

Whether entity is tweening to another entity. IMPORTANT: this is automatically disabled with dynamic entities!

Default Value:
  • false
Source:

<readonly> movingToTweenPct :Number

Percent progress of tweening to another entity.

Source:

<readonly> movingX :Boolean

Whether entity is moving horizontally.

Default Value:
  • false
Source:

<readonly> movingY :Boolean

Whether entity is moving vertically.

Default Value:
  • false
Source:

needsRebuild :Boolean

Whether entity needs to be rebuilt on next refresh. IMPORTANT: it is usually a bad idea to set this to false initially!

Default Value:
  • true
Source:

needsVertices :Boolean

Whether to calculate vertices on change.

Source:
See:

offset :Vector2|Object

Offset of entity, reflected on both sides.

Source:
See:

onAdded :ig.Signal

Signal dispatched when entity added to game.
- created on init.

Source:

oneWay :Boolean

Whether entity is one way

Default Value:
  • false
Source:

oneWayFacing :Vector2

Direction from which entity will collide with another entity.

Default Value:
  • null
Source:
Example
// direction should be a 2d vector with a length of 1
// i.e. this is invalid
entity.oneWayFacing = { x: 0, y: 0 };
// while either of the following is okay
entity.oneWayFacing = { x: 1, y: 0 };
entity.oneWayFacing = ig.utilsvector2.vector( 1, 0 );
// to block from the left
entity.oneWayFacing = { x: -1, y: 0 };
// to block from the right
entity.oneWayFacing = { x: 1, y: 0 };
// to block from the top
entity.oneWayFacing = { x: 0, y: -1 };
// to block from the bottom
entity.oneWayFacing = { x: 0, y: 1 };

onMovedTo :ig.Signal

Signal dispatched when entity completes moving to another entity.
- created on init.

Source:

onRefreshed :ig.Signal

Signal dispatched when entity is refreshed.
- created on init.

Source:

onRemoved :ig.Signal

Signal dispatched when entity removed from game.
- created on init.

Source:

opaque :Boolean

Whether entity casts a shadow from lights.

Source:

opaqueFromVertices :Boolean

Whether opaque vertices should use vertices when present. IMPORTANT: when true, this overrides ig.EntityExtended#initOpaqueVertices, and ig.EntityExtended#getOpaqueVertices.

Source:
See:

opaqueOffset :Object

Size to offset from entity bounds for casting shadows when ig.EntityExtended#opaque. Tip: to set opaque offsets per animation, use ig.AnimationExtended#opaqueOffset

Source:
See:
Example
// by default, shadow casting uses
// entity's opaque offsets
entity.opaqueOffset = {
     left: 0,
     right: 0,
     top: 0,
     bottom: 0
};
// unless the entity's current animation
// has its own opaque offsets
entity.currentAnim.opaqueOffset = {
     left: 0,
     right: 0,
     top: 0,
     bottom: 0
};
// opaque offsets can also be done per tile
entity.currentAnim.opaqueOffset = {
     tiles: {
        1: {
             left: 0,
             right: 0,
             top: 0,
             bottom: 0
         },
         2: {...}
     }
};

opaqueVertices :Array

List of vertices in world space for shadow casting.
- recalculated when casting shadows by ig.EntityExtended#getOpaqueVertices

Source:

<readonly> overridingAnim :ig.AnimationExtended

Currently overriding animation.
- if present, this displays instead of ig.EntityExtended#currentAnim

Default Value:
  • null
Source:

<readonly> paused :Boolean

Whether entity is paused.

Default Value:
  • false
Source:

performance :String

How entity should perform during update.
- static will only update animation
- movable can move but does not collide with collision map
- dynamic does full update, including movement and collision map checks IMPORTANT: this directly correlates to the complexity of entity's update and whether it collides with collision map.

Default Value:
  • static
Source:

persistent :Boolean

Whether entity should remain across levels. Tip: an entity will only be moved from one level to another if an entity is found with a matching name! IMPORTANT: the game will keep the first of each uniquely named persistent entity it encounters and merge the editor position and settings of any others with the same name as it encounters them.

Default Value:
  • false
Source:

pos :Vector2|Object

Base position.

Source:

<readonly> posDraw :Vector2|Object

Drawn position.

Source:

rangeInteractableX :Number

Horizontal range at which this entity can be interacted with.
- a range of 0 is considered infinite
- abilities compare this to their own range and use the higher of the two IMPORTANT: only relevant if entity type includes ig.EntityExtended.TYPE.INTERACTIVE.

Default Value:
  • 0
Source:

rangeInteractableY :Number

Vertical range at which this entity can be interacted with.
- a range of 0 is considered infinite
- abilities compare this to their own range and use the higher of the two IMPORTANT: only relevant if entity type includes ig.EntityExtended.TYPE.INTERACTIVE.

Default Value:
  • 0
Source:

resetState :Object

Last recorded state taken during ig.EntityExtended#recordResetState.
- automatically updated first time entity added to game world
- reset state records only a limited set of properties
- this can be useful for checkpoints, respawning, etc

Source:

scale :Number

Scale that overrides system scale when ig.EntityExtended#ignoreSystemScale is true.

Default Value:
  • ig.CONFIG.ENTITY.SCALE
Source:

scaleMax :Number

Maximum value of ig.EntityExtended#scale.

Default Value:
  • ig.CONFIG.ENTITY.SCALE_MAX
Source:

scaleMin :Number

Minimum value of ig.EntityExtended#scale.

Default Value:
  • ig.CONFIG.ENTITY.SCALE_MIN
Source:

<readonly> scaleMod :Number

Modifier for when ig.EntityExtended#scale != ig.system.scale.

Default Value:
  • 1
Source:

scaleOfSystemScale :Number

Scale of system scale.

Default Value:
  • ig.CONFIG.ENTITY.SCALE_OF_SYSTEM_SCALE
Source:

size :Vector2|Object

Size of entity

Source:
See:

<readonly> sizeDraw :Vector2|Object

Drawn size of entity, including size, offsets, etc.

Source:

slope :Object

Whether entity is on a slope, and if so, slope properties.

Source:

slopeSpeedMod :Number

Speed multiplier on slopes

Source:
See:

slopeStanding :Vector2

Slope angle range that entity can stand on.

Source:
See:

slopeSticking :Boolean

Whether entity should stick to slopes instead of sliding down.

Source:
See:

standing :Boolean

Whether entity is standing.

Source:
See:

targetable :Boolean

Whether entity can be targeted by an intersection search. Tip: for interactive entities, set this to true and add the ig.EntityExtended.TYPE.INTERACTIVE flag to its type.

Default Value:
  • false
Source:

textured :Boolean

Whether animations should be automatically textured across entity when added to entity.
- textures can be animated, but be careful about adding high amounts of frames Tip: this is best applied to resizable entities.

Default Value:
  • false
Source:

<readonly> tweens :Object

All tweens affecting this entity that were initiated by ig.EntityExtended#tween.
- these tweens are automatically deleted when complete

Source:

type :Bitflag|Number

Entity type, expanded for more flexibility and specificity. IMPORTANT: for an entity to avoid being ignored in checks, it must either collide, checkAgainst, or have a type!

Default Value:
  • none
Source:
See:

vertices :Array

List of vertices based on bounds, relative to entity.
- not calculated by default for performance reasons
- to manually enable, use ig.EntityExtended#needsVertices

Source:

verticesWorld :Array

List of vertices based on bounds, relative to world space.
- not calculated by default for performance reasons
- to manually enable, use ig.EntityExtended#needsVertices

Source:

<readonly> visible :Boolean

Whether entity is visible in screen.

Default Value:
  • false
Source:

<readonly> wasChecking :Boolean

Whether entity was checking against another entity matching ig.Entity#checkAgainst flag.

Default Value:
  • false
Source:

<static> checkPair()

Expanded pair checking to handle groups and one-way.

Source:

<static> solveCollision()

Expanded collision solving to ensure stable entity bounds.

Source:

activate(entity)

Do some activated behavior.

Parameters:
Name Type Argument Description
entity Entity <optional>
causing activation.
Source:

addAnim(name, settings)

Adds an animation to an entity.
- uses ig.AnimationExtended instead of the original ig.Animation

Parameters:
Name Type Argument Description
name String name of animation
settings Object <optional>
settings based on animation properties
Source:
See:

addControl()

Adds control to entity. Tip: this allows entity to call ig.GameExtended#updateChanges during update cycle.

Source:

angleTo(from) → {Number}

Calculates angle from this entity to another entity or position.

Parameters:
Name Type Description
from ig.EntityExtended | Vector2 | Object entity or position to find angle to.
Source:
Returns:
{ Number } angle

animOverride(animName, settings)

Plays an animation and sets animation as override until complete to ensure that no other animations play.

Parameters:
Name Type Argument Description
animName String name of animation to play.
settings Object <optional>
settings object.
Source:
Example
// settings is a plain object
settings = {};
// use an animation from another entity
settings.entity = otherEntity;
// don't auto release override
settings.lock = true;
// loop overriding animation
// also does not auto release override
settings.loop = true;
// play animation in reverse
settings.reverse = true;
// call a function when override completes
settings.callback = function () {...};
// call the callback in a context
settings.context = callbackContext;

animRelease(name, silent)

Removes animation override, see ig.EntityExtended.animOverride.

Parameters:
Name Type Argument Default Description
name String <optional>
any specific name of overriding animation to release. If does not match will not release.
silent Boolean <optional>
false whether to suppress callback.
Source:

applyAntiGravity()

Applies velocity to counteract gravity.

Source:

applyAntiVelocity()

Zeroes out velocity.

Source:

applyAntiVelocityX()

Zeroes out horizontal velocity.

Source:

applyAntiVelocityY()

Zeroes out vertical velocity.

Source:

castShadow(light, context, point, minX, minY, radius)

Fill context with the shadow cast by this entity from a point within a light, constrained by the given bounds.

Parameters:
Name Type Description
light ig.EntityLight to cast shadows from
context CanvasRenderingContext2D The canvas context onto which the shadows will be cast.
point Object point that represents where the light is coming from.
minX Number left position of light
minY Number top position of light
radius Number radius of light
Source:

changePerformance() → {Boolean}

Makes changes based on this entity's performance level.

Source:
Returns:
{ Boolean } whether changed or not.

changePerformanceDynamic()

Called when performance changed to dynamic.

Source:

changePerformanceMovable()

Called when performance changed to movable.

Source:

changePerformanceStatic()

Called when performance changed to static.

Source:

check(entity)

Checks this entity against another entity that matches this entity's ig.EntityExtended#type.

Parameters:
Name Type Argument Description
entity ig.EntityExtended <optional>
other entity.
Source:
See:
  • ig.Entity.

cleanup()

Does cleanup on entity as it is added to deferred removal list.

Source:

cleanupCollision()

Cleans entity of previous collision properties just before new collision checks.

Source:

cleanupPersistent()

Does cleanup on persistent changes to game made by this entity, ex: UI elements.

Source:

collideWith(entity, dirX, dirY, nudge, vel, weak)

Collides with another entity along a specified axis.

Parameters:
Name Type Description
entity ig.EntityExtended entity colliding with.
dirX Number horizontal direction of colliding entity
dirY Number vertical direction of colliding entity
nudge Number nudge amount in direction
vel Number velocity in direction
weak Boolean weak colliding entity (i.e. only weak moves)
Source:

createAnim(name, settings)

Generates and adds an animation from ig.EntityExtended#animSettings. If no settings passed, creates default idle animation.

Parameters:
Name Type Argument Description
name Object <optional>
name of animation.
settings Object <optional>
settings for animation.
Source:
See:

deactivate(entity)

Do some deactivated behavior.

Parameters:
Name Type Argument Description
entity Entity <optional>
causing deactivation.
Source:

death(animNameDeath)

Shows death animation, automatically called when entity is first killed. Tip: it is not recommended to call this method, but it is fine to override it!

Parameters:
Name Type Argument Default Description
animNameDeath String <optional>
"death" + direction name of death animation to play
Source:

die()

Automatically called after entity finished being killed. IMPORTANT: for full animated death, use ig.EntityExtended#kill instead.

Source:

distanceEdgeTo(from) → {Number}

Calculates distance from edge of this entity to edge of another entity or position.

Parameters:
Name Type Description
from ig.EntityExtended | Vector2 | Object entity or position to find distance to.
Source:
Returns:
{ Number } distance

distanceSquaredEdgeTo(from) → {Number}

Calculates distance squared from edge of this entity to edge of another entity or position.
- this is faster than distanceEdgeTo as it avoids sqrt, but the distance is squared

Parameters:
Name Type Description
from ig.EntityExtended | Vector2 | Object entity or position to find distance to.
Source:
Returns:
{ Number } distance

distanceSquaredTo(from) → {Number}

Calculates distance squared from center of this entity (in world space) to center of another entity or position (in world space).
- this is faster than distanceTo as it avoids sqrt, but the distance is squared

Parameters:
Name Type Description
from ig.EntityExtended | Vector2 | Object entity or position to find distance to.
Source:
Returns:
{ Number } distance squared

distanceTo(from) → {Number}

Calculates distance from center of this entity to center of another entity or position.

Parameters:
Name Type Description
from ig.EntityExtended | Vector2 | Object entity or position to find distance to.
Source:
Returns:
{ Number } distance

draw()

Draws entity.

Source:

fadeIn(settings) → {Tween}

Convenience function for tween fade to max alpha.

Parameters:
Name Type Argument Description
settings Object <optional>
settings for tween.
Source:
Returns:
{ Tween } tween object.

fadeOut(settings) → {Tween}

Convenience function for tween fade out.

Parameters:
Name Type Argument Description
settings Object <optional>
settings for tween.
Source:
Returns:
{ Tween } tween object.

fadeTo(alpha, settings) → {Tween}

Simple fade to specified alpha. Only tweens if not already at alpha, but onUpdate and onComplete methods are guaranteed to call at least once.

Parameters:
Name Type Argument Description
alpha Number alpha value between 0 and 1.
settings Object <optional>
settings for tween.
Source:
Returns:
{ Tween } tween object if tweening to alpha.

fadeToDeath(settings) → {Tween}

Convenience function for tween fade out and then kill.

Parameters:
Name Type Argument Description
settings Object <optional>
settings for tween.
Source:
Returns:
{ Tween } tween object.

getCenterX() → {Number}

Calculates entity's center x position.

Source:
Returns:
{ Number } horizontal center.

getCenterY() → {Number}

Calculates entity's center x position.

Source:
Returns:
{ Number } vertical center.

getDirectionalAnimName(animName) → {String}

Gets the directional name of an animation based on whether entity can flip and current facing. IMPORTANT: this method is biased towards facing vertical.

Parameters:
Name Type Description
animName String base animation name
Source:
Returns:
{ String } directional animation name
Example
// if we begin with an animation named "move"
// and this entity can flip horizontally
var animName = entity.getAnimName( "move" );
// the result will be "moveX"
// while if the entity cannot flip horizontally
// but it is facing to the left
entity.facing.x = -1;
// the result will be "moveLeft"

getIsCollidingWithOneWay(entityOneWay) → {Boolean}

Approximate check of whether this entity is colliding with the one way blocking direction of another other entity.
- checks for whether the touching edges are within a certain range based on ig.CONFIG#PRECISION_PCT_ONE_SIDED IMPORTANT: the non one way entity does this check to allow it to choose whether to ignore one way block.

Parameters:
Name Type Description
entityOneWay ig.EntityExtended one way entity to check against.
Source:
Returns:
{ Boolean } true if this entity is coming from other entity's one way blocking direction.

getIsMovingSelf() → {Boolean}

Calculates if entity is handling its own movement, i.e. dynamic, moving to, etc.

Source:
Returns:
{ Boolean } if is handling own movement.

getIsVisible() → {Boolean}

Calculates if entity is visible in screen.
- instead of calling this, use ig.EntityExtended#visible

Source:
Returns:
{ Boolean } if is in screen.
Example
// this is a bad idea
var visible = entity.getIsVisible();
// this is a good idea
var visible = entity.visible;

getLayer() → {ig.Layer}

Gets entity layer based on ig.EntityExtended#layerName.

Source:
Returns:
{ ig.Layer } layer this entity is on.

getNewVelocity(vel, accel, friction, max)

Calculates new velocity on a single axis for entity, and fixes bug of friction not limiting velocity.

Parameters:
Name Type Description
vel Number velocity
accel Number acceleration
friction Number friction
max Number max velocity
Source:

getOpaqueVertices() → {Array}

Calculates vertices for shadow casting just before first shadow is cast since changed.

Source:
Returns:
{ Array } vertices for shadow casting

getPosDrawX() → {Number}

Calculates entity's draw x position, offset included.

Source:
Returns:
{ Number } draw x position.

getPosDrawY() → {Number}

Calculates entity's draw y position, offset included.

Source:
Returns:
{ Number } draw y position.

getSizeDrawX() → {Number}

Calculates horizontal size, offset included.

Source:
Returns:
{ Number } total horizontal size.

getSizeDrawY() → {Number}

Calculates horizontal size, offset included.

Source:
Returns:
{ Number } total vertical size.

getVertices() → {Array}

Calculates vertices based on entity's size.
- vertices are relative to entity, not world space, and are not scaled to window
- instead of calling this, use ig.EntityExtended#vertices

Source:
Returns:
{ Array } vertices.
Example
// normally, vertices are never calculated
// but you can force vertices to be updated on change
entity.needsVertices = true;
// this is a bad idea
var vertices = entity.getVertices();
// this is a good idea
var vertices = entity.vertices;

getVerticesWorld() → {Array}

Calculates vertices in world space.
- verticesWorld are in world space and are not scaled to window
- instead of calling this, use ig.EntityExtended#verticesWorld

Source:
Returns:
{ Array } vertices.
Example
// normally, vertices are never calculated
// but you can force vertices to be updated on change
entity.needsVertices = true;
// this is a bad idea
var verticesWorld = entity.getVerticesWorld();
// this is a good idea
var verticesWorld = entity.verticesWorld;

handleMovementTrace()

Enhanced handling of results of collision with collision map.

Source:
Example
// generally, climbable tiles are IGNORED
// if we need them we should be using game's shapesPasses
myGame.shapesPasses = [
     {
         ignoreSolids: true,
         ignoreOneWays: true
     }
]
// this is because movement trace only catches collisions
// and it does not record the tile(s) this entity is within
// but the above shapes passes will extract climbable shapes
// and create entities of them, so we can know when
// one entity is within another entity that is climbable

hide()

Sets ig.EntityExtended#hidden to true.

Source:

init(x, y, settings)

Initializes entity.
- initializes types for checks, via ig.EntityExtended#initTypes
- initializes properties that are created at run-time, such as signals and timers, via ig.EntityExtended#initProperties
- resets entity, merges in new settings, and initializes animations via ig.EntityExtended#reset

Parameters:
Name Type Argument Description
x Number x position.
y Number y position.
settings Object <optional>
settings object.
Source:

initOpaqueVertices()

Initializes vertices for shadow casting.

Source:

initProperties()

Adds properties that should only be initialized once.

Source:

initTypes()

Adds this entity's types and checks.

Source:

intersectWith(entity)

Called when two entities intersect, regardless of collides and before checks or collisions.

Parameters:
Name Type Description
entity ig.EntityExtended entity intersecting.
Source:

kill(silent)

Kills entity and shows optional effects, animation, etc via ig.EntityExtended#death.
- this is not the same as ig.GameExtended#removeEntity

Parameters:
Name Type Argument Description
silent Boolean <optional>
whether to die without effects or animation.
Source:
See:
  • ig.Entity.

lineOfSight(entity) → {Boolean}

Whether this entity can see another in a direct line of sight.

Parameters:
Name Type Description
entity ig.EntityExtended entity to check against.
Source:
Returns:
{ Boolean } if sees other.

Links entity to another entity, making original refresh after the entity it is linked to. Tip: this allows for entity chaining and pseudo parent/child transforms.

Parameters:
Name Type Argument Default Description
entity ig.EntityExtended to link to.
refresh Boolean <optional>
true whether to refresh after linking.
Source:

lookAt(target)

Flips entity to face a target entity or position.

Parameters:
Name Type Description
target ig.EntityExtended | Vector2 | Object target to look at.
Source:

manageStart()

Called automatically by ig.GameExtended#PlayerManager when managing entity as if player were playing them.

Source:

manageStop()

Called automatically by ig.GameExtended#PPlayerManager when done managing entity.

Source:

moveAllStop()

Stops all movement immediately.

Source:

moveTo(item, settings) → {Boolean}

Moves to an item, which can be an entity or a position.

Parameters:
Name Type Argument Description
item ig.EntityExtended | Vector2 | Object entity with bounds or position with x and y properties.
settings Object <optional>
settings for move.
Source:
Returns:
{ Boolean } whether a new move to has been started
Example
// settings is a plain object
settings = {};
// to ensure entity follows other properly
settings.matchPerformance = true;
// to move to only once
settings.once = true;
// follow defaults to aligning at center of followed
// to follow at the top left instead of center
settings.align = { x: 0, y: 0 };
// to follow and flip with whatever we're moving to
settings.flipWith = true;
// to follow offset by 10 px
settings.offset = { x: 10, y: 10 };
// to follow above
settings.offsetPct = { x: 0, y: -1 };
// to follow at a random offset between -0.25 and 0.25 on both axes
settings.randomOffsetPct = { x: 0.25, y: 0.25 };
// a lerp between 0 and 1 will cause a smooth follow
settings.lerp = 0.1;
// a tweened follow with optional tween settings based on ig.EntityExtended#tween
settings.tween = true;
settings.tweenSettings = {...};

moveToComplete() → {Boolean}

Called when moved to complete.

Source:
Returns:
{ Boolean } true when move is completed, otherwise is continuing sequence.

moveToPosition(item, settings)

Positions this entity relative to moving to item based on settings.

Parameters:
Name Type Argument Description
item ig.EntityExtended | Vector2 | Object item to move to.
settings Object <optional>
settings object.
Source:
See:

moveToSequenceNext()

Moves to next in current sequence of moving to entities.

Source:

moveToStop()

Ends any moveTo in progress.

Source:

moveToUpdate()

Updates any moveTo in progress.

Source:

pause()

Pauses entity.

Source:

projectShadow(point, radius, a, b, pointToA, pointToB, aToB) → {Array}

Projects an edge based on an point.

Parameters:
Name Type Description
point Vector2 | Object 2d point to project from.
radius Number
a Object edge vertex a.
b Object edge vertex b.
pointToA Vector2 | Object 2d vector from point to vertex a.
pointToB Vector2 | Object 2d vector from point to vertex b.
aToB Object 2d vector from vertex a to vertex b.
Source:
Returns:
{ Array } vertices of the shape cast by light from edge.

ready()

Called automatically when entity added to game world.

Source:
See:
  • ig.Entity.

rebuild()

Rebuilds entity by updating all animations.

Source:

receiveDamage(amount, from, unblockable) → {Boolean}

Does damage to entity while checking if invulnerable.

Parameters:
Name Type Argument Description
amount Number amount of damage.
from ig.EntityExtended <optional>
entity causing damage.
unblockable Boolean <optional>
whether damage cannot be blocked.
Source:
Returns:
{ Boolean } whether damage was applied.

recordChanges(force)

Records limited changes in transform and sets ig.EntityExtended#changed and ig.EntityExtended#moving.
- called automatically by ig.EntityExtended#update

Parameters:
Name Type Argument Description
force Boolean <optional>
forces changed.
Source:

recordLast()

Records last transform.
- called automatically by ig.EntityExtended#update

Source:

recordResetState()

Records the state of an entity for later reset.
- does not record all properties for performance reasons

Source:

refresh(force)

Refreshes entity size, position, etc when screen is resized or linked to is refreshed. Tip: usually this is best applied to UI elements and not dynamic entities.

Parameters:
Name Type Argument Description
force Boolean <optional>
whether to force.
Source:

removeControl()

Removes control from entity. Tip: this blocks entity from calling ig.GameExtended#updateChanges during update cycle.

Source:

reposition(force)

Repositions entity. Tip: by default, this method does nothing, so override this method with a class specific one.

Parameters:
Name Type Argument Description
force Boolean <optional>
whether to force.
Source:

reset(x, y, settings)

Resets an entity to last state.

Parameters:
Name Type Argument Description
x Number x position.
y Number y position.
settings Object <optional>
settings object.
Source:

resetCore(x, y, settings)

Resets settings and position of entity.

Parameters:
Name Type Argument Description
x Number x position.
y Number y position.
settings Object <optional>
settings object.
Source:

resetExtras()

Resets extra properties after core.

Source:

resetToInitAnim()

Resets current anim to initial animation.

Source:

resize(force)

Resizes entity. Tip: by default, this method does nothing, so override this method with a class specific one.

Parameters:
Name Type Argument Description
force Boolean <optional>
whether to force.
Source:

setControllable(controllable)

Sets whether entity can control self.

Parameters:
Name Type Argument Default Description
controllable Boolean <optional>
true
Source:

setGrounded(withoutVelocity)

Sets entity as grounded. Only changes gravity state if has gravity.

Parameters:
Name Type Argument Default Description
withoutVelocity Boolean <optional>
false whether to leave velocity untouched
Source:

setHidden(hidden)

Sets ig.EntityExtended#hidden.

Parameters:
Name Type Argument Default Description
hidden Boolean <optional>
false whether entity should be hidden.
Source:

setPerformance()

Sets this entity's performance level.

Source:

setUngrounded()

Sets entity as ungrounded.

Source:

spawn()

Called after ig.EntityExtended#ready when spawn animation is complete.
- sets ig.EntityExtended#currentAnim to ig.EntityExtended#animInit if present
- activates entity if ig.EntityExtended#activated is true

Source:

toggleActivate(entity)

Toggles between activate and deactivate.

Parameters:
Name Type Argument Description
entity Entity <optional>
causing deactivation.
Source:

touches(entity) → {Boolean}

Whether this entity touches another.

Parameters:
Name Type Description
entity ig.EntityExtended entity to check against.
Source:
Returns:
{ Boolean } if touches other.

tween(properties, settings) → {Tween}

Simple tween of specified properties. IMPORTANT: make sure this entity has all tweening properties.

Parameters:
Name Type Argument Description
properties Object property values on entity.
settings Object <optional>
settings for tween, based on ig.TWEEN.tween.
Source:
Returns:
{ Tween } tween object.

tweenEnd(name)

Stops tweens on this entity. IMPORTANT: if no specific tween name passed, will stop all tweens.

Parameters:
Name Type Argument Description
name String <optional>
name of specific tween.
Source:

unhide()

Sets ig.EntityExtended#hidden to false.

Source:

Unlinks entity from whatever it was linked to.

Parameters:
Name Type Argument Default Description
refresh Boolean <optional>
true whether to refresh after unlinking.
Source:

unpause()

Unpauses entity.

Source:

update()

Entities update is now broken down into a series of functions/methods, which can be opted into based on ig.EntityExtended#frozen and ig.EntityExtended#performance.
- paused and frozen entities don't update at all
- performance === ig.EntityExtended.PERFORMANCE.STATIC entities only check if visible and do ig.EntityExtended#updateVisible
- performance === ig.EntityExtended.PERFORMANCE.MOVABLE does all static performance steps plus can move self or be moved, but ignores collision map, and checks for changes via ig.EntityExtended#updateChanges and ig.EntityExtended#recordChanges
- performance === ig.EntityExtended.PERFORMANCE.DYNAMIC does all movable performance steps plus collides with collision map and has physics forces via ig.EntityExtended#updateDynamics IMPORTANT: ig.EntityExtended#performance has nothing to do with entity to entity collisions, which is defined by ig.EntityExtended#collides.

Source:

updateBounds()

Updates bounds.
- called automatically by ig.EntityExtended#recordChanges when ig.EntityExtended#needsBounds

Source:

updateChanges()

Changes entity.
- called automatically by ig.EntityExtended#update Tip: use this method to handle moving, acting, etc, instead of the main update method.

Source:

updateDynamics()

Updates dynamic properties such as velocity, gravity, collisions with collision map, etc.
- called automatically by ig.EntityExtended#update IMPORTANT: if you change the way bounds are calculated you will also need to override the updateDynamics method!

Source:

updateVelocity()

Updates velocity based on acceleration and friction.
- called automatically by ig.EntityExtended#updateDynamics

Source:

updateVisible()

Called when visible to update animations.
- called automatically by ig.EntityExtended#update

Source: