An open API service indexing awesome lists of open source software.

https://github.com/phasereditor2d/phasereditor2d-roundedrectangle-plugin

A Phaser Editor 2D plugin with support for the RoundedRectangle game object.
https://github.com/phasereditor2d/phasereditor2d-roundedrectangle-plugin

Last synced: 11 months ago
JSON representation

A Phaser Editor 2D plugin with support for the RoundedRectangle game object.

Awesome Lists containing this project

README

          

# Phaser Editor 2D v3 - RoundedRectangle plugin

This repository contains RoundedRectangle plugin for Phaser Editor 2D v3.

*This RoundedRectangle implementation is based on a `Phaser.GameObjects.RenderTexture` and has a poor performance. For a better implementation, check the [phasereditor2d-roundedRectangleGraphics-plugin](https://github.com/PhaserEditor2D/phasereditor2d-roundedrectanglegraphics-plugin).*

## Install

The plugin is distributed as a NodeJS package:

```bash
$ npm i --save-dev phasereditor2d-roundedrectangle-plugin
```

It is important that you install the package as a development dependency (`--save-dev`), because Phaser Editor 2D only searches for plugins in that section. Also, the `package.json` file should be in the root of the project.

## Creating a RoundedRectangle object

For creating a RoundedRectangle object, you can drag the **RoundedRectangle** type from the **Built-In** section of the **Blocks** view and drop it in the scene.

By default, it shows a white rectangle:

![Create object](images/create-roundedRectangle.png)

## RoundedRectangle parameters

A RoundedRectangle object is similar to the Rectangle game object. It has size, background, stroke, in addition to specific properties, like radius, and shadow.

The shadow is part of the bound of the object, it means, if you increase the shadow offset, the background of the object decreases.

![RoundedRectangle properties](images/properties.png)

There are other properties common to the RenderTexture object, like those in the sections Transform, Origin, Visible, etc...

## Size manipulators

You can resize the RoundedRectangle object with the **Size Tool**. Press the `Z` key or select this tool in the context menu **Tools** > **Resize Tool**.

![Resize tool](images/size-tool.png)

## Code generation

The RoundedRectangle object is not available in the Phaser built-in API. Phaser Editor 2D uses an internal implementation of this object, and provides the source code of a RoundedRectangle game object that you can use in your project.

To get the source code of the RoundedRectangle game object, execute the command **Create Rounded Rectangle User Files**:

![Create rounded rectangle files command](images/create-files-commands.png)

You can open the Command Palette in the main menu or by pressing the `Ctrl+K` keys.

Look you there are four different commands:

* For creating JavaScript files as ES modules.
* For creating simple JavaScript files.
* For creating TypeScript files as ES modules.
* For creating simple TypeScript files.

These commands create a series of files with the source code of the RoundedRectangle object. The files are copied in the folder selected in the **Files** view.

![Rounded rectangle user files](images/api-files.png)

The files are following:

### `RoundedRectangle.ts`

Contains the implementation of the RoundedRectangle game object.

You can create a new instance like this:

```javascript
const obj = new RoundedRectangle(scene, 10, 10, 100, 100);
scene.add.existing(obj);
```

### `registerRoundedRectangleFactory.ts`

Contains the `registerRoundedRectangleFactory()` function.

You should use it for registering a `GameObjectFactory` method. It allows you creating new RoundedRectangle objects like this:

```javascript
const obj = this.add.roundedRectangle(10, 10, 100, 100);
```
Before, you need to register the factory:

```javascript

const game = new Phaser.Game(...);
...
registerRoundedRectangleFactory();
...
```

### `roundedRectangle.d.ts`

Contains the TypeScript definitions. Maybe you should move it to the `types` folder of your project. Or you should configure the `tsconfig.json` file finding the definitions.

### Code customization

You are free to change the code of the generated RoundedRectangle files, however, take in consideration that the scene's code generated by the editor uses always the same public interface of the RoundedRectangle object.