Hello. Is it possible to create and use JS classes from Scittle? I searched through the Scittle source code but didn't find any references to class or defclass (like in shadow.cljs.modern). Are there other recommended ways for doing it or what syntax should I use?
For example, what would the equivalent code be using Scittle:
class Example extends Phaser.Scene
{
preload ()
{
this.load.setBaseURL('');
this.load.image('sky', 'assets/skies/space3.png');
}
create ()
{
this.add.image(400, 300, 'sky');
}
}
In this case I'm trying to write code to interface with the Phaser JS game framework (like done in https://phaser.io/tutorials/getting-started-phaser3/part5). Thank you for any tips and suggestions!Not in scittle, unless you use js/eval
Thanks! I'll try to find another way
Thank you. I searched for this in the #scittle channel and went over the first 60 pages of results but didn't find messages that dealt with the use of this . I'll keep checking back here, hopefully you can help me out with some tips.
I imagine getting access to this directly would be most straight forward solution (unless there's more wrapping into functions happening behind the scenes).
The other way I can think is to implement my Scittle code (clojure that integrates with the Phaser JS library) so that once the objects are instantiated the this in the JS world works the way expected.
The workaround is this: First create the object.
(let [this #js {} ;; in your case, probably the class instance
Then create the method:
meth (fn [this] (whatever you need to do with this))
Then assign the method to the object:
(set! this .-theMethod meth)Thanks, got the problem solved! Using your suggestion and after reading more about Phaser code (this part especially https://github.com/phaserjs/phaser/blob/master/src/scene/SceneManager.js#L372) I came up with this solution which works:
(ns blog.demos.phaser-playground
(:require ["Phaser" :refer [Scene Game Class] :as Phaser]))
(defn create [this]
(.image (.-add this) 100 300 "taikodrummaster"))
(defn create-scene
[]
(let [scene (new Scene (clj->js {:key "MyClojureScene"}))]
(set! (.-create scene) (partial create scene))
scene))
(def config
{:type (.-AUTO Phaser)
:parent "game-container"
:width 800
:height 600
:scene (create-scene)})
(defn create-game
[]
(let [game (new Game (clj->js config))]
game))nice :)
Hello. I'm experimenting with Scittle and the Phaser JS game framework for a small demo and throughout the Phaser code, the use of this is widespread and I haven't found a way to get access to the functions (like this.load.image(...) or this.add.image(...).
I would like to ask your help or any tips on how to get access to this inside a function (without this-as as it seems unavailable in Scittle)?
I prepared an example fiddle (no ES6 classes just ES5) on https://jsfiddle.net/madisnomme/brmgyjze/6/
It's from example code from Phaser documentation https://phaser.io/examples/v3.85.0/loader/image/view/load-image
I'll reply later today, there is a workaround for this - perhaps search this channel first if you want a faster answer, I have some appointments first
I'm finally fixing this-as in SCI