Copy class

Copies are the entities that interact with each other on the screen and what drives the game's logic. They derive from Pixi's AnimatedSprite class, so you can find much more parametersopen in new window at their docs site.

TIP

To create and find copies, see the ct.templates reference.

Moving Copies Around

Each Copy has these parameters for movement:

PropertyTypeDescription
x, ynumberCopy's location, by X and Y axes (horizontal and vertical axes).
xprev, yprevnumberThe location of a Copy in a previous frame.
xstart, ystartnumberThe coordinates at which a copy was created.
speednumberMovement speed (or the length of vector [hspeed; vspeed]).
hspeed, vspeednumberHorizontal and vertical speed.
directionnumberMovement direction (from 0 to 360, from right side going clock-wise).
gravitynumberGravity force, as an amount of speed added at each frame.
gravityDirnumberGravity direction (from 0 to 360, default is 90).

You can also call this.addSpeed to add speed vector to a Copy in a given direction.

this.addSpeed(speed, dir);

To actually move a copy, you should call this.move(); in your copy's OnStep code (it is included in each Type by default). Default movement system already takes ct.delta into account, so it will move with the same speed at every frame rate.

Manipulating Copies' look

There are a number of parameters that can be changed:

PropertyTypeDescription
alphanumberThe opacity of the copy. 0 makes a copy invisible, 1 is the default (fully opaque) mode. All in between will make a gradual transparency change.
blendModePIXI.BLEND_MODES (number)How to mix the copy with the rest of the world. Defaults to PIXI.BLEND_MODES.NORMAL. Can be one of:
  • PIXI.BLEND_MODES.NORMAL
  • PIXI.BLEND_MODES.ADD
  • PIXI.BLEND_MODES.MULTIPLY
  • PIXI.BLEND_MODES.SCREEN
depthnumberThe drawing layer.
anglenumberThe rotation of the copy in degrees ranging from 0 to 360, starting from right side and going clock-wise.
scalePIXI.ObservablePointThe scale factor of the object. You can either assign a simple value (this.scale = 0.5;) for uniform scaling or access its x and y compounds (this.scale.x = 0.5;).
texstringThe name of a ct.js texture to use. Setting this.tex = 'NewTexture'; will change the displayed texture and reset animation.
tintnumberThe tint applied to the sprite. This is a hex value. A value of 0xFFFFFF will remove any tint effect. The colors are the same as in CSS but with 0x instead of #, e.g. 0xFF0000 is red, 0x00FFFF is cyan, ect.
visiblenumberThe visibility of the object (true or false).

Animation

PropertyTypeDescription
animationSpeednumberAnimation speed. Higher is faster, lower is slower.
currentFramenumberRead-only. Current drawing frame index. You should change it with gotoAndPlay, gotoAndStop methods.
totalFramesnumberRead-only. The total number of frames in the Copy.

Methods:

copy.gotoAndPlay(frameIndex)

Goes to a specific frame and begins playing the animation.

copy.gotoAndStop(frameIndex)

Stops the animation and goes to a specific frame.

copy.play()

Plays the animation.

copy.stop()

Stops the animation.

Deleting Copies (this.kill property)

To delete a Copy, simply set its kill parameter to true.

Example: delete a Copy, if its health is depleted

if (this.health <= 0) {
    this.kill = true;
}

Note

OnStep code will still be executed to its end. Copies get logically deleted between OnStep and Draw calls.

Misc

copy.getRoom()

Returns the room that owns the current copy. This is useful when working with different rooms in a stage. Returns an instance of Room class.

copy.template

The name of the template from which a Copy was created (a string).