Release v5.0.0#27
Merged
Merged
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scratch for Java 5 is about what a beginner meets first.
Version 4 grew by addition. Every capability arrived as more public methods on
SpriteandStage, more constructors, more public fields to assign beforestarting, and more packages to import. A learner opening
Spritein BlueJ met289 public methods, most of which had no Scratch block behind them, and a
mistyped costume name closed BlueJ itself.
v5 removes what nobody needed, moves what belonged elsewhere, and fills the
gaps that were actually stopping projects.
SpriteandStageare down from289 public methods to 193, and everything a first course needs is behind one
import.
Nothing here is a rename for its own sake: every removal is either a second way
to do something that already had a first way, or something with no Scratch
equivalent and no demonstrated use.
Migrating from v4
One import
Eight packages moved into
org.openpatch.scratch, soPen,Text,Timer,AnimatedSprite,Vector2,Random,Color,Hitboxand the shapes all comefrom one line:
Delete any
import org.openpatch.scratch.extensions.animation.*;and itssiblings for
color,hitbox,math,pen,shape,textandtimer.Five packages are still opt-in, for things a first course does not meet:
camera,fs,recorder,shaderandtiled, joined by the newpixelsandsorting.Handlers are overridden, not registered
The whole
setWhenXfamily is gone — 16 setters acrossSprite,StageandWindow, and the 16 nestedWhen*Handlerinterfaces that went with them. Everyevent already had an overridable method, which is the form that matches Scratch:
setRungoes the same way — overriderun(). AndsetOnEdgeBounce(true)becomes a call inside
run(), the way the block works:Settings are methods, chosen before the window opens
Public fields you assigned before starting did nothing at all if you assigned
them afterwards — no error, no warning. They are methods now, and they say so
when used too late:
new Stage(true, 800, 600)Window.useFullScreen();thennew Stage(800, 600)Window.TEXTURE_SAMPLING_MODE = 2;Window.useTextureSampling(TextureSampling.POINT);Text.DEFAULT_FONT = "f.ttf";Text.useFont("f.ttf");Text.DEFAULT_FONT_SIZE = 11;Text.useFont("f.ttf", 11);Text.FONT_SIZES = new int[]{14, 20};Text.useFontSizes(14, 20);Text.SMOOTHING = false;Text.useSmoothing(false);Stage.setTextureSampling(...)Window.useTextureSampling(...)TextureSamplingandTextAlignare enums rather than loose ints, so a wrongvalue can no longer be written. Code that already said
TextAlign.LEFTcompilesunchanged.
Methods that moved to a class of their own
Nine clock values and nine shader methods existed on both
SpriteandStage— 36 methods for 18 ideas.this.getCurrentYear()Clock.getYear()this.addShader(...),this.switchShader(...)this.getShaders().add(...),.switchTo(...)this.setSorter(...),this.enableYSort()this.getSorting().byY()this.getPixels()→int[]this.getPixels().main()→int[]this.stampToUI()this.stamp(Layer.UI)this.getWindow()Window.getInstance()stage.countSpritesOf(C.class)stage.count(C.class)stage.findPensOf(C.class)stage.find(C.class)Layeris a new enum withBACKGROUND,FOREGROUNDandUI, so choosing alayer is something you say rather than a method name you pick.
Overloads that made the wrong thing easy
broadcast(Object)andwhenIReceive(Object)are gone. Broadcasting anon-
Stringused to call only theObjecthandler, so a sprite overridingwhenIReceive(String)silently heard nothing. Messages are names, as inScratch.
whenAddedToStage(Stage)andwhenRemovedFromStage(Stage)are gone —override the no-argument forms; the argument is what
getStage()returns.setHitbox(Hitbox)andsetHitbox(double[], double[])are gone.setHitbox(Shape)andsetHitbox(double... points)cover both.Interface parts have their own class
Buttons and bars want to be drawn on top, ignore the camera, and be sized in
pixels rather than percent. That is now
UISprite:setWidth,setHeight,setNineSliceanddisableNineSliceareprotectedonSpriteand public onUISprite;changeWidthandchangeHeightare onUISpriteonly;isUI(boolean)becameprotected setUI(boolean); andStage.goToUILayeris gone.Fewer constructors
Stagehad seven andWindoweight, four of each differing only by a leadingboolean fullScreen.StagekeepsStage(),Stage(width, height)andStage(width, height, assets);Windowkeeps those three plusWindow(assets). Full screen isWindow.useFullScreen().Plumbing that was public only to cross a package
Stage.draw,pre,keyEventandmouseEventwere public only so the renderloop could reach them from another package. They are private now, reached
through an internal interface the stage hands over.
Stage.stamp(Queue<Stamp>, Layer)went the same way. It existed soTiledMapcould put a map's tiles into the stage's stamp queues, which meant a method
taking
internal.Stamp— a type nobody outside the library can build — sat inautocomplete next to the real blocks.
TiledMapnow goes through an internalaccessor, and the method is package-private.
Neither was reachable in any useful way before, so no project has to change.
Sprite.stamp(Layer)is still the stamp block.Behaviour that changed without the code changing
These need no edit, but a v4 project may look or behave differently:
often drawn into a larger canvas — a standing pose in a costume tall enough to
hold a jumping one — and a sprite used to collide with that empty space.
Collisions now match what a player can see. Hitboxes set with
setHitbox(...)are unaffected.
explains once on the console what to add, because drawing nothing looks exactly
like a broken program. A sprite with a hitbox and no costume — an invisible
wall — is left alone.
ScratchExceptioninstead of callingSystem.exit.Ending the process took BlueJ's virtual machine with it, so a mistyped costume
name used to close everything the student had open.
starting a project.
What is new
838 built-in sprites and 266 built-in sounds from kenney.nl
ship inside the jar, so a first project needs no downloads at all:
Names are matched ignoring case, a wrong name suggests the closest matches
instead of reporting a missing file, and anything with a file extension is
still treated as a path — so existing projects are unaffected. Ogg Vorbis is
now a supported sound format.
askandanswer, so a program can take typed input. Unlike Scratch itdoes not pause the script, so check
isAsking()or wait forgetAnswer()tochange.
glide(seconds, x, y)withisGliding(),setVolume/changeVolume/getVolume, andStage.waitUntil(condition).Your own logo on the loading screen, with
Window.useSplashLogo(...).Named timers create themselves —
getTimer("countdown")no longer has tobe declared with
addTimerfirst.touching colorwas attempted and dropped: it needs the whole screen read backoff the graphics card every frame, which is too slow for the machines this
library is meant for.
getPixels()carries the same limitation, now writtendown in its documentation.
Fixes
ifOnEdgeBounce()no longer leaves a sprite stuck half outside the stage. Itused to reposition using the size of the hitbox alone, which only works while
the hitbox is centred on the sprite; it now nudges the sprite by however far
its hitbox pokes over the border.
the letterbox bars came out grey for one frame, because a render buffer's
OpenGL framebuffer was being allocated after the canvas had already been
painted black.
GifRecorder.stop()no longer truncates the last frame of a recording.covers most short sound effects.
META-INF/services, so the Ogg decoder survivesshading.
Documentation
The book is now seven tutorials, and every Java block on the hand-written pages
is compiled by
mvn test, so an example cannot quietly stop working — which hadalready happened twice.
Green Light, Guess the Number, Bouncing Hedgehog, Dodge the
Rocks. All but the hedgehog need no downloaded files, and each links a
finished project to compare against.
jar's own resources, searchable, with a click copying the
addCostume(...)oraddSound(...)line.pages, and 108 pages now carry a worked example, against one before v5. 429
stale pages for methods that no longer exist were deleted.
./scripts/run.shpicks any of the 153 demos, finished projects and referenceexamples and runs it.