File tree Expand file tree Collapse file tree 6 files changed +39
-2
lines changed
src/org/openpatch/scratch Expand file tree Collapse file tree 6 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ function s4j_examples_run() {
2424 pushd $java_dir;
2525 java_filename = " ${ java_file%.* } "
2626 lib = $( s4j_workdir) /distribution/scratch4j-linux-amd64.jar
27+ rm -rf **/*.class
2728 javac -cp "$lib:." $java_file
2829 echo $PWD
2930 echo $java_file
@@ -40,6 +41,7 @@ function s4j_examples_run_all() {
4041 java_dir = ${ f%/* }
4142 java_name = " ${ java_file%.* } "
4243 pushd $java_dir
44+ rm -rf **/*.class
4345 javac -cp "$root/distribution/scratch4j-linux-amd64.jar:." $java_file
4446 java -cp "$root/distribution/scratch4j-linux-amd64.jar:." $java_name
4547 popd
Original file line number Diff line number Diff line change @@ -3,6 +3,11 @@ name: Changelog
33index : 4
44---
55
6+ ## 4.3.0
7+
8+ - 🚀 Feat: Random can now create a new random unit vector (Random.randomVector2()).
9+ - 🚀 Feat: You can now set the width of a text after calling the constructor (text.setWidth(40)).
10+
611## 4.2.1
712
813- 🐛 Fix: AnimatedSprite throws an error, because the animationFrame is too high.
Original file line number Diff line number Diff line change @@ -504,6 +504,10 @@ public void setPosition(Vector2 v) {
504504 this .setPosition (v .getX (), v .getY ());
505505 }
506506
507+ public Vector2 getPosition () {
508+ return new Vector2 (x , y );
509+ }
510+
507511 /**
508512 * Rotates the sprite by a certain degrees to the left.
509513 *
@@ -918,6 +922,7 @@ public Hitbox getHitbox() {
918922 }
919923
920924 public boolean isTouchingSprite (Sprite sprite ) {
925+ if (sprite == this ) return false ;
921926 if (stage == null ) return false ;
922927 if (sprite == null || !sprite .show || sprite .hitboxDisabled ) return false ;
923928 return this .getHitbox ().intersects (sprite .getHitbox ());
@@ -968,6 +973,10 @@ public float getMouseY() {
968973 return this .stage .getMouseY ();
969974 }
970975
976+ public Vector2 getMouse () {
977+ return new Vector2 (this .getMouseX (), this .getMouseY ());
978+ }
979+
971980 /**
972981 * Returns true is the mouse button is down
973982 *
Original file line number Diff line number Diff line change @@ -56,6 +56,15 @@ public static void noiseSeed(long noiseSeed) {
5656 Random .noiseSeed = noiseSeed ;
5757 }
5858
59+ /**
60+ * Returns a random unit vector
61+ *
62+ * @return a random unit vector
63+ */
64+ public static Vector2 randomVector2 () {
65+ return new Vector2 (random (), random ()).unitVector ();
66+ }
67+
5968 /**
6069 * Returns a random double between 0 and 1.
6170 *
Original file line number Diff line number Diff line change @@ -238,6 +238,10 @@ public float getWidth() {
238238 return this .width ;
239239 }
240240
241+ public void setWidth (double width ) {
242+ this .width = (float ) width ;
243+ }
244+
241245 public void setAlign (int align ) {
242246 this .textAlign = align ;
243247 }
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ public class Image {
1414
1515 String name ;
1616 PImage image ;
17+ AbstractMap <Float , PImage > imageResized = new ConcurrentHashMap <>();
1718 final PImage originalImage ;
1819 Color tint = new Color ();
1920 float transparency = 255 ;
@@ -188,8 +189,15 @@ public void setImage(String imagePath) {
188189 public void setSize (float percentage ) {
189190 this .width = Math .round (this .originalImage .width * percentage / 100 );
190191 this .height = Math .round (this .originalImage .height * percentage / 100 );
191- this .image = this .originalImage .copy ();
192- this .image .resize (this .width , this .height );
192+
193+ var imageResized = this .imageResized .get (percentage );
194+ if (imageResized != null ) {
195+ this .image = imageResized ;
196+ } else {
197+ imageResized = this .originalImage .copy ();
198+ imageResized .resize (this .width , this .height );
199+ this .image = imageResized ;
200+ }
193201 }
194202
195203 /**
You can’t perform that action at this time.
0 commit comments