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: README.md
+54-7Lines changed: 54 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,8 +23,11 @@ initialize the ScratchStage. You only need to place this statement
23
23
```java
24
24
importeu.barkmin.processing.scratch.*;
25
25
26
+
ScratchStage stage;
27
+
26
28
void setup() {
27
29
ScratchStage.init(this);
30
+
stage =ScratchStage.getInstance();
28
31
}
29
32
30
33
void draw() {
@@ -64,8 +67,16 @@ To add a new backdrop call `stage.addBackdrop("newBackdrop",
64
67
65
68
| Scratch | Processing |
66
69
| :-: | :-: |
67
-
|| Overwrite `stage.keyEvent(KeyEvent e)`. The method will be called everytime a new KeyEvent is fired. For example when pressing or releasing a key. See [KeyEvent](https://processing.github.io/processing-javadocs/core/processing/event/KeyEvent.html) for more Information. |
68
-
|| Overwrite `stage.mouseEvent(MouseEvent e)`. The method will be called everytime a new MouseEvent is fired. For example when pressing, releasing or moving the mouse. See [MouseEvent](https://processing.github.io/processing-javadocs/core/processing/event/MouseEvent.html) for more Information. |
70
+
|| Overwrite `stage.whenKeyPressed(int keycode)`. This method is called everytime a key is pressed. See [http://keycode.info](http://keycode.info) for keycode information |
71
+
|| Overwrite `stage.whenMouseMoved(float x, float y)`. This method is called everytime the mouse is moved. |
72
+
73
+
74
+
### Other methods
75
+
76
+
| Processing | Description |
77
+
| :-: | :-: |
78
+
|`stage.addSprite(sprite)`| Adds a sprite to stage |
79
+
|`stage.removeSprite(sprite)`| Removes a sprite from the stage |
In Scratch sprites are the main actors. Every sprite has a custom set of
96
107
costumes and sounds, which could be dynamically changed. Most of the
97
108
functionality which sprites in Scratch have were tried to reimplement in
98
-
processing.
109
+
processing. When added to the stage, the run method of a sprite will be called continuously.
99
110
100
111
#### Creation
101
112
102
113
```java
103
114
importeu.barkmin.processing.scratch.*;
104
115
116
+
ScratchStage stage;
105
117
CatSprite myCat;
106
118
107
119
void setup() {
108
120
size(800, 600);
109
121
ScratchStage.init(this);
122
+
stage =ScratchStage.getInstance();
110
123
myCat =newCatSprite();
124
+
stage.addSprite(myCat);
111
125
}
112
126
113
127
void draw() {
114
-
myCat.draw();
115
128
}
116
129
117
130
// Define a class Cat
118
131
classCatSpriteextendsScratchSprite {
119
132
CatSprite() {
120
-
super("cat", "sprites/cat.png");
133
+
this.addCostume("cat", "sprites/cat.png");
121
134
this.setOnEdgeBounce(true);
122
135
}
123
-
voiddraw() {
124
-
super.draw();
136
+
voidrun() {
125
137
this.move(2);
126
138
}
127
139
}
@@ -186,6 +198,41 @@ To add a new costume call `sprite.addCostume("newCostume",
186
198
|| Overwrite `sprite.keyEvent(KeyEvent e)`. The method will be called everytime a new KeyEvent is fired. For example when pressing or releasing a key. See [KeyEvent](https://processing.github.io/processing-javadocs/core/processing/event/KeyEvent.html) for more Information. |
187
199
|| Overwrite `sprite.mouseEvent(MouseEvent e)`. The method will be called everytime a new MouseEvent is fired. For example when pressing, releasing or moving the mouse. See [MouseEvent](https://processing.github.io/processing-javadocs/core/processing/event/MouseEvent.html) for more Information. |
188
200
201
+
### Other methods
202
+
203
+
| Processing | Description |
204
+
| :-: | :-: |
205
+
|`sprite.run()`| Will be called continuously, when the sprite is added to the stage. |
206
+
|`sprite.draw()`| Overwrite this methode to gain more controll over the sprite and draw it without added it to the stage. |
207
+
208
+
209
+
The following code will show the same result. The normal sprite is handled by the ScratchStage, the custom sprite is handled by us.
0 commit comments