Skip to content

Commit

Permalink
docs: event gudie
Browse files Browse the repository at this point in the history
  • Loading branch information
lajbel committed Dec 20, 2024
1 parent d9b97c5 commit fe4623c
Show file tree
Hide file tree
Showing 12 changed files with 332 additions and 205 deletions.
11 changes: 1 addition & 10 deletions guides/en/1_getting_started/1_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ url: install

# Installation

This guide covers:

- [create-kaplay](https://npmjs.com/package/create-kaplay) for create KAPLAY
projects easily
- Using KAPLAY with a CDN
- Using KAPLAY with Node.js
- Loading assets
- Running a static file server

The most easy way to get started with KAPLAY is to use the
[CLI tool](https://www.npmjs.com/package/create-kaplay), which will generate a
project for you:
Expand All @@ -27,7 +18,7 @@ $ cd mygame
$ npm run dev
```

This will create your game in the `mygame` directory, and start a development
This will create your game in the `mygame` folder, and start a development
server for you to preview your game. If you edit `src/main.js` and refresh the
page, you will see your changes.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ the entities that move, interact, and make the game interesting.
## Creating Game Objects

We create game objects with the `add()` function. It creates the object and
attach it to the scene.
attach it to the scene. It receives **components** and **tags**.

```js
const player = add([
rect(32, 32),
pos(80, 80),
const dinosaur = add([
// while components gives different behaviours to the game obj
rect(32, 32), // draw a rect
pos(80, 80), // set a position
// tags classify the game object
"dangerous",
"big",
]);
```

We will see in deep components and tags in their respective guides.

## Parents, childs and root

A game object can have child game objects. This will give to the children the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@ import Info from "@/components/Content/Info.astro";

# Components

Components are the building blocks of game objects. They define the behavior of
the object, like how it moves, how it looks, and how it interacts with other
objects.

## What is a Component?

A component is a piece of code that defines a specific behavior of a game
object.
object. It returns a set of **properties** and **methods** that are attached to
the game object.

## Using a component

It returns a set of **properties** and **methods** that are attached to the game
object.
For use components we have to attach them in the `add()` function.

```js
// pos() component gives the object the .pos prop, and .move() method
const player = add([pos(80, 80)]);
const player = add([
// rect(width, height) comp draws a rectangle in the obj
rect(40, 60),
// pos(x, y) comp sets the obj position
pos(10, 10),
]);

player.move(100, 0); // move the player 100 pixels to the right, this is a method
console.log(player.pos); // { x: 180, y: 80 }, this is a property
// method given by pos() comp
player.move(100, 0); // moves the player 100px to the right
// property given by rect() comp
debug.log(player.height); // will log 60
```

There are a lot of useful components in KAPLAY like:
Expand All @@ -36,7 +38,6 @@ There are a lot of useful components in KAPLAY like:
animations
- [`area()`](/doc/ctx/area) to make the object do collision detection, with
methods like [`onCollide()`](/doc/AreaComp#AreaComp-onCollide)
- [`rect()`](/doc/ctx/rect) to make the object draw a simple rectangle shape
- [`text()`](/doc/ctx/text) to make the object draw text
- [`scale()`](/doc/ctx/scale) to make the game object bigger or smaller or to
stretch it
Expand All @@ -45,6 +46,9 @@ You can see all the components in the [API Reference](/doc/ctx/pos).

## Components operations

All components have an _id_, this is the **name** of the component, `sprite()`'s
id is `"sprite"`. This is used in many operations.

### How to add components

```js
Expand All @@ -63,14 +67,14 @@ bean.use(color("#ff00ff")); // green bean <:
### How to remove components

```js
// We pass the component name for remove it.
// We pass the component id for remove it.
bean.unuse("sprite"); // bye bean
```

### How to know if a game object have a component

```js
// We pass the component name:
// We pass the component id:
bean.has("sprite"); // false - true if comp is there, otherwise false
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,27 @@ get all game objects
```js
get("*"); // list of all game objects
```

## Components as tags

In v3001, KAPLAY by default will take component id's as tags:

```js
// this means if your object have a sprite() component, it also have a "sprite" tag
const tga = add([
sprite("tga"),
]);

tga.is("sprite"); // true
```

In next versions this is disabled by default, but if you want to enable it or
disable it in v3001 version, you can use the `tagsAsComponents` option:

```js
kaplay({
tagsAsComponents: false,
});

tga.is("sprite"); // false
```
Loading

0 comments on commit fe4623c

Please sign in to comment.