API Docs for: 1.4.0
Show:

Kiwi.Files.TextureFile Class

Extends Kiwi.Files.File
Module: Files
Parent Module: Kiwi

Available since 1.2.0

TextureFile which contains settings, loading, and processing information for textures/images in Kiwi.

Contains two methods of loading. XHR + arraybuffer and also tag loading.

Constructor

Kiwi.Files.TextureFile

(
  • game
  • params
)
Kiwi.Files.TextureFile

Defined in src\file\TextureFile.ts:10

Available since 1.2.0

Parameters:

  • game Kiwi.Game

    The game that this file is for

  • params Object

    Options for this file.

    • key String

      User defined name for this file. This would be how the user would access it in the file store.

    • url String

      Location of the file to be loaded.

    • [metadata={}] Object optional

      Any metadata to be associated with the file.

    • [state=null] Kiwi.State optional

      The state that this file belongs to. Used for defining global assets vs local assets.

    • [fileStore=null] Kiwi.Files.FileStore optional

      The filestore that this file should be save in automatically when loaded.

    • [type=UNKNOWN] Number optional

      The type of file this is.

    • [tags] Array optional

      Any tags to be associated with this file.

    • [xhrLoading=false] Boolean optional

      If xhr + arraybuffer loading should be used instead of tag loading.

Methods

_assignFileDetails

(
  • url
)
private

Inherited from Kiwi.Files.File: src\file\File.ts:131

Available since 1.2.0

Gets the file details from the URL passed. Name, extension, and path are extracted.

Parameters:

  • url String

_getXhrHeaderInfo

() private

Inherited from Kiwi.Files.File: src\file\File.ts:871

Available since 1.2.0

Retrieves the HEAD information from the XHR. This method is used for both 'load' and 'loadDetails' methods.

_load

() protected

Inherited from Kiwi.Files.File but overwritten in src\file\TextureFile.ts:73

Initialises the loading method. Tagloading is the default but also supports XHR + arraybuffer.

_parseParamsOld

(
  • dataType
  • path
  • [name='']
  • [saveToFileStore=true]
  • [storeAsGlobal=true]
)
private

Inherited from Kiwi.Files.File: src\file\File.ts:60

Available since 1.2.0

Assigns properties and variables for the constructor as in pre 1.2 Kiwi versions.

Parameters:

  • dataType Number

    The type of file that is being loaded. For this you can use the STATIC properties that are located on this class for quick code completion.

  • path String

    The location of the file that is to be loaded.

  • [name=''] String optional

    A name for the file. If no name is specified then the files name will be used.

  • [saveToFileStore=true] Boolean optional

    If the file should be saved on the file store or not.

  • [storeAsGlobal=true] Boolean optional

    If this file should be stored as a global file, or if it should be destroyed when this state gets switched out.

_start

() private

Is executed when this file starts loading. Gets the time and resets properties used in file loading.

_stop

() private

Is executed when this file stops loading.

addTag

(
  • tag
)
public

Adds a new tag to this file.

Parameters:

  • tag String

    The tag that you would like to add

destroy

() public

Inherited from Kiwi.Files.File but overwritten in src\file\TextureFile.ts:154

Available since 1.2.0

Destroys all external object references on this object.

getFileDetails

(
  • [callback=null]
  • [maxLoadAttempts=1]
  • [timeout=this.timeOutDelay]
)
deprecated private

Inherited from Kiwi.Files.File: src\file\File.ts:1407

Deprecated: Use 'loadDetails' instead. Deprecated as of 1.2.0

Attempts to make the file send a XHR HEAD request to get information about the file that is going to be downloaded. This is particularly useful when you are wanting to check how large a file is before loading all of the content.

Parameters:

  • [callback=null] Any optional

    The callback to send this FileInfo object to.

  • [maxLoadAttempts=1] Number optional

    The maximum amount of load attempts. Only set this if it is different from the default.

  • [timeout=this.timeOutDelay] Number optional

    The timeout delay. By default this is the same as the timeout delay property set on this file.

hasTag

(
  • tag
)
Boolean public

Checks to see if a tag that is passed exists on this file. Returns a boolean that is used as a indication of the results. True means that the tag exists on this file.

Parameters:

  • tag String

    The tag you are checking to see exists.

Returns:

Boolean:

If the tag does exist on this file or not.

load

() public

Starts the loading process for this file. Passing parameters to this method has been deprecated and only exists for backwards compatibility.

