Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify bits for Rect, add setInterval and setTimeout to cloning and … #35

Merged
merged 1 commit into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Clarify bits for Rect, add setInterval and setTimeout to cloning and …
…fix first tutorial link on README.md
  • Loading branch information
pelshen committed Aug 2, 2019
commit b8d768e280cfc7be1e749e70a316f787cdc9f229
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Mobile games for beginners.

* [Install](https://livewires.github.io/you-win/install)
* Read the [Intro tutorial](https://livewires.github.io/you-win/1-numbers)
* Read the [Intro tutorial](https://livewires.github.io/you-win/00-new-world)
* Make a [Doodle Jump clone](https://livewires.github.io/you-win/jump)

For experts:
Expand Down
10 changes: 10 additions & 0 deletions docs/cloning.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ <h1 class=title><a href="https://github.com/livewires/you-win">you-win</a></h1>
<ul>
<li class=page-heading><a href="#functions">Functions</a>
<li class=page-heading><a href="#copying-a-sprite">Copying a sprite</a>
<li class=page-heading><a href="#delaying-the-copies">Delaying the copies</a>
<li class=page-heading><a href="#on-tap">On tap</a>
<li class=page-heading><a href="#moving-clones">Moving clones</a>
<li class=page-heading><a href="#destroying-clones">Destroying clones</a>
Expand Down Expand Up @@ -73,6 +74,15 @@ <h2 id="copying-a-sprite">Copying a sprite</h2>
}
</code></pre>
<p><img class="emojione" alt="👉" title=":point_right:" src="https://cdn.jsdelivr.net/emojione/assets/3.1/png/32/1f449.png"/> Make sure there are 100 sprites created. You’ll need to randomize their positions (or something) or they’ll all be overlapping each other in the middle!</p>
<h2 id="delaying-the-copies">Delaying the copies</h2>
<p>Or, if we wanted to make a new copy every 3 seconds, we could use <code>setInterval</code>. This allows us to give a function that we want to execute each time and the amount of time to wait in between.</p>
<pre><code class="lang-JS">setInterval(function() {
makeCow()
}, 3000)
</code></pre>
<p>Note that the amount of time is in milliseconds (3000ms = 3seconds).</p>
<p>If you wanted to only wait <em>once</em>, rather than multiple times, you can use <code>setTimeout</code> in exactly the same way.</p>
<p>For more information on setTimeout and setInterval, including how to stop a <code>setInterval</code> from executing from running using <code>clearInterval</code>, have a look <a href="https://www.w3schools.com/js/js_timing.asp">here</a>.</p>
<h2 id="on-tap">On tap</h2>
<p>We can use our new function to create a sprite when you <a href="05-events#taps">tap the screen</a>. </p>
<pre><code class="lang-js">world.onTap(e =&gt; {
Expand Down
Binary file modified docs/pdfs/00-new-world.pdf
Binary file not shown.
Binary file modified docs/pdfs/01-creating-sprites.pdf
Binary file not shown.
Binary file modified docs/pdfs/02-position.pdf
Binary file not shown.
Binary file modified docs/pdfs/03-random.pdf
Binary file not shown.
Binary file modified docs/pdfs/04-forever.pdf
Binary file not shown.
Binary file modified docs/pdfs/05-events.pdf
Binary file not shown.
Binary file modified docs/pdfs/06-recipes.pdf
Binary file not shown.
Binary file modified docs/pdfs/2-animation.pdf
Binary file not shown.
Binary file modified docs/pdfs/3-arrays.pdf
Binary file not shown.
Binary file modified docs/pdfs/4-functions.pdf
Binary file not shown.
Binary file modified docs/pdfs/angles.pdf
Binary file not shown.
Binary file modified docs/pdfs/bouncing.pdf
Binary file not shown.
Binary file modified docs/pdfs/cloning.pdf
Binary file not shown.
Binary file modified docs/pdfs/collisions.pdf
Binary file not shown.
Binary file modified docs/pdfs/install.pdf
Binary file not shown.
Binary file modified docs/pdfs/jump.pdf
Binary file not shown.
Binary file modified docs/pdfs/reference.pdf
Binary file not shown.
Binary file modified docs/pdfs/scoring.pdf
Binary file not shown.
Binary file modified docs/pdfs/scrolling.pdf
Binary file not shown.
2 changes: 2 additions & 0 deletions docs/reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ <h2 id="importing">Importing</h2>
<li><a href="#sprite">Sprite</a></li>
<li><a href="#text">Text</a></li>
<li><a href="#polygon">Polygon</a></li>
<li><a href="#rect">Rect</a></li>
<li><a href="#phone">Phone</a></li>
<li><a href="#sound">Sound</a></li>
</ul>
Expand Down Expand Up @@ -329,6 +330,7 @@ <h2 id="rect">Rect</h2>
<p>See <a href="#polygon">Polygon</a> for more details.</p>
</li>
</ul>
<p>Don’t forget you will need to use <code>new Rect</code> and not <code>new Polygon</code></p>
<h2 id="touch-events">Touch Events</h2>
<p>An <strong>event</strong> tells you that something has happened. Both Worlds and Sprites will emit events when they are tapped or dragged.</p>
<p>If a tap overlaps more than one sprite (because the sprites are overlapping), then the sprites are told about the events in order. The front-most one sees the event first.</p>
Expand Down
14 changes: 14 additions & 0 deletions docs/sheets/cloning.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ for (let num of uw.range(100)) {

👉 Make sure there are 100 sprites created. You'll need to randomize their positions (or something) or they'll all be overlapping each other in the middle!

## Delaying the copies

Or, if we wanted to make a new copy every 3 seconds, we could use `setInterval`. This allows us to give a function that we want to execute each time and the amount of time to wait in between.
```JS
setInterval(function() {
makeCow()
}, 3000)
```

Note that the amount of time is in milliseconds (3000ms = 3seconds).

If you wanted to only wait *once*, rather than multiple times, you can use `setTimeout` in exactly the same way.

For more information on setTimeout and setInterval, including how to stop a `setInterval` from executing from running using `clearInterval`, have a look [here](https://www.w3schools.com/js/js_timing.asp).

## On tap

Expand Down
2 changes: 2 additions & 0 deletions docs/sheets/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ title: API Reference
* [Sprite](#sprite)
* [Text](#text)
* [Polygon](#polygon)
* [Rect](#rect)
* [Phone](#phone)
* [Sound](#sound)

Expand Down Expand Up @@ -410,6 +411,7 @@ Instead of a `costume`, `Rect`s have the following:

See [Polygon](#polygon) for more details.

Don't forget you will need to use `new Rect` and not `new Polygon`

## Touch Events

Expand Down