+42
-0
lines changedFilter options
+42
-0
lines changed Original file line number Diff line number Diff line change
@@ -69,6 +69,7 @@ import javafx.scene.input.MouseButton
69
69
import javafx.scene.text.Text
70
70
import javafx.stage.Stage
71
71
import javafx.util.Duration
72
+
import java.net.URL
72
73
import java.util.*
73
74
import java.util.concurrent.Callable
74
75
import java.util.function.BiConsumer
@@ -331,10 +332,18 @@ class FXGL private constructor() { companion object {
331
332
332
333
@JvmStatic fun image(assetName: String, width: Double, height: Double): Image = texture(assetName, width, height).image
333
334
335
+
@JvmStatic fun image(url: URL): Image = getAssetLoader().loadImage(url)
336
+
337
+
@JvmStatic fun image(url: URL, width: Double, height: Double): Image = texture(url, width, height).image
338
+
334
339
@JvmStatic fun texture(assetName: String): Texture = getAssetLoader().loadTexture(assetName)
335
340
336
341
@JvmStatic fun texture(assetName: String, width: Double, height: Double): Texture = getAssetLoader().loadTexture(assetName, width, height)
337
342
343
+
@JvmStatic fun texture(url: URL): Texture = getAssetLoader().loadTexture(url)
344
+
345
+
@JvmStatic fun texture(url: URL, width: Double, height: Double): Texture = getAssetLoader().loadTexture(url, width, height)
346
+
338
347
@JvmStatic fun text(assetName: String) = getAssetLoader().loadText(assetName)
339
348
340
349
/* AUDIO */
@@ -349,6 +358,16 @@ class FXGL private constructor() { companion object {
349
358
return music
350
359
}
351
360
361
+
/**
362
+
* @param url url to the background music file to loop
363
+
* @return the music object that is played in a loop
364
+
*/
365
+
@JvmStatic fun loopBGM(url: URL): Music {
366
+
val music = getAssetLoader().loadMusic(url)
367
+
getAudioPlayer().loopMusic(music)
368
+
return music
369
+
}
370
+
352
371
/**
353
372
* Convenience method to play music/sound given its filename.
354
373
*
@@ -370,6 +389,29 @@ class FXGL private constructor() { companion object {
370
389
}
371
390
}
372
391
392
+
/**
393
+
* Convenience method to play music/sound given its filename.
394
+
*
395
+
* @param url name of the music file
396
+
*/
397
+
@JvmStatic fun play(url: URL) {
398
+
val assetName = url.toExternalForm()
399
+
400
+
when {
401
+
assetName.endsWith(".wav") -> {
402
+
val sound = getAssetLoader().loadSound(url)
403
+
getAudioPlayer().playSound(sound)
404
+
}
405
+
assetName.endsWith(".mp3") -> {
406
+
val music = getAssetLoader().loadMusic(url)
407
+
getAudioPlayer().playMusic(music)
408
+
}
409
+
else -> {
410
+
throw IllegalArgumentException("Unsupported audio format: $assetName")
411
+
}
412
+
}
413
+
}
414
+
373
415
/* INPUT */
374
416
375
417
private var actionCounter = 0
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4