-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add reference in documentation + some cleaning
- Loading branch information
1 parent
1fac12c
commit 60535dc
Showing
19 changed files
with
1,056 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Groups | ||
|
||
Groups are set of many graphics put together in order to move them or display/hide them all at the same moment. | ||
|
||
We'll use the ``cazan.graphics`` namespace here. | ||
|
||
## Demonstration | ||
|
||
````js | ||
let head = new Rectangle({ | ||
game: game, | ||
position: {x: 0, y: 0}, | ||
dimensions: {width: 50, height: 50}, | ||
styles: {graphic: {color: "rgba(255,165,0,1)", type: "fill"}}, | ||
toDisplay: false //(1)! | ||
}) | ||
|
||
let body = new Rectangle({ | ||
game: game, | ||
position: {x: 0, y: 50}, | ||
dimensions: {width: 50, height: 100}, | ||
styles: {graphic: {color: "rgba(0,0,0,1)",type: "fill"}}, | ||
toDisplay: false | ||
}) | ||
|
||
let man = new Group( | ||
"man", | ||
{x: 100, y: 100}, //(2)! | ||
{ | ||
"head": head, //(3)! | ||
"body": body | ||
} | ||
) | ||
|
||
man.show() //(4)! | ||
```` | ||
|
||
1. You don't need to show them immediately after their creation (otherwise they will be displayed in order of the canvas origin) | ||
2. This is the position of the group. It will be the origin of all graphics that belong to this group. | ||
3. Here put the graphics and name them. | ||
4. Don't forget to display the shapes after the initialisation! And you can use the Group properties already! | ||
|
||
This will create a kind of man (that have an orange head and a black suit). | ||
|
||
And there's how we can move the little man: | ||
````js | ||
man.setPosition({x: man.getPosition().x + 25}) | ||
```` | ||
|
||
## Reference | ||
|
||
````ts | ||
class Group { | ||
protected graphicsRelativesPositions: Record<string, Position> = {} | ||
|
||
constructor( | ||
protected name: string, | ||
protected position: Position, | ||
protected graphics: Record<string, Graphic> | ||
) {} | ||
|
||
show(): void {} | ||
|
||
hide(): void {} | ||
|
||
setPosition(newPosition: {x?: number, y?: number}): void {} | ||
|
||
getPosition(): Position {} | ||
|
||
setGraphicRelativePositions(graphicName: string, newPosition: Position): void {} | ||
|
||
getGraphicsRelativePositions(): Record<string, Position> {} | ||
|
||
setName(name: string): void {} | ||
|
||
getName(): string {} | ||
|
||
setGraphics(graphics: Record<string, Graphic>): void {} | ||
|
||
addGraphic(newGraphic: {name: string, graphic: Graphic}): void {} | ||
|
||
removeGraphic(graphicName: string): void {} | ||
|
||
getGraphics(): Record<string, Graphic> {} | ||
|
||
getGraphic(name: string): Graphic {} | ||
|
||
private _registerRelativesPositions(graphic?: {name: string, graphic: Graphic}): void {} | ||
} | ||
```` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Sprites | ||
|
||
!!!warning | ||
This feature isn't already tested well. It could evolve. | ||
|
||
## Demonstration | ||
|
||
````js | ||
let rectangle = new Rectangle({ /* .... */ }) | ||
let sprite = new Sprite( | ||
rectangle, //(1)! | ||
"seq1", //(2)! | ||
{ | ||
"seq1": [ //(3)! | ||
{image: "img1.1", time: 500}, | ||
{image: "img1.2", time: 1500}, //(4)! | ||
{image: "img1.3", time: 500} | ||
], | ||
"seq2": [ | ||
{image: "img2.1", time: 500}, | ||
{image: "img2.2", time: 500}, | ||
{image: "img2.3", time: 500} | ||
] | ||
} | ||
) | ||
```` | ||
|
||
1. The graphic that hosts the sprite. | ||
2. The current sequence. It's the name of the sequence that will be automatically be used by Cazan. | ||
3. Here define your different sequences of images. | ||
4. This image here will be displayed a bit longer than the other of its sequence. | ||
|
||
It creates a sprite on the ``rectangle``. On this sprite there's two different sequences of three images each. | ||
|
||
If you want to change of sequence, just type: | ||
|
||
````js | ||
sprite.changeSequence("seq2") | ||
```` | ||
|
||
!!!tip "About multiple sequences..." | ||
We invented this system to help you to animate characters! You know, there's many steps to animate somebody walking, | ||
but with this set of many sequences, you can create a sequence of animations for each direction on only one sprite! | ||
|
||
Example: | ||
````js | ||
let player = new Rectangle({ /* .... */ }) | ||
let sprite = new Sprite( | ||
player, | ||
"right", | ||
{ | ||
"right": [ | ||
{image: "img1.1", time: 500}, | ||
{image: "img1.2", time: 500}, | ||
{image: "img1.3", time: 500} | ||
], | ||
"left": [ | ||
{image: "img2.1", time: 500}, | ||
{image: "img2.2", time: 500}, | ||
{image: "img2.3", time: 500} | ||
] | ||
// ...... | ||
} | ||
) | ||
```` | ||
|
||
## Reference | ||
|
||
````ts | ||
class Sprite { | ||
currentImage = 0 | ||
|
||
/** | ||
* | ||
* @param rectangle | ||
* @param currentSequence It must be the name of one of the sequences of the ``images`` argument. | ||
* @param images It's an object that can contain multiple sequences of images. | ||
*/ | ||
constructor( | ||
protected rectangle: Rectangle, | ||
protected currentSequence: string, | ||
protected images: Record<string, SpriteImage[]> | ||
) {} | ||
|
||
changeSequence(newSequence: string): void {} | ||
|
||
/** | ||
* You can use this method to create new sequences. | ||
*/ | ||
setImageSequence(sequence: string, images: SpriteImage[]): void {} | ||
|
||
getImageSequence(sequence: string): SpriteImage[] {} | ||
} | ||
```` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.