loadDetails

(
  • [callback]
  • [context]
)
Boolean public

Inherited from Kiwi.Files.File: src\file\File.ts:845

Available since 1.2.0

Makes a XHR HEAD request to get information about the file that is going to be downloaded. This is particularly useful when you are wanting to check how large a file is before loading all of the content.

Parameters:

  • [callback] Any optional
  • [context] Any optional

Returns:

Boolean:

If the request was made

loadError

(
  • error
)
protected

Inherited from Kiwi.Files.File: src\file\File.ts:512

Available since 1.2.0

Executed when the loading process fails. This could be for any reason

Parameters:

  • error Any

    The event / reason for the file to not be loaded.

loadProgress

() protected

Inherited from Kiwi.Files.File: src\file\File.ts:475

Available since 1.2.0

Should be called by the loading method. Dispatches the 'onProgress' callback.

loadSuccess

() protected

Inherited from Kiwi.Files.File: src\file\File.ts:486

Available since 1.2.0

Called by the loading methods when the file has been loaded and successfully processed. Dispatches the 'onComplete' callback and sets the appropriate properties.

objType

() String public

Inherited from Kiwi.Files.File but overwritten in src\file\TextureFile.ts:52

Returns the type of this object

Returns:

String:

"TextureFile"

parseParams

(
  • [params]
)
protected

Inherited from Kiwi.Files.File: src\file\File.ts:89

Available since 1.2.0

Sets properties for this instance based on an object literal passed. Used when the class is being created.

Parameters:

  • [params] Object optional
    • [metadata] optional

      {Object} Any metadata to be associated with the file.

    • [state=null] Kiwi.State optional

      The state that this file belongs to. Used for defining global assets vs local assets.

    • [fileStore=null] Kiwi.Files.FileStore optional

      The filestore that this file should be save in automatically when loaded.

    • [type=UNKNOWN] Number optional

      The type of file this is.

    • [tags] Array optional

      Any tags to be associated with this file.

    • [timeout=TIMEOUT_DELAY] Number optional

      Sets the timeout delay when loading via ajax.

processXhr

(
  • response
)
protected

Inherited from Kiwi.Files.File but overwritten in src\file\TextureFile.ts:110

Gets the response data (which is an arraybuffer), creates a Blob from it and creates an objectURL from it.

Parameters:

  • response Any

    The data stored in the 'xhr.response' tag

removeTag

(
  • tag
)
public

Removes a tag from this file.

Parameters:

  • tag String

    The tag that is to be removed.

revoke

() private

Revokes the object url that was added to the window when creating the image. Also tells the File that the loading is now complete.

tagLoader

() private

Contains the functionality for tag loading

xhrHeadOnError

(
  • event
)
private

Executed when a xhr head request fails

Parameters:

  • event Any

xhrHeadOnLoad

(
  • event
)
private

Executed when a XHR head request has loaded. Checks that the status of the request is 200 before classifying it as a success.

Parameters:

  • event Any

xhrHeadRequest

() private

Inherited from Kiwi.Files.File: src\file\File.ts:896

Available since 1.2.0

Sets up a XMLHttpRequest object and sends a HEAD request.

xhrLoader

(
  • [method="GET"]
  • [responseType="text"]
  • [timeoutDelay]
)
protected

Sets up a XHR loader based on the properties of this file and parameters passed.

Parameters:

  • [method="GET"] String optional

    The method this request should be made in.

  • [responseType="text"] String optional

    The type of response we are expecting.

  • [timeoutDelay] Number optional

xhrOnLoad

(
  • event
)
protected

Fired when the file has been loaded. Checks that the response contains information before marking it as a success.

Parameters:

  • event Any

xhrOnProgress

(
  • event
)
protected

Progress event fired whilst the file is loading via XHR.

Parameters:

  • event Any

Properties

_loadInParallel

Boolean private

Inherited from Kiwi.Files.File: src\file\File.ts:185

Available since 1.2.0

Indicates if this file can be loaded in parallel to other files. This is usually only used files are using the tag loaders and not XHR.

Default: false

_tags

String private

Any tags that are on this file. This can be used to grab files/objects on the whole game that have these particular tag.

Default: []

_xhr

XMLHttpRequest protected

The XMLHttpRequest object. This only has a value if the xhr method of load is being used, otherwise this is null.

attemptCounter

Number protected

