Grid cut image
Introduction¶
Grid cut image texture to frames, then create image game objects from these frames.
- Author: Rex
- Methods
Live demos¶
Usage¶
Install plugin¶
Load minify file¶
- Load plugin (minify file) in preload stage
scene.load.plugin('rexgridcutimageplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexgridcutimageplugin.min.js', true); - Create images
var images = scene.plugins.get('rexgridcutimageplugin').gridCut(gameObjects, columns, rows, config);
Import plugin¶
- Install rex plugins from npm
npm i phaser3-rex-plugins - Install plugin in configuration of game
import GridCutImagePlugin from 'phaser3-rex-plugins/plugins/gridcutimage-plugin.js'; var config = { // ... plugins: { global: [{ key: 'rexGridCutImage', plugin: GridCutImagePlugin, start: true }, // ... ] } // ... }; var game = new Phaser.Game(config); - Create images
var images = scene.plugins.get('rexGridCutImage').gridCut(gameObjects, columns, rows, config);
Import method¶
- Install rex plugins from npm
npm i phaser3-rex-plugins - Import method
import GridCutImage from 'phaser3-rex-plugins/plugins/gridcutimage.js'; - Create images
var images = GridCutImage(gameObjects, columns, rows, config);
Grid cut¶
var cellImages = scene.plugins.get('rexGridCutImage').gridCut(gameObjects, columns, rows, {
// createImageCallback: undefined,
// ImageClass: Phaser.GameObjects.Image,
// originX: 0.5,
// originY: 0.5,
// add: true,
// align: true,
// objectPool: undefined
})
gameObjects: Target game object which has a texture, ex Image, RenderTexture.columns,rows: Cut texture incolumnsxrowsgridscreateImageCallback: Custom callback to return an image game object, optional.function(scene, texture, frame) { return gameObject; }texture: A texture object.frame: Frame name.
ImageClass: Create image game object from this class. Default value is built-in Image class. Used whencreateImageCallbackisundefined.originX,originY: Origin of created image game objectsadd:true: Add these created image game objects to scene. Default value.false: Don't add created image game objects to scene.
align:true: Align position of created image game objects to target game object (gameObjects). Default value whenaddis set totrue.false: Don't set position of created image game objects. Default value whenaddis set tofalse.
objectPool: An array of image game objects, will reuse image game objects from this pool. Optional.cellImages: Return image game objects.