From 81bdbf8825e8975a4a39dbfb9c526ec02732aad4 Mon Sep 17 00:00:00 2001 From: Yusef Sohail Date: Thu, 25 Feb 2016 23:35:05 -0600 Subject: [PATCH] adding actor documentation --- docs/cruft/core/Actor.md | 57 ++++++++++++++++++++++------------------ tests/Actor.test.js | 10 ++++++- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/docs/cruft/core/Actor.md b/docs/cruft/core/Actor.md index a13f9df..a9f9341 100644 --- a/docs/cruft/core/Actor.md +++ b/docs/cruft/core/Actor.md @@ -1,7 +1,12 @@ -#Actor -[engine/core/Actor.js](https://github.com/mjneil/CruftEngine/blob/master/engine/core/Actor.js) +#Actor extends [Emitter](Emitter.md) +[cruft/core/Actor.js](https://github.com/mjneil/CruftEngine/blob/master/cruft/core/Actor.js) This class defines an Actor. +## Importing +```javascript +import Actor from "cruft/core/Actor" +``` + ## Constructors ### Actor( [ [guid](/primitives.md#number) ] ) @@ -10,7 +15,7 @@ This class defines an Actor. ```javascript let actor = new Actor(); //or -let actor2 = new Actor(12); +let actor2 = new Actor(12); //actor2.guid === 12; ``` @@ -24,57 +29,57 @@ let actor2 = new Actor(12); ##Methods -### addComponent( ) -DESC - +### addComponent( [component](Component.md) ) +Add a component to an actor. ```javascript -//example +actor.addComponent(component); ``` - -### removeComponent( ) -DESC +### getComponent( [type](/primitives.md#string) ) +Get a component of the specified type. ```javascript -//example +var transform = actor.getComponent("transform"); ``` -### getComponent( ) -DESC +### removeComponent( [type](/primitives.md#string) ) +Remove a component of the specified type. ```javascript -//example +actor.removeComponent("transform"); ``` -### addChild( ) -DESC + +### addChild( [child](Actor.md) ) +Add a child to an actor. ```javascript -//example +actor1.addChild(actor2) ``` -### removeChild( ) -DESC +### removeChild( [child](Actor.md) ) +Remove a child from an actor. ```javascript -//example +actor1.removeChild(actor2) ``` -### setParent( ) -DESC +### setParent( [parent](Actor.md) ) +Method used to set actor's parent reference. +**AddChild already takes care of setting a child's parent. ** ```javascript -//example +actor1.setParent(actor2). ``` -### update( ) -DESC +### update( [now](/primitives.md#number) , [deltaMs](/primitives.md#number) ) +Recursive function to update all children Actor/Component 's of an actor. ```javascript -//example +actor.update(now, deltaMs) ``` diff --git a/tests/Actor.test.js b/tests/Actor.test.js index ff2b327..85b15f3 100644 --- a/tests/Actor.test.js +++ b/tests/Actor.test.js @@ -1,16 +1,24 @@ import Actor from 'cruft/core/Actor.js'; describe("Actor", () => { + let actor = null; beforeEach(() => { - actor = new Actor(); + actor = null; }) it('generates a random guid', () => { + actor = new Actor(); expect(actor.guid).toBeTruthy(); }); + it('accepts a passed in guid', () => { + var id = 12; + actor = new Actor(id); + expect(actor.guid).toBe(id); + }); + }) \ No newline at end of file