Class: Object2D

Grape2D. Object2D

new Object2D()

Object2D represents an object of the scene. An Object2D is a simple scene object which the main purpose is to render a texture at a position. More complex behaviors should be implemented by others objects that inherit from Object2D.
Parameters:
Name Type Argument Description
options.position Grape2D.Vector <optional>
The position of the shape
options.visible boolean <optional>
True to render the object, false otherwise.
options.texture Grape2D.Texture The texture of the object.
options.textureOffset Grape2D.Vector <optional>
The offset position of the texture relative to the objects position.
options.boundingBox Grape2D.Shape The primary use of the bounding box is to select the items to display in the renderer, other behaviors such as collision detection can be done with this property, in some simple cases. So the bounding box should bounded tightly to what's supposed to be seen.
options.boundingBoxOffset Grape2D.Vector <optional>
The offset position of the bounding box relative to the objects position.
options.castShadow boolean <optional>
Used by the IlluminatedRenderer to render this object shadow.
options.receiveLight boolean <optional>
Used by the IlluminatedRenderer to render the objects texture with a light overlay, if set to true.
Source:

Members

<private> boundingBox :Grape2D.Shape

Object's bounding box.
Type:
Source:

<private> boundingBoxOffset :Grape2D.Vector

Bounding box offset.
Type:
Source:

<private> castShadow :boolean

Object cast shadow.
Type:
  • boolean
Source:

<private> position :Grape2D.Vector

Object's position.
Type:
Source:

<private> receiveLight :boolean

Object can receive light.
Type:
  • boolean
Source:

<private> texture :Grape2D.Texture

The texture of the object.
Type:
Source:

<private> textureOffset :Grape2D.Vector

The offset of the texture.
Type:
Source:

<private> texturePosition :Grape2D.Vector

The position of the texture. It is computed from the object's position and the texture offset.
Type:
Source:

<private> visible :boolean

Visible property.
Type:
  • boolean
Source:

Methods

canCastShadow() → {boolean}

Checks if the object can cast shadows.
Source:
Returns:
True if it cast shadows, false otherwise.
Type
boolean

canReceiveLight() → {boolean}

Checks if an object can receive light.
Source:
Returns:
True if it receives light.
Type
boolean

<protected> computeBoundingBoxPosition()

Computes the bounding box position, from the object's position and bounding box offset.
Source:

<protected> computeTexturePosition()

Computes the texture position of the object, from the object's position and texture offset.
Source:

getBoundingBox() → {Grape2D.Shape}

Gets the bounding box of the object.
Source:
Returns:
The shape of the object.
Type
Grape2D.Shape

getBoundingBoxOffset() → {Grape2D.Vector}

Gets the bounding box offset
Source:
Returns:
The bounding box offset.
Type
Grape2D.Vector

getBoundingBoxPosition() → {Grape2D.Vector}

Gets the bounding box position.
Source:
Returns:
The center position of the bounding box.
Type
Grape2D.Vector

getPosition() → {Grape2D.Vector}

Gets the object position. Be careful, because it returns the vector used by the object, and not a copy. Use it wisely.
Source:
Returns:
The position of the object.
Type
Grape2D.Vector

getTexture() → {Grape2D.Texture}

Gets the texture of the object.
Source:
Returns:
The texture of the object.
Type
Grape2D.Texture

getTextureOffset() → {Grape2D.Vector}

Gets the texture offset
Source:
Returns:
The texture offset.
Type
Grape2D.Vector

getTexturePosition() → {Grape2D.Vector}

Gets the texture position.
Source:
Returns:
The position of the texture
Type
Grape2D.Vector

isVisible() → {boolean}

Checks if the object should be rendered.
Source:
Returns:
True if it can be rendered.
Type
boolean

process(processor)

Processes this object thought a processor. Same as a visitor pattern.
Parameters:
Name Type Description
processor Grape2D.Object2DProcessor A processor.
Source:

render(renderer, camera)

Renders the object to a renderer.
Parameters:
Name Type Description
renderer Grape2D.Renderer The place to render the object.
camera Grape2D.Camera The camera, that will transform the positions.
Source:

setBoundingBox(boundingBox)

Sets the bounding box of the object. Also, the position of the new bounding box, will be transformed in the default offset of the bounding box.
Parameters:
Name Type Description
boundingBox Grape2D.Shape The bounding box.
Source:

setBoundingBoxOffset(offset)

Sets the bounding box offset.
Parameters:
Name Type Description
offset Grape2D.Vector The offset of the bounding box, from the object's position.
Source:

setCastShadow(castShadow)

Sets if an object can cast shadows.
Parameters:
Name Type Description
castShadow boolean True to cast shadows, false otherwise.
Source:

setPosition(position)

Sets the object position.
Parameters:
Name Type Description
position Grape2D.Vector The position of the object.
Source:

setReceiveLight(receiveLight)

Sets if the object can receive light.
Parameters:
Name Type Description
receiveLight boolean True if it receives light.
Source:

setTexture(texture)

Sets the texture of the object.
Parameters:
Name Type Description
texture Grape2D.Texture The texture.
Source:

setTextureOffset(offset)

Sets the texture offset.
Parameters:
Name Type Description
offset Grape2D.Vector The offset of the texture, from the object's position.
Source:

setVisible(visible)

Sets if an object should be rendered.
Parameters:
Name Type Description
visible boolean True, so that it renders, false otherwise.
Source:

update(dt, scene)

Updates the object. This method should be refined in further subclasses if needed be.
Parameters:
Name Type Description
dt number Time interval.
scene Grape2D.Scene Scene where this object is.
Source: