new Crop()
The Crop component provides the ability to crop a texture based Game Object to a defined rectangle, which can be updated in real-time.
Members
-
cropRect : Phaser.Rectangle
-
The Rectangle used to crop the texture this Game Object uses. Set this property via
crop. If you modify this property directly you must callupdateCropin order to have the change take effect.Type:
Methods
-
crop(rect [, copy])
-
Crop allows you to crop the texture being used to display this Game Object. Setting a crop rectangle modifies the core texture frame. The Game Object width and height properties will be adjusted accordingly.
Cropping takes place from the top-left and can be modified in real-time either by providing an updated rectangle object to this method, or by modifying
cropRectproperty directly and then callingupdateCrop.The rectangle object given to this method can be either a
Phaser.Rectangleor any other object so long as it has publicx,y,width,height,rightandbottomproperties.A reference to the rectangle is stored in
cropRectunless thecopyparameter istrue, in which case the values are duplicated to a local object.Parameters:
Name Type Argument Default Description rectPhaser.Rectangle The Rectangle used during cropping. Pass null or no parameters to clear a previously set crop rectangle.
copyboolean <optional>
false If false
cropRectwill be stored as a reference to the given rect. If true it will copy the rect values into a local Phaser Rectangle object stored in cropRect. -
updateCrop()
-
If you have set a crop rectangle on this Game Object via
cropand since modified thecropRectproperty, or the rectangle it references, then you need to update the crop frame by calling this method.