Skip to content

Commit fdc1a81

Browse files
author
Builder
committed
Merge branch 'adding-gif-examples' into 'master'
[FEAT][SDK-DOC]Adding gif examples See merge request codingame/game-engine!165
2 parents 16311eb + bb2a1e8 commit fdc1a81

12 files changed

+52
-12
lines changed

playground/graphics/graphics-2-entities.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ Every sprite, shape, text, etc are entities displayable in the viewer. They impl
1717
Circle circle = graphicEntityModule.createCircle()
1818
.setRadius(50)
1919
.setLineWidth(0)
20-
.setFillColor(0x00FF00);
20+
.setFillColor(0x00FF00)
21+
.setX(70)
22+
.setY(70);
2123
```
2224
## Moving a circle
2325
```java
@@ -29,21 +31,34 @@ circle
2931
### With a Curve
3032
```java
3133
circle
32-
.setX(player.getX(), Curve.LINEAR)
33-
.setY(player.getY(), Curve.LINEAR);
34+
.setX(player.getX(), Curve.EASE_IN_AND_OUT)
35+
.setY(player.getY(), Curve.EASE_IN_AND_OUT);
3436
```
37+
By default the `Curve.LINEAR` is used.
38+
39+
It should look like this :
40+
![Example](resources/circles.gif)
41+
The first circle is not animated,
42+
the second is animated with the default curve
43+
and the last one is animated with the custom curve.
44+
3545
## Creating a group of sprites <a name="creating-a-group-of-sprites"></a>
3646
```java
3747
Sprite planet1 = graphicEntityModule.createSprite()
38-
.setImage("planet")
48+
.setImage("planet0.png")
49+
.setAnchorX(0.5)
50+
.setAnchorY(0.5)
3951
.setX(-20);
4052
Sprite planet2 = graphicEntityModule.createSprite()
41-
.setImage("planet")
42-
.setX(30);
53+
.setImage("planet1.png")
54+
.setAnchorX(0.5)
55+
.setAnchorY(0.5)
56+
.setX(30)
4357
.setY(-10);
4458
Sprite planet3 = graphicEntityModule.createSprite()
45-
.setImage("planet")
46-
.setY(20);
59+
.setImage("planet2.png")
60+
.setAnchorX(0.5)
61+
.setAnchorY(0.5);
4762

4863
// The planets are around the point (960,540).
4964
Group system = graphicEntityModule.createGroup(planet1, planet2, planet3)
@@ -58,4 +73,6 @@ Group system = graphicEntityModule.createGroup(planet1, planet2, planet3)
5873
planet3.setRotation(planet3.getRotation() + Math.PI / 16);
5974

6075
system.setRotation(system.getRotation() + Math.PI / 2);
61-
```
76+
```
77+
It should look like this :
78+
![Example](resources/planets.gif)

playground/graphics/graphics-3-states.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ graphicEntityModule.commitEntityState(0.9, circle);
3939
circle.setRadius(50);
4040
graphicEntityModule.commitEntityState(1, circle);
4141
```
42+
It should look like this :
43+
![Example](resources/frames.gif)
4244

4345
## Animating several entities
4446

playground/graphics/graphics-4-spritesheets.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,24 @@ String[] seaweedSprites = graphicEntityModule.createSpriteSheetSplitter()
2626
.setImagesPerRow(4)
2727
.setName("seaweed")
2828
.split();
29+
30+
//Creating an animation from the splitted spritesheet
31+
graphicEntityModule.createSpriteAnimation()
32+
.setImages(seaweedSprites)
33+
.setX(50)
34+
.setY(50)
35+
.setLoop(true);
36+
37+
//Or a sprite from the 1st image of the spritesheet
38+
graphicEntityModule.createSprite()
39+
.setImage(seaweedSprites[0])
40+
.setX(250)
41+
.setY(250);
2942
```
3043

31-
We can now use these images in Sprite entites as shown [here](graphics-2-entities.md#creating-a-group-of-sprites).
44+
It should look like this :
45+
![Example](resources/spritesheet.gif)
46+
3247

3348
## Using JSON sprites resources as assets
3449

playground/graphics/graphics-5-animations.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ graphicEntityModule.createSpriteAnimation()
99
.setImages(heroSprites)
1010
.setX(hero.getX())
1111
.setY(hero.getY())
12-
.setDuration(2000)
12+
.setDuration(100)
1313
.setLoop(true)
1414
.setPlaying(true);
1515
```
16+
It should look like this :
17+
![Example](resources/hero.gif)
18+
1619
- `setImages(heroSprites)`: set a `String` array containing the filenames of the sprites.
1720
- `setX(hero.getX())`, `setY(hero.getY())`: set the position.
1821
- `setDuration(2000)`: set how long the whole animation takes to be played (in milliseconds).

playground/graphics/graphics-text.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ graphicEntityModule.createText("Hello World")
1414
.setFontSize(50)
1515
.setFillColor(0x000000); // Setting the text color to black
1616
```
17+
![Example](resources/text1.png)
18+
1719
The only font family values that will work are:
1820
"Lato" and those that are available by default on all browsers.
1921
If the browser does not recognise the font family, it will be displayed in a fallback font chosen by the browser.
@@ -25,11 +27,12 @@ This class is used to display text using a bitmap font in your assets folder.
2527
```java
2628
graphicEntityModule.createBitmapText()
2729
.setText("Hello World")
28-
.setFontFamily("myCustomFont")
30+
.setFont("myCustomFont")
2931
// Assuming that you have a working 'myCustomFont.fnt' and 'myCustomFont.png' in your assets folder
3032
.setFontSize(50)
3133
.setTint(0xff0000); // Tinting it in red
3234
```
35+
![Example](resources/text-2.png)
3336

3437
Extra tips :
3538
- A little help to turn fonts into bitmap fonts : http://kvazars.com/littera/
24.8 KB
Loading
6.16 KB
Loading
83.3 KB
Loading
458 KB
Loading
35.1 KB
Loading
2.92 KB
Loading
4.51 KB
Loading

0 commit comments

Comments
 (0)