Skip to content

Commit a8e3699

Browse files
author
Mike Barkmin
committed
Add documentation about hitboxes
1 parent 1d9abb2 commit a8e3699

2 files changed

Lines changed: 33 additions & 13 deletions

File tree

‎README.md‎

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ API: https://www.barkmin.eu/processing-library-scratch/reference/eu/barkmin/proc
9191
Source Code: https://github.com/mikebarkmin/processing-library-scratch/blob/master/src/eu/barkmin/processing/scratch/ScratchSprite.java
9292

9393
In Scratch sprites are the main actors. Every sprite has a custom set of
94-
costumes and sounds, which could be dynamicly changed. Most of the
94+
costumes and sounds, which could be dynamically changed. Most of the
9595
functionality which sprites in Scratch have were tried to reimplement in
9696
processing.
9797

@@ -149,7 +149,7 @@ class CatSprite extends ScratchSprite {
149149
| :-: | :-: |
150150
| ![sprite show](web/assets/sprite_show.png) | `sprite.show();` |
151151
| ![sprite hide](web/assets/sprite_hide.png) | `sprite.hide();` |
152-
| ![srpite switch costume](web/assets/sprite_switch_costume_to.png) | `sprite.switchCostume("costume1");` |
152+
| ![sprite switch costume](web/assets/sprite_switch_costume_to.png) | `sprite.switchCostume("costume1");` |
153153
| ![sprite next costume](web/assets/sprite_next_costume.png) | `sprite.nextCostume();` |
154154
| ![sprite set color](web/assets/sprite_set_color_to.png) | `sprite.setTint(0);` |
155155
| ![sprite change color by](web/assets/sprite_change_color_by.png) | `sprite.changeTint(25);` |
@@ -161,7 +161,7 @@ class CatSprite extends ScratchSprite {
161161
| ![sprite size](web/assets/sprite_size.png) | `sprite.getSize();` |
162162

163163
To add a new costume call `sprite.addCostume("newCostume",
164-
"path/to/newCostume.png");`. Afterwards you can swith to the costume by calling
164+
"path/to/newCostume.png");`. Afterwards you can switch to the costume by calling
165165
`sprite.switchCostume("newCostume");`.
166166

167167
#### Sensing
@@ -173,9 +173,9 @@ To add a new costume call `sprite.addCostume("newCostume",
173173
| ![sprite mouse y](web/assets/sprite_mouse_y.png) | `sprite.getMouseY()` |
174174
| ![sprite is key pressed](web/assets/sprite_key_pressed.png) | `sprite.isKeyPressed(32)` <br> For key pressed you need to use key codes see https://keycode.info/ to find the appropriate one. |
175175
| ![sprite current ?](web/assets/sprite_current_time.png) | `sprite.getCurrentYear()`, `sprite.getCurrentDay()`, `sprite.getCurrentHour()`, `sprite.getCurrentMinute()`, `sprite.getCurrentSecond()`, `sprite.getCurrentMillisecond()`, `sprite.getCurrentDayOfWeek()` |
176-
| ![sprite touching mouse pointer](web/assets/sprite_touching_mouse_pointer.png) | `sprite.isTouchingMousePointer()` |
177-
| ![sprite touching edge](web/assets/sprite_touching_edge.png) | `sprite.isTouchingEdge()` |
178-
| ![sprite touching sprite](web/assets/sprite_touching_sprite.png) | `sprite.isTouchingSprite(anotherSprite)` |
176+
| ![sprite touching mouse pointer](web/assets/sprite_touching_mouse_pointer.png) | `sprite.isTouchingMousePointer()` Pixelperfect, transparent pixel will be ignored |
177+
| ![sprite touching edge](web/assets/sprite_touching_edge.png) | `sprite.isTouchingEdge()` based on the default [hitbox](#hitboxes)|
178+
| ![sprite touching sprite](web/assets/sprite_touching_sprite.png) | `sprite.isTouchingSprite(anotherSprite)` based on a custom or the default [hitbox](#hitboxes)|
179179

180180
#### Events
181181

@@ -210,7 +210,7 @@ API: https://www.barkmin.eu/processing-library-scratch/reference/eu/barkmin/proc
210210
Source Code: https://github.com/mikebarkmin/processing-library-scratch/blob/master/src/eu/barkmin/processing/scratch/ScratchPen.java
211211

212212
In Scratch every sprite can use a pen to draw lines, therefore every
213-
ScratchSprite object has an pen assoziated with it. Through a similiar api the
213+
ScratchSprite object has an pen associated with it. Through a similar api the
214214
pen can be modified.
215215

216216
| Scratch | Processing |
@@ -227,9 +227,9 @@ pen can be modified.
227227

228228
### Timer
229229

230-
Sometimes you want to tigger an event after a certain time or at a certain time
230+
Sometimes you want to trigger an event after a certain time or at a certain time
231231
interval. Therefore the stage and every sprite have one or more Timer objects.
232-
You can access the timer objects throught `stage.getTimer()` or
232+
You can access the timer objects through `stage.getTimer()` or
233233
`sprite.getTimer()`. The timer object has some useful methods:
234234

235235
| API | Example | Description |
@@ -261,18 +261,18 @@ intervalMillis(600, 300, true) -> red (seventh line)
261261

262262
If you want that a sprite should do something every 2000ms and every 1000ms,
263263
you need two timers. To add a timer you simply call
264-
`sprite.addTimer("timerForMe")`. The timer is than accessable with `sprite.getTimer("timerForMe")`.
264+
`sprite.addTimer("timerForMe")`. The timer is than accessible with `sprite.getTimer("timerForMe")`.
265265

266-
Unfortunatly the timer are not on point. Sometimes they are lacking behind.
266+
Unfortunately the timer are not on point. Sometimes they are lacking behind.
267267
This happens when the frame rate drops. This can lead to a unwanted rendering
268-
order. For example the pattern which was tried to achive in the example
268+
order. For example the pattern which was tried to achieve in the example
269269
[TimedDot](#TimeDot) should look like this:
270270

271271
Lila, Lila, Green, Lila, Lila, Green, Clear.
272272

273273
Especially at the beginning of the sketch the frame rate increases slowly to
274274
the desired one. Therefore there are some missing frames in the beginning and
275-
the pattern is messed up. To achive a better result you should use a multiple
275+
the pattern is messed up. To achieve a better result you should use a multiple
276276
of the frame rate for millis. (If not set the standard frame rate is 60). You
277277
can see the difference below.
278278

@@ -408,6 +408,26 @@ Shows the sensing time methods
408408
* blocks which are not listed above are currently missing
409409
* sprites can not speak or think
410410

411+
## Advanced Features
412+
413+
### Hitboxes
414+
415+
The default hitbox is defined by the image you have used, but you have the
416+
ability to define a custom hitbox. Therefore call the method `setHitbox` on the
417+
sprite you would like to modify. The `setHitbox` method gets two arguments
418+
`int[] xPoints` and `int[] yPoints` these correspond to the outline out the new
419+
hitbox. The path will be close automatically.
420+
421+
Example: We set the hitbox of an 615px x 570px image.
422+
423+
```
424+
int[] xHitbox = {0, 300, 300, 0, 150};
425+
int[] yHitbox = {0, 0, 570, 570, 275};
426+
this.setHitbox(xHitbox, yHitbox);
427+
```
428+
429+
![hitbox](web/assets/custom_hitbox.png)
430+
411431
## How to install Scratch
412432

413433
### Install with the Contribution Manager

‎web/assets/custom_hitbox.png‎

67.5 KB
Loading

0 commit comments

Comments
 (0)