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() {
24
24
pushd $java_dir;
25
25
java_filename = " ${ java_file%.* } "
26
26
lib = $( s4j_workdir) /distribution/scratch4j-linux-amd64.jar
27
+ rm -rf **/*.class
27
28
javac -cp "$lib:." $java_file
28
29
echo $PWD
29
30
echo $java_file
@@ -40,6 +41,7 @@ function s4j_examples_run_all() {
40
41
java_dir = ${ f%/* }
41
42
java_name = " ${ java_file%.* } "
42
43
pushd $java_dir
44
+ rm -rf **/*.class
43
45
javac -cp "$root/distribution/scratch4j-linux-amd64.jar:." $java_file
44
46
java -cp "$root/distribution/scratch4j-linux-amd64.jar:." $java_name
45
47
popd
Original file line number Diff line number Diff line change @@ -3,6 +3,11 @@ name: Changelog
3
3
index : 4
4
4
---
5
5
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
+
6
11
## 4.2.1
7
12
8
13
- 🐛 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) {
504
504
this .setPosition (v .getX (), v .getY ());
505
505
}
506
506
507
+ public Vector2 getPosition () {
508
+ return new Vector2 (x , y );
509
+ }
510
+
507
511
/**
508
512
* Rotates the sprite by a certain degrees to the left.
509
513
*
@@ -918,6 +922,7 @@ public Hitbox getHitbox() {
918
922
}
919
923
920
924
public boolean isTouchingSprite (Sprite sprite ) {
925
+ if (sprite == this ) return false ;
921
926
if (stage == null ) return false ;
922
927
if (sprite == null || !sprite .show || sprite .hitboxDisabled ) return false ;
923
928
return this .getHitbox ().intersects (sprite .getHitbox ());
@@ -968,6 +973,10 @@ public float getMouseY() {
968
973
return this .stage .getMouseY ();
969
974
}
970
975
976
+ public Vector2 getMouse () {
977
+ return new Vector2 (this .getMouseX (), this .getMouseY ());
978
+ }
979
+
971
980
/**
972
981
* Returns true is the mouse button is down
973
982
*
Original file line number Diff line number Diff line change @@ -56,6 +56,15 @@ public static void noiseSeed(long noiseSeed) {
56
56
Random .noiseSeed = noiseSeed ;
57
57
}
58
58
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
+
59
68
/**
60
69
* Returns a random double between 0 and 1.
61
70
*
Original file line number Diff line number Diff line change @@ -238,6 +238,10 @@ public float getWidth() {
238
238
return this .width ;
239
239
}
240
240
241
+ public void setWidth (double width ) {
242
+ this .width = (float ) width ;
243
+ }
244
+
241
245
public void setAlign (int align ) {
242
246
this .textAlign = align ;
243
247
}
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ public class Image {
14
14
15
15
String name ;
16
16
PImage image ;
17
+ AbstractMap <Float , PImage > imageResized = new ConcurrentHashMap <>();
17
18
final PImage originalImage ;
18
19
Color tint = new Color ();
19
20
float transparency = 255 ;
@@ -188,8 +189,15 @@ public void setImage(String imagePath) {
188
189
public void setSize (float percentage ) {
189
190
this .width = Math .round (this .originalImage .width * percentage / 100 );
190
191
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
+ }
193
201
}
194
202
195
203
/**
You can’t perform that action at this time.
0 commit comments