The number of attempts at loading there have currently been at loading the file. This is only used with XHR methods of loading.

buffer

Any deprecated public

Inherited from Kiwi.Files.File: src\file\File.ts:1397

Deprecated: Use 'data' instead. Deprecated as of 1.2.0

The response that is given by the XHR loader when loading is complete.

bytesLoaded

Number public

The number of bytes that have currently been loaded. Useful when wanting to know exactly how much data has been transferred. Only has a value when using the XHR method of loading.

Default: 0

bytesTotal

Number public

The total number of bytes that the file consists off. Only has a value when using the XHR method of loading or you are getting the file details before hand.

Default: 0

complete

Boolean public

Indicates if the file has attempted to load. This is regardless of whether it was a success or not.

Default: false

crossOrigin

String public

For tag loading only. The crossOrigin value applied to loaded images. Very often this needs to be set to 'anonymous'

Default: ''

data

Any public

Inherited from Kiwi.Files.File but overwritten in src\file\File.ts:242

A dictionary, stores any information relating to this file. Used when loading images that are to be used as a spritesheet or texture atlas.

dataType

String public

Holds the type of data that is being loaded. This should be used with the STATIC properties that hold the various datatypes that can be loaded.

detailsReceived

Boolean public

Inherited from Kiwi.Files.File: src\file\File.ts:835

Available since 1.2.0

An indication of whether this files information has been retrieved or not.

Default: false

duration

Number public

The duration or how long it took to load the file. In milliseconds.

Default: 0

error

Any public

Holds the error (if there was one) when loading the file.

ETag

String public

The Entity Tag that is assigned to the file. O Only has a value when either using the XHR loader OR when requesting the file details.

extension

String public

Inherited from Kiwi.Files.File: src\file\File.ts:289

Available since 1.2.0

The extension of the file that is being loaded. This is based upon what the file path that the developer specifies.

fileName

String deprecated public

Inherited from Kiwi.Files.File: src\file\File.ts:1233

Deprecated: Use `name`. Deprecated as of 1.2.0

The name of the file being loaded.

filePath

String deprecated public

Inherited from Kiwi.Files.File but overwritten in src\file\File.ts:1247

Deprecated: Use `path`. Deprecated as of 1.2.0

The location of where the file is placed without the file itself (So without the files name). Example: If the file you are load is located at 'images/awesomeImage.png' then the filepath will be 'images/'

fileSize

Number deprecated public

Inherited from Kiwi.Files.File: src\file\File.ts:1307

Deprecated: Use `size`. Deprecated as of 1.2.0

The size of the file that was/is being loaded. Only has a value when the file was loaded by the XHR method OR you request the file information before hand using 'getFileDetails'.

fileStore

Kiwi.Files.FileStore public

Inherited from Kiwi.Files.File: src\file\File.ts:212

Available since 1.2.0

The filestore this file should be added to when it has loaded. This can be replaced with a custom one if wanted.

fileType

String deprecated public

Inherited from Kiwi.Files.File: src\file\File.ts:1291

Deprecated: Use `type`. Deprecated as of 1.2.0

The type of file that is being loaded. Is only ever given a value when used with the XHR method of loading OR if you use 'getFileDetails' before hand. The value is based off of the 'Content-Type' of the XHR's response header returns.

fileURL

String deprecated public

Inherited from Kiwi.Files.File: src\file\File.ts:1277

Deprecated: Use `URL`. Deprecated as of 1.2.0

The full filepath including the file itself.

game

Kiwi.Game public

Inherited from Kiwi.Files.File: src\file\File.ts:169

Available since 1.2.0

The game that this file belongs to.

hasError

Boolean public

If file loading failed or encountered an error and so was not laoded

Default: false

hasTimedOut

Boolean deprecated public

Inherited from Kiwi.Files.File: src\file\File.ts:1377

Deprecated: Deprecated as of 1.2.0

If this file has timeout when it was loading.

Default: false

headCompleteCallback

Any private

Inherited from Kiwi.Files.File: src\file\File.ts:814

Available since 1.2.0

The callback method to be executed when the file details have been retrieved.

headCompleteContext

Any private

Inherited from Kiwi.Files.File: src\file\File.ts:823

Available since 1.2.0

The context the 'headCompleteCallback' should be executed in.. The callback is the following arguments.

  1. If the details were recieved

isAudio

Boolean public

An indication of if this file is a piece of audio. This is READ ONLY.

