Home Reference Source Repository

js/GameplayKit/GKAgent2D.js

  1. 'use strict'
  2.  
  3. import CGPoint from '../CoreGraphics/CGPoint'
  4. import GKAgent from './GKAgent'
  5.  
  6. /**
  7. * An agent that operates in a two-dimensional space.
  8. * @access public
  9. * @extends {GKAgent}
  10. * @see https://developer.apple.com/documentation/gameplaykit/gkagent2d
  11. */
  12. export default class GKAgent2D extends GKAgent {
  13.  
  14. /**
  15. * constructor
  16. * @access public
  17. * @constructor
  18. */
  19. constructor() {
  20. super()
  21.  
  22. // Managing an Agent’s Position and Orientation
  23.  
  24. /**
  25. * The current position of the agent in 2D space.
  26. * @type {CGPoint}
  27. * @see https://developer.apple.com/documentation/gameplaykit/gkagent2d/1501043-position
  28. */
  29. this.position = new CGPoint(0, 0)
  30.  
  31. /**
  32. * The rotation of the agent around the z-axis.
  33. * @type {number}
  34. * @see https://developer.apple.com/documentation/gameplaykit/gkagent2d/1501045-rotation
  35. */
  36. this.rotation = 0
  37.  
  38.  
  39. // Running the Agent Simulation
  40.  
  41. /**
  42. * @access private
  43. * @type {CGPoint}
  44. */
  45. this._velocity = new CGPoint()
  46. }
  47.  
  48. // Running the Agent Simulation
  49.  
  50. /**
  51. * Causes the agent to evaluate its goals and update its position, rotation, and velocity accordingly.
  52. * @access public
  53. * @param {number} seconds -
  54. * @returns {void}
  55. * @desc You call this method directly on an individual agent, or on all the agents in your game through a GKComponentSystem object, whenever you want to run a step of the agent simulation. Typically, a game updates its agent simulation whenever it prepares to draw a new frame—for example, in the update(_:) method of a SpriteKit SKScene object.
  56. * @see https://developer.apple.com/documentation/gameplaykit/gkagent2d/1501242-update
  57. */
  58. updateDeltaTime(seconds) {
  59. }
  60.  
  61. /**
  62. * The current velocity of the agent in 2D space.
  63. * @type {CGPoint}
  64. * @desc An agent’s velocity is a calculated property—the velocity vector is determined by an agent’s facing direction (its rotation property) and its speed property.
  65. * @see https://developer.apple.com/documentation/gameplaykit/gkagent2d/1501186-velocity
  66. */
  67. get velocity() {
  68. return this._velocity
  69. }
  70. }