Reputation: 940
I'm playing around with using Scala for my processing projects.
I've extended the Rect
class from ToxicLibs, but I'm getting a null pointer exception when I try to call rect(toxi.geom.Rect r)
from within a method.
import toxi.processing.ToxiclibsSupport
import toxi.geom.{ Vec2D, Rect }
class Scope(x: Float, y: Float, width: Float, height: Float) extends Rect(x, y, width, height) {
def this(r: Rect) {
this(r.x, r.y, r.width, r.height)
}
def draw(gfx: ToxiclibsSupport) {
gfx.rect(this) // null pointer exception occurs here
}
}
This is the code that calls the draw
method:
import processing.core.PApplet
import toxi.processing.ToxiclibsSupport
import toxi.geom.Rect
class ScalaP5Test extends PApplet {
var gfx = new ToxiclibsSupport(this)
override def setup() {
size(1000, 800)
}
override def draw() {
var scope = new Scope(100, 200, 400, 300)
scope.draw(gfx) // draw called here
}
}
any ideas?
Upvotes: 3
Views: 344
Reputation: 940
Ahh, I got it:
class ScalaP5Test extends PApplet {
var gfx = null
override def setup() {
gfx = ToxiclibsSupport(this)
...
}
...
}
Then you can reuse the variable in other functions. I'm not sure if that's the best way, so if you have a better way, let me know!
Upvotes: 1