Jekyll2023-11-03T17:44:45+00:00https://csourcesc.github.io/feed.xmlCatSourceTutorials, resources and more, for Scratchers, by Scratchers.Getting started with Cloud Data : creating a global high score2020-12-29T13:30:00+00:002020-12-29T13:30:00+00:00https://csourcesc.github.io/clouddata-global-highscore<p>So you made a great game, and you want to know who’s the best at playing it.</p>
<p>Well, you will share it on Scratch, and you’ll add a High Score variable, and if Score is more than High Score then set High Score to Score. This should work, right? If you test it you’ll see it does. But… not really. It will not work with other people, except if you play in the offline editor or on the same account.</p>
<p>Why? Because, when <em>you</em>, on your account or offline, change the variable’s value, <strong>Scratch will think you made a change to your project</strong>, so it will save it. But other people aren’t able to modify your project, so it won’t save for them.</p>
<h2 id="this-is-where-cloud-data-comes-in">This is where Cloud Data comes in!</h2>
<p>Cloud Data lets you create <strong>global, shared variables</strong>, that everyone (with a Scratcher rank, see below) can modify, which you can use to save a global high score.</p>
<p>To be able to use Cloud Data, <strong>you need to have a Scratcher rank on the Scratch website.</strong> This applies to you and to those who play your project : they can’t change these variables without the Scratcher rank.</p>
<!-- To be wrapped in a callout -->
<p>Cloud Data variables can only be numbers, and cloud lists aren’t a thing, but there are workarounds which I won’t cover here yet.</p>
<p>To have this Scratcher rank, you have to be active in the Scratch community, have a verified email address, and at least 2 shared projects. More on that <a href="https://en.scratch-wiki.info/wiki/New_Scratcher_Status#Requirements_for_becoming_a_Scratcher">here</a>.</p>
<p>Now, let’s get started and create a simple highscore system!</p>
<h2 id="creating-a-cloud-variable">Creating a cloud variable</h2>
<p>First, open your project. Go to Variables and click <code class="language-plaintext highlighter-rouge">Make a Variable</code>. Name the variable <code class="language-plaintext highlighter-rouge">High Score</code>. <strong>Be sure to check <code class="language-plaintext highlighter-rouge">Cloud variable (stored on server)</code></strong>, otherwise it will not be a cloud variable.</p>
<p>You will see the variable alongside other variables, and its name will be preceded with a ☁︎ symbol. This means it’s a cloud variable.</p>
<p>Now, at the end of the game, do a check to verify if the score is superior to the high score, and if yes, update the <code class="language-plaintext highlighter-rouge">High Score</code> variable, just like you would do as usual.</p>
<p>As you can see, Cloud Data is really easy to get started with.</p>locness3You want to show the highest score ever made in your game. Well, you just add a High Score variable, and if Score > High Score then set High Score to Score. That should work, right? Well, not really... Read on to find out more.How to make smooth animations in Scratch2020-05-06T16:26:22+00:002020-05-06T16:26:22+00:00https://csourcesc.github.io/how-to-make-smooth-animations<h2 id="introduction">Introduction</h2>
<p>In Scratch, the most common way to grow a sprite is using <strong>change size</strong>.</p>
<pre class="ScratchBlocks">
change size by ()
</pre>
<p>And the most common way to move a sprite is using <strong>glide</strong>.</p>
<pre class="ScratchBlocks">
glide () secs to x:() y:()
</pre>
<p>Using these methods for animations like clicking a button or showing a logo is not really good.<br />
Here, i use another method, that I call “smooth animation”.<br />
In short, a “smooth animation” is when the sprite’s movement speed varies in the animation, which is better than one of the “animating” methods showed before.
Here we’ll see how to make a smooth animation for changing the size of a sprite.</p>
<h2 id="explaining-by-an-example--changing-size">Explaining by an example : changing size</h2>
<p>First, let’s set the beginning size.<br />
Then, we open a loop where, at each iteration, we make our sprite grow by the size you want to get minus your current size, divided by your speed.</p>
<pre class="ScratchBlocks">
repeat (100)
change size by (((endSize) - (size)) * (speed))
end
</pre>
<p><strong>Important</strong> :</p>
<ul>
<li>The <strong>lower is the speed</strong>, the more you have to <strong>repeat the loop</strong>.</li>
<li>The <strong>speed</strong> should be a number between 0 and 1.</li>
</ul>
<p><strong>Why do we do this ?</strong><br />
Doing the current size minus the wanted size will do the difference between these two. Knowing that difference, we multiply it by a non integer number, so we divide it, to split the difference in mutliple parts, who get smaller as the animation moves on; that’s what makes the “smooth” effect.</p>
<p>Here is an example :</p>
<pre class="ScratchBlocks">
set size to (50)%
repeat (100)
change size by (((200) - (size)) * (0.3))
end
</pre>
<h2 id="do-what-you-want-">Do what you want !</h2>
<p>You can now change that code to use it for something else, like the position.</p>
<pre class="ScratchBlocks">
go to x: (beginX) y: (beginY)
repeat (100)
change x by (((endX) - (x position)) * (speed))
change Y by (((endY) - (y position)) * (speed))
end
</pre>
<p>Now have fun with that !<br />
<em>Thank you for reading this article :3</em></p>
<p><em>Article written by <a href="https://scratch.mit.edu/users/delnyn/">delnyn</a>.</em></p>delnynLearn how to create smooth movement animation, that nicely transitions from one state to another.How to create gravity in Scratch2020-04-02T11:53:21+00:002020-04-02T11:53:21+00:00https://csourcesc.github.io/how-to-create-gravity-in-scratch<h2 id="explanation">Explanation</h2>
<p>To create gravity in scratch we first need to understand how gravity acts in the real world. If you have an apple and you drop from high up what happens? Well the speed (or velocity) of the apple increases towards objects exerting gravity - in proportion to mass - until it reaches terminal velocity or hits something.</p>
<p>Let’s start by simplifying this a bit. Most gravity will come from the earth - so we will ignore other objects. The earth will always be at the bottom of the screen. There will also be no terminal velocity.</p>
<h2 id="basic-physics-in-scratch">Basic Physics in Scratch</h2>
<p>Create a sprite for the object you want to fall (or use one you already have).</p>
<p>First, we will need to create a variable for the current velocity of the sprite.</p>
<pre class="ScratchBlocks">
(Y Velocity)
</pre>
<p>We want the y position of the sprite to change by its y velocity every frame. We can do that with this simple loop. You probably want to attach a when green flag clicked block on top of this.</p>
<pre class="ScratchBlocks">
forever
change y by (Y Velocity)
end
</pre>
<p>That’s great but it doesn’t do anything. This is because Y Velocity stays at zero. To make gravity we need to add a change Y Velocity by block and put a negative number in (so the sprite goes down the screen). Put this in the forever loop.</p>
<pre class="ScratchBlocks">
change [Y Velocity v] by (-3)
</pre>
<p>Things also slow down due to air resistance. For this I just set Y Velocity to 80% (multiplied by 0.8) of what it was. You can change that if you want. We will add this code into the forever loop.</p>
<pre class="ScratchBlocks">
set [Y Velocity v] to ((Y Velocity) * (-8))
</pre>
<p>And finally, there is collision. Create another sprite or colour for the object to collide with.
Let’s say when the thing collides it stops. You want an if else block with a condition for hitting something in the slot at the top; a set Y Velocity to 0 block in the first gap and the gravity code in the else. It falls if it is not colliding otherwise it stops. To make it bounce, you would set the y velocity to Y velocity multiplied by a negative number e.g. -0.9.
Attach this into the forever loop; deleting the previous gravity code.</p>
<pre class="ScratchBlocks">
if <touching color [#b7ff03] ?> then
set (Y Velocity) to (0)
else
change (Y Velocity) by (-3)
</pre>
<p><em>Big thanks to</em> <a href=""><em>Jimmyrooster</em></a> <em>for writing this article.</em></p>
<h2 id="the-final-code">The final code</h2>
<p>You can see the final code <a href="https://scratch.mit.edu/projects/382036051/">here</a>. Feel free to remix it or backpack it for use (but give credit).</p>JimmyroosterLearn how to create simple gravity with a collision.