diff --git a/.travis.yml b/.travis.yml index 2a66c8ff..56ed861f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,5 +5,5 @@ dist: trusty sudo: required addons: chrome: stable -script: npm test && npm run test-sprite +script: npm test && npm run test:permutations after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" \ No newline at end of file diff --git a/docs/api/animation.html b/docs/api/animation.html index aef04287..f17de451 100644 --- a/docs/api/animation.html +++ b/docs/api/animation.html @@ -46,6 +46,7 @@
  • Core
  • Events
  • GameLoop
  • +
  • GameObject
  • Keyboard
  • Plugin
  • Pointer
  • diff --git a/docs/api/assets.html b/docs/api/assets.html index 873d384f..b64e5d70 100644 --- a/docs/api/assets.html +++ b/docs/api/assets.html @@ -46,6 +46,7 @@
  • Core
  • Events
  • GameLoop
  • +
  • GameObject
  • Keyboard
  • Plugin
  • Pointer
  • diff --git a/docs/api/collision.html b/docs/api/collision.html index ded8a6d3..5020a827 100644 --- a/docs/api/collision.html +++ b/docs/api/collision.html @@ -46,6 +46,7 @@
  • Core
  • Events
  • GameLoop
  • +
  • GameObject
  • Keyboard
  • Plugin
  • Pointer
  • diff --git a/docs/api/core.html b/docs/api/core.html index 7f76ba86..0d4c395c 100644 --- a/docs/api/core.html +++ b/docs/api/core.html @@ -46,6 +46,7 @@
  • Core
  • Events
  • GameLoop
  • +
  • GameObject
  • Keyboard
  • Plugin
  • Pointer
  • diff --git a/docs/api/events.html b/docs/api/events.html index 8d346c59..1477b8c3 100644 --- a/docs/api/events.html +++ b/docs/api/events.html @@ -46,6 +46,7 @@
  • Core
  • Events
  • GameLoop
  • +
  • GameObject
  • Keyboard
  • Plugin
  • Pointer
  • diff --git a/docs/api/gameLoop.html b/docs/api/gameLoop.html index 09ff6480..c9bff726 100644 --- a/docs/api/gameLoop.html +++ b/docs/api/gameLoop.html @@ -46,6 +46,7 @@
  • Core
  • Events
  • GameLoop
  • +
  • GameObject
  • Keyboard
  • Plugin
  • Pointer
  • diff --git a/docs/api/gameobject.html b/docs/api/gameobject.html new file mode 100644 index 00000000..6dcf343d --- /dev/null +++ b/docs/api/gameobject.html @@ -0,0 +1,1042 @@ + + + + Kontra.js – GameObject + + + + + + + + + + +
    + + +
    +
    + + +

    GameObject(​properties) +

    + +

    A versatile way to update and draw your game objects. It can handle simple rectangles, images, and game object sheet animations. It can be used for your main player object as well as tiny particles in a particle engine.

    +

    GameObject Parameters

    +
    +
    + properties + +
    +

    Object. Properties of the game object.

    +
    +
    + properties.x + +
    +

    Number. X coordinate of the position vector.

    +
    +
    + properties.y + +
    +

    Number. Y coordinate of the position vector.

    +
    +
    + properties.dx + Optional +
    +

    Number. X coordinate of the velocity vector.

    +
    +
    + properties.dy + Optional +
    +

    Number. Y coordinate of the velocity vector.

    +
    +
    + properties.ddx + Optional +
    +

    Number. X coordinate of the acceleration vector.

    +
    +
    + properties.ddy + Optional +
    +

    Number. Y coordinate of the acceleration vector.

    +
    +
    + properties.color + Optional +
    +

    String. Fill color for the game object if no image or animation is provided.

    +
    +
    + properties.width + Optional +
    +

    Number. Width of the game object.

    +
    +
    + properties.height + Optional +
    +

    Number. Height of the game object.

    +
    +
    + properties.ttl + Optional +
    +

    Number. How many frames the game object should be alive. Used by Pool. Defaults to Infinity.

    +
    +
    + properties.rotation + Optional +
    +

    Number. game objects rotation around the origin in radians. Defaults to 0.

    +
    +
    + properties.anchor + Optional +
    +

    Number. The x and y origin of the game object. {x:0, y:0} is the top left corner of the game object, {x:1, y:1} is the bottomright corner. Defaults to {x:0,y:0}.

    +
    +
    + properties.context + Optional +
    +

    Canvas​Rendering​Context2D. The context the game object should draw to. Defaults to core.getContext().

    +
    +
    + properties.image + Optional +
    +

    Image or HTMLCanvasElement. Use an image to draw the game object.

    +
    +
    + properties.animations + Optional +
    +

    Object. An object of Animations from a game objectsheet to animate the game object.

    +
    +
    + properties.update + Optional +
    +

    Function. Function called every frame to update the game object.

    +
    +
    + properties.render + Optional +
    +

    Function. Function called every frame to render the game object.

    +
    +
    + properties.* + Optional +
    +

    Any type. Any additional properties you need added to the game object. For example, if you pass game object({type: 'player'}) then the game object will also have a property of the same name and value. You can pass as many additional properties as you want.

    +
    +
    + + +
    +

    Table of Contents

    + + +
    + + +
    +

    + + GameObject​.acceleration + + +

    + +

    The game objects acceleration vector.

    + +
    +
    +

    + + GameObject​.advance(​[dt]) + + +

    + +

    Move the game object by its acceleration and velocity. If the game object is an [animation game object](api/gameObject#animation-game object), it also advances the animation every frame.

    +

    If you override the game objects update() function with your own update function, you can call this function to move the game object normally.

    +
    +
      +
    • + +
    • +
    • + +
    • +
    • + +
    • +
    • +
    +
    let { game object } = kontra;
    +
    +let game object = game object({
    +  x: 100,
    +  y: 200,
    +  width: 20,
    +  height: 40,
    +  dx: 5,
    +  dy: 2,
    +  update: function() {
    +    // move the game object normally
    +    game object.advance();
    +
    +    // change the velocity at the edges of the canvas
    +    if (this.x < 0 ||
    +        this.x + this.width > this.context.canvas.width) {
    +      this.dx = -this.dx;
    +    }
    +    if (this.y < 0 ||
    +        this.y + this.height > this.context.canvas.height) {
    +      this.dy = -this.dy;
    +    }
    +  }
    +});
    +
    import { game object } from 'path/to/kontra.mjs';
    +
    +let game object = game object({
    +  x: 100,
    +  y: 200,
    +  width: 20,
    +  height: 40,
    +  dx: 5,
    +  dy: 2,
    +  update: function() {
    +    // move the game object normally
    +    game object.advance();
    +
    +    // change the velocity at the edges of the canvas
    +    if (this.x < 0 ||
    +        this.x + this.width > this.context.canvas.width) {
    +      this.dx = -this.dx;
    +    }
    +    if (this.y < 0 ||
    +        this.y + this.height > this.context.canvas.height) {
    +      this.dy = -this.dy;
    +    }
    +  }
    +});
    +
    import { game object } from 'kontra';
    +
    +let game object = game object({
    +  x: 100,
    +  y: 200,
    +  width: 20,
    +  height: 40,
    +  dx: 5,
    +  dy: 2,
    +  update: function() {
    +    // move the game object normally
    +    game object.advance();
    +
    +    // change the velocity at the edges of the canvas
    +    if (this.x < 0 ||
    +        this.x + this.width > this.context.canvas.width) {
    +      this.dx = -this.dx;
    +    }
    +    if (this.y < 0 ||
    +        this.y + this.height > this.context.canvas.height) {
    +      this.dy = -this.dy;
    +    }
    +  }
    +});
    +
    +

    advance Parameters

    +
    +
    + dt + Optional +
    +

    Number. Time since last update.

    +
    +
    + +
    +
    +

    + + GameObject​.anchor + + +

    + +

    The x and y origin of the game object. {x:0, y:0} is the top left corner of the game object, {x:1, y:1} is the bottom right corner.

    + + +
    +
      +
    • + +
    • +
    • + +
    • +
    • + +
    • +
    • +
    +
    +
    let { game object } = kontra
    +
    +let game object = game object({
    +  x: 150,
    +  y: 100,
    +  color: 'red',
    +  width: 50,
    +  height: 50,
    +  render: function() {
    +    this.draw();
    +
    +    // draw origin
    +    this.context.fillStyle = 'yellow';
    +    this.context.beginPath();
    +    this.context.arc(this.x, this.y, 3, 0, 2*Math.PI);
    +    this.context.fill();
    +  }
    +});
    +game object.render();
    +
    +game object.anchor = {x: 0.5, y: 0.5};
    +game object.x = 300;
    +game object.render();
    +
    +game object.anchor = {x: 1, y: 1};
    +game object.x = 450;
    +game object.render();
    +
    +
    +
    import { game object } from 'path/to/kontra.mjs'
    +
    +let game object = game object({
    +  x: 150,
    +  y: 100,
    +  color: 'red',
    +  width: 50,
    +  height: 50,
    +  render: function() {
    +    this.draw();
    +
    +    // draw origin
    +    this.context.fillStyle = 'yellow';
    +    this.context.beginPath();
    +    this.context.arc(this.x, this.y, 3, 0, 2*Math.PI);
    +    this.context.fill();
    +  }
    +});
    +game object.render();
    +
    +game object.anchor = {x: 0.5, y: 0.5};
    +game object.x = 300;
    +game object.render();
    +
    +game object.anchor = {x: 1, y: 1};
    +game object.x = 450;
    +game object.render();
    +
    +
    +
    import { game object } from 'kontra';
    +
    +let game object = game object({
    +  x: 150,
    +  y: 100,
    +  color: 'red',
    +  width: 50,
    +  height: 50,
    +  render: function() {
    +    this.draw();
    +
    +    // draw origin
    +    this.context.fillStyle = 'yellow';
    +    this.context.beginPath();
    +    this.context.arc(this.x, this.y, 3, 0, 2*Math.PI);
    +    this.context.fill();
    +  }
    +});
    +game object.render();
    +
    +game object.anchor = {x: 0.5, y: 0.5};
    +game object.x = 300;
    +game object.render();
    +
    +game object.anchor = {x: 1, y: 1};
    +game object.x = 450;
    +game object.render();
    +
    +
    + + +
    +
    +

    + + GameObject​.children + + +

    + +

    The game objects children objects.

    + +
    +
    +

    + + GameObject​.color + + +

    + +

    The color of the game object if it was passed as an argument.

    + +
    +
    +

    + + GameObject​.context + + +

    + +

    The context the game object will draw to.

    + +
    +
    +

    + + GameObject​.ddx + + +

    + +

    X coordinate of the acceleration vector.

    + +
    +
    +

    + + GameObject​.ddy + + +

    + +

    Y coordinate of the acceleration vector.

    + +
    +
    +

    + + GameObject​.draw(​) + + +

    + +

    Draw the game object at its X and Y position. This function changes based on the type of the game object. For a [rectangle game object](api/gameObject#rectangle-game object), it uses context.fillRect(), for an [image game object](api/gameObject#image-game object) it uses context.drawImage(), and for an [animation game object](api/gameObject#animation-game object) it uses the currentAnimation render() function.

    +

    If you override the game objects render() function with your own render function, you can call this function to draw the game object normally.

    +
    +
      +
    • + +
    • +
    • + +
    • +
    • + +
    • +
    • +
    +
    let { game object } = kontra;
    +
    +let game object = game object({
    + x: 290,
    + y: 80,
    + color: 'red',
    + width: 20,
    + height: 40,
    +
    + render: function() {
    +   // draw the rectangle game object normally
    +   this.draw();
    +
    +   // outline the game object
    +   this.context.strokeStyle = 'yellow';
    +   this.context.lineWidth = 2;
    +   this.context.strokeRect(this.x, this.y, this.width, this.height);
    + }
    +});
    +
    +game object.render();
    +
    import { game object } from 'path/to/kontra.mjs';
    +
    +let game object = game object({
    + x: 290,
    + y: 80,
    + color: 'red',
    + width: 20,
    + height: 40,
    +
    + render: function() {
    +   // draw the rectangle game object normally
    +   this.draw();
    +
    +   // outline the game object
    +   this.context.strokeStyle = 'yellow';
    +   this.context.lineWidth = 2;
    +   this.context.strokeRect(this.x, this.y, this.width, this.height);
    + }
    +});
    +
    +game object.render();
    +
    import { game object } from 'kontra';
    +
    +let game object = game object({
    + x: 290,
    + y: 80,
    + color: 'red',
    + width: 20,
    + height: 40,
    +
    + render: function() {
    +   // draw the rectangle game object normally
    +   this.draw();
    +
    +   // outline the game object
    +   this.context.strokeStyle = 'yellow';
    +   this.context.lineWidth = 2;
    +   this.context.strokeRect(this.x, this.y, this.width, this.height);
    + }
    +});
    +
    +game object.render();
    +
    + +
    +
    +

    + + GameObject​.dx + + +

    + +

    X coordinate of the velocity vector.

    + +
    +
    +

    + + GameObject​.dy + + +

    + +

    Y coordinate of the velocity vector.

    + +
    +
    +

    + + GameObject​.height + + +

    + +

    The height of the game object. If the game object is a [rectangle game object](api/gameObject#rectangle-game object), it uses the passed in value. For an [image game object](api/gameObject#image-game object) it is the height of the image. And for an [animation game object](api/gameObject#animation-game object) it is the height of a single frame of the animation.

    +

    Setting the value to a negative number will result in the game object being flipped across the horizontal axis while the height will remain a positive value.

    + +
    +
    +

    + + GameObject​.init(​properties) + + +

    + +

    Use this function to reinitialize a game object. It takes the same properties object as the constructor. Useful it you want to repurpose a game object.

    +

    init Parameters

    +
    +
    + properties + +
    +

    Object. Properties of the game object.

    +
    +
    + +
    +
    +

    + + GameObject​.isAlive(​) + + +

    + +

    Check if the game object is alive. Primarily used by Pool to know when to recycle an object.

    + +

    isAlive Return value

    +

    true if the game objects ttl property is above 0, false otherwise.

    +

    +
    +
    +

    + + GameObject​.localPosition + + +

    + +

    The game objects local rotation, which is its rotation relative to a parent object. If the game object does not have a parent object, the local rotation will be the same as the [rotation](api/gameObject#rotation].

    + +
    +
    +

    + + GameObject​.localPosition + + +

    + +

    The game objects local position vector, which is its position relative to a parent object. If the game object does not have a parent object, the local position will be the same as the [position vector](api/gameObject#position].

    + +
    +
    +

    + + GameObject​.parent + + +

    + +

    The game objects parent object.

    + +
    +
    +

    + + GameObject​.position + + +

    + +

    The game objects position vector. The game objects position is its position in the world, as opposed to the position in the viewport. Typically the position in the world and the viewport are the same value. If the game object has been added to a tileEngine, the position vector represents where in the tile world the game object is while the viewport represents where to draw the game object in relation to the top-left corner of the canvas.

    + +
    +
    +

    + + GameObject​.render(​) + + +

    + +

    Render the game object. Calls the game objects draw() function.

    + +
    +
    +

    + + GameObject​.rotation + + +

    + +

    The rotation of the game object around the origin in radians. This rotation takes into account rotations from parent objects.

    + +
    +
    +

    + + GameObject​.sx + + +

    + +

    The X coordinate of the camera. Used to determine viewX.

    + +
    +
    +

    + + GameObject​.sy + + +

    + +

    The Y coordinate of the camera. Used to determine viewY.

    + +
    +
    +

    + + GameObject​.ttl + + +

    + +

    How may frames the game object should be alive. Primarily used by Pool to know when to recycle an object.

    + +
    +
    +

    + + GameObject​.update(​[dt]) + + +

    + +

    Update the game objects position based on its velocity and acceleration. Calls the game objects advance() function.

    +

    update Parameters

    +
    +
    + dt + Optional +
    +

    Number. Time since last update.

    +
    +
    + +
    +
    +

    + + GameObject​.velocity + + +

    + +

    The game objects velocity vector.

    + +
    +
    +

    + + GameObject​.viewX + + +

    + +

    Readonly. X coordinate of where to draw the game object. Typically the same value as the position vector unless the game object has been added to a tileEngine.

    + +
    +
    +

    + + GameObject​.viewY + + +

    + +

    Readonly. Y coordinate of where to draw the game object. Typically the same value as the position vector unless the game object has been added to a tileEngine.

    + +
    +
    +

    + + GameObject​.width + + +

    + +

    The width of the game object. If the game object is a [rectangle game object](api/gameObject#rectangle-game object), it uses the passed in value. For an [image game object](api/gameObject#image-game object) it is the width of the image. And for an [animation game object](api/gameObject#animation-game object) it is the width of a single frame of the animation.

    +

    Setting the value to a negative number will result in the game object being flipped across the vertical axis while the width will remain a positive value.

    + +
    +
    +

    + + GameObject​.x + + +

    + +

    X coordinate of the position vector.

    + +
    +
    +

    + + GameObject​.y + + +

    + +

    Y coordinate of the position vector.

    + +
    + +
    +
    +
    + + + + + + + \ No newline at end of file diff --git a/docs/api/keyboard.html b/docs/api/keyboard.html index 7532fc8e..79071d10 100644 --- a/docs/api/keyboard.html +++ b/docs/api/keyboard.html @@ -46,6 +46,7 @@
  • Core
  • Events
  • GameLoop
  • +
  • GameObject
  • Keyboard
  • Plugin
  • Pointer
  • diff --git a/docs/api/plugin.html b/docs/api/plugin.html index 1f4a8a1e..0bb867e7 100644 --- a/docs/api/plugin.html +++ b/docs/api/plugin.html @@ -46,6 +46,7 @@
  • Core
  • Events
  • GameLoop
  • +
  • GameObject
  • Keyboard
  • Plugin
  • Pointer
  • diff --git a/docs/api/pointer.html b/docs/api/pointer.html index 5dda4fa3..945b7a70 100644 --- a/docs/api/pointer.html +++ b/docs/api/pointer.html @@ -46,6 +46,7 @@
  • Core
  • Events
  • GameLoop
  • +
  • GameObject
  • Keyboard
  • Plugin
  • Pointer
  • diff --git a/docs/api/pool.html b/docs/api/pool.html index 01a8cb18..e6ce1862 100644 --- a/docs/api/pool.html +++ b/docs/api/pool.html @@ -46,6 +46,7 @@
  • Core
  • Events
  • GameLoop
  • +
  • GameObject
  • Keyboard
  • Plugin
  • Pointer
  • diff --git a/docs/api/quadtree.html b/docs/api/quadtree.html index 7dc7b915..5bbfd55b 100644 --- a/docs/api/quadtree.html +++ b/docs/api/quadtree.html @@ -46,6 +46,7 @@
  • Core
  • Events
  • GameLoop
  • +
  • GameObject
  • Keyboard
  • Plugin
  • Pointer
  • diff --git a/docs/api/sprite.html b/docs/api/sprite.html index c24d19f8..bafa7369 100644 --- a/docs/api/sprite.html +++ b/docs/api/sprite.html @@ -46,6 +46,7 @@
  • Core
  • Events
  • GameLoop
  • +
  • GameObject
  • Keyboard
  • Plugin
  • Pointer
  • @@ -149,7 +150,7 @@

    Sprite Parametersproperties.anchor Optional -

    Number. The x and y origin of the sprite. {x:0, y:0} is the top left corner of the sprite, {x:1, y:1} is the bottom right corner. Defaults to {x:0,y:0}.

    +

    Number. The x and y origin of the sprite. {x:0, y:0} is the top left corner of the sprite, {x:1, y:1} is the bottomright corner. Defaults to {x:0,y:0}.

    properties.context @@ -207,162 +208,32 @@

    Table of Contents

    Properties

  • Methods

  • @@ -377,22 +248,22 @@

    In its most basic form, a sprite is a rectangle with a fill color. To create a rectangle sprite, pass the arguments width, height, and color. A rectangle sprite is great for initial prototyping and particles.

    - +
    • - +
    • - +
    • - +
    -
    +
    let { Sprite } = kontra
     
     let sprite = Sprite({
    @@ -408,7 +279,7 @@ 

    sprite.render();

    -
    +
    import { Sprite } from 'path/to/kontra.mjs'
     
     let sprite = Sprite({
    @@ -424,7 +295,7 @@ 

    sprite.render();

    -
    +
    import { Sprite } from 'kontra';
     
     let sprite = Sprite({
    @@ -443,8 +314,8 @@ 

    -

    @@ -1316,28 +917,6 @@

    sprite.playAnimation('idle');

    - -
    -

    - - Sprite​.color - - -

    - -

    The color of the sprite if it was passed as an argument.

    - -
    -
    -

    - - Sprite​.context - - -

    - -

    The context the sprite will draw to.

    -

    @@ -1349,151 +928,6 @@

    The currently playing Animation object if animations was passed as an argument.

    -

    -
    -

    - - Sprite​.ddx - - -

    - -

    X coordinate of the acceleration vector.

    - -
    -
    -

    - - Sprite​.ddy - - -

    - -

    Y coordinate of the acceleration vector.

    - -
    -
    -

    - - Sprite​.draw(​) - - -

    - -

    Draw the sprite at its X and Y position. This function changes based on the type of the sprite. For a rectangle sprite, it uses context.fillRect(), for an image sprite it uses context.drawImage(), and for an animation sprite it uses the currentAnimation render() function.

    -

    If you override the sprites render() function with your own render function, you can call this function to draw the sprite normally.

    -
    -
      -
    • - -
    • -
    • - -
    • -
    • - -
    • -
    • -
    -
    let { Sprite } = kontra;
    -
    -let sprite = Sprite({
    - x: 290,
    - y: 80,
    - color: 'red',
    - width: 20,
    - height: 40,
    -
    - render: function() {
    -   // draw the rectangle sprite normally
    -   this.draw();
    -
    -   // outline the sprite
    -   this.context.strokeStyle = 'yellow';
    -   this.context.lineWidth = 2;
    -   this.context.strokeRect(this.x, this.y, this.width, this.height);
    - }
    -});
    -
    -sprite.render();
    -
    import { Sprite } from 'path/to/kontra.mjs';
    -
    -let sprite = Sprite({
    - x: 290,
    - y: 80,
    - color: 'red',
    - width: 20,
    - height: 40,
    -
    - render: function() {
    -   // draw the rectangle sprite normally
    -   this.draw();
    -
    -   // outline the sprite
    -   this.context.strokeStyle = 'yellow';
    -   this.context.lineWidth = 2;
    -   this.context.strokeRect(this.x, this.y, this.width, this.height);
    - }
    -});
    -
    -sprite.render();
    -
    import { Sprite } from 'kontra';
    -
    -let sprite = Sprite({
    - x: 290,
    - y: 80,
    - color: 'red',
    - width: 20,
    - height: 40,
    -
    - render: function() {
    -   // draw the rectangle sprite normally
    -   this.draw();
    -
    -   // outline the sprite
    -   this.context.strokeStyle = 'yellow';
    -   this.context.lineWidth = 2;
    -   this.context.strokeRect(this.x, this.y, this.width, this.height);
    - }
    -});
    -
    -sprite.render();
    -
    - -
    -
    -

    - - Sprite​.dx - - -

    - -

    X coordinate of the velocity vector.

    - -
    -
    -

    - - Sprite​.dy - - -

    - -

    Y coordinate of the velocity vector.

    - -
    -
    -

    - - Sprite​.height - - -

    - -

    The height of the sprite. If the sprite is a rectangle sprite, it uses the passed in value. For an image sprite it is the height of the image. And for an animation sprite it is the height of a single frame of the animation.

    -

    Setting the value to a negative number will result in the sprite being flipped across the horizontal axis while the height will remain a positive value.

    -

    @@ -1506,40 +940,6 @@

    The image the sprite will use when drawn if passed as an argument.

    -
    -

    - - Sprite​.init(​properties) - - -

    - -

    Use this function to reinitialize a sprite. It takes the same properties object as the constructor. Useful it you want to repurpose a sprite.

    -

    init Parameters

    -
    -
    - properties - -
    -

    Object. Properties of the sprite.

    -
    -
    - -
    -
    -

    - - Sprite​.isAlive(​) - - -

    - -

    Check if the sprite is alive. Primarily used by Pool to know when to recycle an object.

    - -

    isAlive Return value

    -

    true if the sprites ttl property is above 0, false otherwise.

    -

    -

    @@ -1637,159 +1037,6 @@

    playAnimation

    -
    -

    - - Sprite​.position - - -

    - -

    The sprites position vector. The sprites position is its position in the world, as opposed to the position in the viewport. Typically the position in the world and the viewport are the same value. If the sprite has been added to a tileEngine, the position vector represents where in the tile world the sprite is while the viewport represents where to draw the sprite in relation to the top-left corner of the canvas.

    - -
    -
    -

    - - Sprite​.render(​) - - -

    - -

    Render the sprite. Calls the sprites draw() function.

    - -
    -
    -

    - - Sprite​.rotation - - -

    - -

    The rotation of the sprite around the origin in radians.

    - -
    -
    -

    - - Sprite​.sx - - -

    - -

    The X coordinate of the camera. Used to determine viewX.

    - -
    -
    -

    - - Sprite​.sy - - -

    - -

    The Y coordinate of the camera. Used to determine viewY.

    - -
    -
    -

    - - Sprite​.ttl - - -

    - -

    How may frames the sprite should be alive. Primarily used by Pool to know when to recycle an object.

    - -
    -
    -

    - - Sprite​.update(​[dt]) - - -

    - -

    Update the sprites position based on its velocity and acceleration. Calls the sprites advance() function.

    -

    update Parameters

    -
    -
    - dt - Optional -
    -

    Number. Time since last update.

    -
    -
    - -
    -
    -

    - - Sprite​.velocity - - -

    - -

    The sprites velocity vector.

    - -
    -
    -

    - - Sprite​.viewX - - -

    - -

    Readonly. X coordinate of where to draw the sprite. Typically the same value as the position vector unless the sprite has been added to a tileEngine.

    - -
    -
    -

    - - Sprite​.viewY - - -

    - -

    Readonly. Y coordinate of where to draw the sprite. Typically the same value as the position vector unless the sprite has been added to a tileEngine.

    - -
    -
    -

    - - Sprite​.width - - -

    - -

    The width of the sprite. If the sprite is a rectangle sprite, it uses the passed in value. For an image sprite it is the width of the image. And for an animation sprite it is the width of a single frame of the animation.

    -

    Setting the value to a negative number will result in the sprite being flipped across the vertical axis while the width will remain a positive value.

    - -
    -
    -

    - - Sprite​.x - - -

    - -

    X coordinate of the position vector.

    - -
    -
    -

    - - Sprite​.y - - -

    - -

    Y coordinate of the position vector.

    - -
    diff --git a/docs/api/spriteSheet.html b/docs/api/spriteSheet.html index 90baa627..f175a8e6 100644 --- a/docs/api/spriteSheet.html +++ b/docs/api/spriteSheet.html @@ -46,6 +46,7 @@
  • Core
  • Events
  • GameLoop
  • +
  • GameObject
  • Keyboard
  • Plugin
  • Pointer
  • diff --git a/docs/api/store.html b/docs/api/store.html index 51ee67b8..8b9b6d71 100644 --- a/docs/api/store.html +++ b/docs/api/store.html @@ -46,6 +46,7 @@
  • Core
  • Events
  • GameLoop
  • +
  • GameObject
  • Keyboard
  • Plugin
  • Pointer
  • diff --git a/docs/api/tileEngine.html b/docs/api/tileEngine.html index 510fb2e1..d7bb3abc 100644 --- a/docs/api/tileEngine.html +++ b/docs/api/tileEngine.html @@ -46,6 +46,7 @@
  • Core
  • Events
  • GameLoop
  • +
  • GameObject
  • Keyboard
  • Plugin
  • Pointer
  • @@ -336,22 +337,22 @@

    You'll then need to add at least one tileset with an image as well as firstgid, or first tile index of the tileset. The first tileset will always have a firstgid of 1 as 0 represents an empty tile.

    Lastly, you'll need to add at least one named layer with data. A layer tells the tile engine which tiles from the tileset image to use at what position on the map.

    Once all tileset images and all layers have been added, you can render the tile engine by calling its render() function.

    - +
    • - +
    • - +
    • - +
    -
    +
    let { TileEngine } = kontra
     
     let img = new Image();
    @@ -390,7 +391,7 @@ 

    tileEngine.render(); }

    -
    +
    import { TileEngine } from 'path/to/kontra.mjs'
     
     let img = new Image();
    @@ -429,7 +430,7 @@ 

    tileEngine.render(); }

    -
    +
    import { TileEngine } from 'kontra';
     
     let img = new Image();
    @@ -471,8 +472,8 @@