Home Reference Source Repository

js/SceneKit/SCNActionRunBlock.js

  1. 'use strict'
  2.  
  3. import SCNAction from './SCNAction'
  4. import SCNActionTimingMode from './SCNActionTimingMode'
  5.  
  6. export default class SCNActionRunBlock extends SCNAction {
  7. static get _propTypes() {
  8. return {
  9. _actions: 'NSArray',
  10. _finished: 'boolean',
  11. _duration: 'float',
  12. _timingMode: 'integer',
  13. _beginTime: 'float',
  14. _isRunning: 'boolean',
  15. _pausedTime: 'float',
  16.  
  17. name: ['string', null]
  18. }
  19. }
  20.  
  21. /**
  22. * constructor
  23. * @access public
  24. * @constructor
  25. */
  26. constructor() {
  27. super()
  28.  
  29. this._actions = []
  30. this._finished = false
  31. this._duration = 0
  32. this._timingMode = SCNActionTimingMode.linear
  33. this._beginTime = 0
  34. this._isRunning = false
  35. this._pausedTime = 0
  36. }
  37.  
  38. /**
  39. * @access public
  40. * @returns {SCNActionFade} -
  41. */
  42. copy() {
  43. const action = super.copy()
  44.  
  45. action._block = this._block
  46.  
  47. return action
  48. }
  49.  
  50. /**
  51. * Creates an action that executes a block.
  52. * @access public
  53. * @param {function(arg1: SCNNode): void} block - The block to run. The block takes a single parameter:nodeThe node on which the action is running.
  54. * @returns {SCNAction} -
  55. * @desc When the action executes, SceneKit calls the block. This action takes place instantaneously.This action is not reversible; the reverse action executes the same block.
  56. * @see https://developer.apple.com/documentation/scenekit/scnaction/1523637-run
  57. */
  58. static run(block) {
  59. const action = new SCNActionRunBlock()
  60. action._block = block
  61. return action
  62. }
  63.  
  64. /**
  65. * apply action to the given node.
  66. * @access private
  67. * @param {Object} obj - target object to apply this action.
  68. * @param {number} time - active time
  69. * @param {boolean} [needTimeConversion = true] -
  70. * @returns {void}
  71. */
  72. _applyAction(obj, time, needTimeConversion = true) {
  73. this._block(obj)
  74. this._finished = true
  75. }
  76. }
  77.  
  78. SCNAction.run = SCNActionRunBlock.run