You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Documentation.md
+17-15Lines changed: 17 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,17 @@
1
1
---
2
-
title: API Documentation
2
+
title: Documentation
3
3
layout: default
4
4
nav_order: 3
5
5
---
6
6
7
7
# API Documentation
8
8
9
-
Cube2D Engine just binds or recreate things from [raylib], [raymath], [Cube2D Framework] so there is no need for docs of my own and as [raylib] says, you can just learn things just by looking at the cheatsheet, but in my personal opinion, switching between cheetsheet and code editor is kinda pain so just include [raylib.h], [raymath], [Cube2D.hpp] in your project and your code editor most likely supports better file switch compared to what you would do if those files were not included.
9
+
Cube2D Engine just binds or recreate things from [raylib], [raymath], [Cube2D Framework], and as [raylib] says, you can just learn things just learn things by looking at their cheetsheet, but in my personal opinion, switching between cheetsheet and code editor is kinda pain so just include [raylib.h], [raymath], [Cube2D.hpp] in your project and your code editor most likely supports better file switch compared to what you would do if those files were not included.
10
+
11
+
Now as for the Engine itself, you just gotta see the tutorials.
10
12
11
13
## How To Use Enums & Defines?
12
-
[raylib] defines the following enums
14
+
The following enums are few of enums defined by [raylib].
13
15
```c
14
16
typedefenum {
15
17
MOUSE_BUTTON_LEFT = 0, // Mouse button left
@@ -55,8 +57,8 @@ You just need to learn keywords, like `Engine` from "Cube2D"
55
57
56
58
## What Cube2D Engine Doesn't Bind?
57
59
58
-
Q: Wait, what? I thought Cube2D Engine binds everything from those files.
59
-
A: Nuh uh, not currently at least.
60
+
-Q: Wait, what? I thought Cube2D Engine binds everything from those files.
61
+
-A: Nuh uh, not currently at least.
60
62
61
63
Cube2D Engine also does not yet bind classes which have members like `float v[3]`, you know, the c style array thing. but they will be bind-ed later.
62
64
@@ -69,11 +71,11 @@ Lets start with the simplest, [Cube2D Framework]
69
71
#### `Scene`
70
72
`Scene` is a `class` for scene management which heavily relies on inheritance but for some reason [wren] doesn't support inheritance from `foreign` classes, `foreign` classes refer to classes bind-ed by the engine in our case.
71
73
72
-
Q: But according to home page's example, we were totally doing inheritance of `Scene`
73
-
A: In order to make it work I had to create equivalent of `Scene``class` in [wren] to support inheritance which is contained in the `Cube2D` module you `import` in your wren file.
74
+
-Q: But according to home page's example, we were totally doing inheritance of `Scene`
75
+
-A: In order to make it work I had to create equivalent of `Scene``class` in [wren] to support inheritance which is contained in the `Cube2D` module you `import` in your wren file.
74
76
75
-
Q: So here will be documentation for equivalent of `Scene``class` ?
76
-
A: Nope, it works exactly the same.
77
+
-Q: So here will be documentation for equivalent of `Scene``class` ?
78
+
-A: Nope, it works exactly the same.
77
79
78
80
#### `Rect`
79
81
@@ -83,8 +85,8 @@ A: Nope, it works exactly the same.
83
85
`Rect` is a `class` for easier rectangular manipulation which you would also like to add inheritance to create stuff like entity, tile, player, enemy, etc. but `Rect` is a little more hard `class` to be recreated in wren, so I created bind-ed `Rect``class` from c++ as `OrignalRect` in wren and created a wrapper `class` in purely in wren which calls `OrignalRect` behind the scenes
84
86
85
87
86
-
Q: So why we were using `.Base` for `Engine.WASDMovement`?
87
-
A: `Engine.WASDMovement` takes `OrignalRect` aka C++ `Rect` to move it but `Rect` in [wren] is a [wren]`class` so it throws a bad cast error so I added a `.Base` getter to get the real deal which you can pass onto `Engine.WASDMovement`.
88
+
-Q: So why we were using `.Base` for `Engine.WASDMovement`?
89
+
-A: `Engine.WASDMovement` takes `OrignalRect` aka C++ `Rect` to move it but `Rect` in [wren] is a [wren]`class` so it throws a bad cast error so I added a `.Base` getter to get the real deal which you can pass onto `Engine.WASDMovement`.
88
90
89
91
#### `Init` & `Close`
90
92
Those two are intentionally not bind-ed as they are handled by the engine.
@@ -93,11 +95,11 @@ Those two are intentionally not bind-ed as they are handled by the engine.
93
95
94
96
The next simplest one is [raymath]
95
97
96
-
Q: How do I use [raymath]'s `PI` and stuff, it doesn't follow the syntax shown in [How To Use Enums & Defines]
97
-
A: `import "raymath" for PI, EPSILON, DEG2RAD, RAD2DEG`
98
+
-Q: How do I use [raymath]'s `PI` and stuff, it doesn't follow the syntax shown in [How To Use Enums & Defines]
99
+
-A: `import "raymath" for PI, EPSILON, DEG2RAD, RAD2DEG`
98
100
99
-
Q: What about `MatrixToFloat` and `Vector3ToFloat`?
100
-
A: Later.
101
+
-Q: What about `MatrixToFloat` and `Vector3ToFloat`?
102
+
-A: Later.
101
103
102
104
#### Things that [raylib] defines
103
105
It would be real dumb to rebind things that [raylib] also defines so `import` those stuff from `raylib` module.
**The above code has been tested with correct paths.**
40
+
41
+
You just need a `var` named `Instance` in your error scene file will engine use to throw error and a special method in your scene named `SetError` with signature `_` i.e `SetError(Error)` where you can save the error for displaying later on using Draw() method and as of course you don't need to call `.Run()` cuz the engine does that when the time is right.
Lets create a simple scene where you can move around player.
11
+
12
+
- Create a folder named "Scenes" in your desired `Scripts` folder (optional)
13
+
- Create a file for your scene with your desired name ( I Prefer SceneExample )
14
+
-`import "Cube2D" for Scene`
15
+
- Create a class as following
16
+
```js
17
+
import"Cube2D" for Scene
18
+
19
+
20
+
classSceneExample is Scene {
21
+
construct new() {
22
+
23
+
}
24
+
}
25
+
```
26
+
As you see we are inheriting Scene from the Cube2D module for our usage. So first of all we need a constructer for our new `SceneExample` class which you can use like `SceneExample.new()` but since we are inheriting `Scene` class we can also call `Scene` classes methods so our class is ready to be used like `SceneExample.new().Run()`.
27
+
28
+
- You probably wanna draw something to screen so lets draw a simple rectangle to screen for example.
29
+
- Add `Draw() {}` method to your class.
30
+
-`import "raylib" for COLOR`
31
+
- also `import``Rect` from `Cube2D`
32
+
```js
33
+
import"Cube2D" for Scene, Rect
34
+
35
+
classSceneExample is Scene {
36
+
construct new() {
37
+
_Player =Rect.new(0, 0, 32, 32) // Create a rectangle at (0, 0) with size (32, 32).
38
+
_Player.Tint=COLOR["RED"] // Add a color to the rectangle.
39
+
}
40
+
Draw() {
41
+
_Player.Draw()
42
+
}
43
+
}
44
+
```
45
+
46
+
- Now You probably also wanna controll that player.
47
+
- also `import``Engine` from `Cube2D`
48
+
- Add `Update() {}` method to your class.
49
+
50
+
```cpp
51
+
import"Cube2D"for Engine, Scene, Rect
52
+
import"raylib"forCOLOR
53
+
54
+
classSceneExample is Scene {
55
+
construct new() {
56
+
57
+
_Player = Rect.new(0, 0, 32, 32)
58
+
_Player.Tint = COLOR["RED"]
59
+
60
+
super()
61
+
}
62
+
Update() {
63
+
64
+
var Speed = 24
65
+
Engine.WASDMovement(_Player.Base, Speed)
66
+
}
67
+
Draw() {
68
+
_Player.Draw()
69
+
}
70
+
}
71
+
```
72
+
73
+
- You can also create a new scene that inherits `SceneExample` or any other scene to call methods from that.
Cube2D Engine, A minimal 2D simple and easy to use game development engine that provides everything you need for game development and utilizes super fast and super simple [wren] as its scripting language.
0 commit comments