isData

Boolean public

An indication of if this file is data. This is READ ONLY.

isTexture

Boolean public

An indication of if this file is texture. This is READ ONLY.

key

String public

The 'key' is the user defined name and the users way of accessing this file once loaded.

lastModified

String public

The last date/time that this file was last modified. Only has a value when using the XHR method of loading OR when requesting the file details.

Default: ''

lastProgress

Number public

The time at which progress in loading the file was last occurred. Only contains a value when using XHR methods of loading.

loading

Boolean public

Indication if the file is currently being loaded or not.

loadInParallel

Boolean private

Inherited from Kiwi.Files.File: src\file\File.ts:197

Available since 1.2.0

READ ONLY: Indicates if this file can be loaded in parallel to other files. This is usually only used files are using the tag loaders and not XHR.

Default: false

maxLoadAttempts

Number public

The maximum attempts at loading the file that there is allowed.

Default: 2

name

String public

Inherited from Kiwi.Files.File: src\file\File.ts:268

Available since 1.2.0

The name of the file being loaded.

onComplete

Kiwi.Signal public

Inherited from Kiwi.Files.File: src\file\File.ts:339

Available since 1.2.0

Signal which dispatches events when the file has successfully loaded.

onCompleteCallback

Any deprecated public

Inherited from Kiwi.Files.File: src\file\File.ts:1323

Deprecated: Use `onComplete`. Deprecated as of 1.2.0

A method that is to be executed when this file has finished loading.

Default: null

onProgress

Kiwi.Signal public

Inherited from Kiwi.Files.File: src\file\File.ts:349

Available since 1.2.0

Signal which dispatches events when the file is loading. Not guarenteed to dispatch events as it depends on the method of loading being performed

onProgressCallback

Any deprecated public

Inherited from Kiwi.Files.File: src\file\File.ts:1334

Deprecated: Use `onProgress`. Deprecated as of 1.2.0

A method that is to be executed while this file is loading.

Default: null

ownerState

Kiwi.State public

The state that added the entity - or null if it was added as global

path

String public

Inherited from Kiwi.Files.File: src\file\File.ts:278

Available since 1.2.0

The location of where the file is placed without the file itself (So without the files name). Example: If the file you are load is located at 'images/awesomeImage.png' then the filepath will be 'images/'

percentLoaded

Number public

The amount of percent loaded the file is. This is out of 100.

readyState

Number deprecated public

Inherited from Kiwi.Files.File: src\file\File.ts:1367

Deprecated: Deprecated as of 1.2.0

The ready state of the XHR loader whilst loading.

Default: 0

size

Number public

Inherited from Kiwi.Files.File: src\file\File.ts:321

Available since 1.2.0

The size of the file that was/is being loaded. Only has a value when the file was loaded by the XHR method OR you request the file information beforehand using 'loadDetails'.

Default: 0

status

Number deprecated public

Inherited from Kiwi.Files.File: src\file\File.ts:1345

Deprecated: Deprecated as of 1.2.0

The status of this file that is being loaded. Only used/has a value when the file was/is being loaded by the XHR method.

Default: 0

statusText

String deprecated public

Inherited from Kiwi.Files.File: src\file\File.ts:1357

Deprecated: Deprecated as of 1.2.0

The status piece of text that the XHR returns.

Default: ''

success

Boolean public

If loading was successful or not.

timedOut

Number deprecated public

Inherited from Kiwi.Files.File: src\file\File.ts:1387

Deprecated: Deprecated as of 1.2.0

If the file timed out or not.

Default: 0

timeFinished

Number public

The time at which the load finished.

Default: 0

timeOutDelay

Number public

The number of milliseconds that the XHR should wait before timing out. Set this to NULL if you want it to not timeout.

Default changed in v1.3.1 to null

Default: null

timeStarted

Number public

The time at which the loading started.

Default: 0

type

String public

The type of file that is being loaded. Is only ever given a value when used with the XHR method of loading OR if you use 'loadDetails' before hand. The value is based off of the 'Content-Type' of the XHR's response header returns.

URL

String public

Inherited from Kiwi.Files.File: src\file\File.ts:300

Available since 1.2.0

The full filepath including the file itself.

useTagLoader

Boolean protected

Inherited from Kiwi.Files.File: src\file\File.ts:223

Available since 1.2.0

If this file is using tag loading instead of the XHR method. Only used by extended classes