Skip to main content

Simple OO question

6 replies [Last post]
kram
Offline
Joined: 2007-10-23
Points: 0

I have a SpaceEntity class which extends the javafx Polygon and a SpaceShip class that extends the SpaceEntity class.

I have a:
public attribute rotationAngle: Number;

within the SpaceEntity class,

but when I try to create an instance of the SpaceShip class:

<br />
var spaceShip = SpaceShip {<br />
    startX : 100.0;<br />
    startY : 150.0;</p>
<p>    transform: Translate.rotate(rotationAngle, 0, 0)<br />
}<br />

I get an error:

cannot find symbol
symbol : variable rotationAngle
location: class spacemissionfx.Main
transform: Translate.rotate(rotationAngle, arg1, arg2)

why is that?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexsch
Offline
Joined: 2007-07-12
Points: 0

Try this:

[code]
var spaceShip:SpaceShip = SpaceShip {
startX : 100.0;
startY : 150.0;

transform: Translate.rotate(spaceShip.rotationAngle, 0, 0)
}
[/code]

kram
Offline
Joined: 2007-10-23
Points: 0

Thanks, i'll give that a try later tonight and let you know how it goes.

Although its interesting to note (and you may have noticed this), that startX and startY are properties of the SpaceShip class (not the super SpaceEntity class), and I can access them directly like you see in my post. But not the rotationAngle property...

alexsch
Offline
Joined: 2007-07-12
Points: 0

You can use rotationAngle attribute in the same way:

[code]
var spaceShip:SpaceShip = SpaceShip {
startX : 100.0;
startY : 150.0;
rotationAngle: 45
}
[/code]

The standard way to create a JavaFX component is extending CustomNode class:

[code]
import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.geometry.*;
import javafx.scene.transform.*;

public class SpaceEntity extends CustomNode{

public attribute rotationAngle: Number;
public attribute startX: Number;
public attribute startY: Number;

public function create():Node{

return Group{
transform: bind Translate.rotate(rotationAngle, 0, 0)
content:[
Polygon { }
]

}

}

}
[/code]

kram
Offline
Joined: 2007-10-23
Points: 0

Yeah thats what I thought too, but it doesnt work when I use it in the

[code]
var spaceShip:SpaceShip = SpaceShip {
startX : 100.0;
startY : 150.0;
transform: Translate.rotate(rotationAngle, 0, 0);
}
[/code]

BUT

[code]
var spaceShip:SpaceShip = SpaceShip {
startX : 100.0;
startY : 150.0;
rotationAngle: 0.0;
}
[/code]

This works!! So why wouldnt it be able to find it in the Translate.transform method?

alexsch
Offline
Joined: 2007-07-12
Points: 0

The [b]var a = A{ attr: value } [/b] expression is a syntax sugar for:

[code]
var a = new A();
a.attr = value;
[/code]

The code that uses a class attribute looks like:

[code]
var a:A = A{ attr: a.attr2 }
[/code]

kram
Offline
Joined: 2007-10-23
Points: 0

ok, so are you saying that in order to use the rotate method, I have to do it like this:

[code]
var spaceShip:SpaceShip = SpaceShip {
startX : 100.0;
startY : 150.0;
}
spaceShip.transform = Translate.rotate(spaceShip.rotationAngle, 0, 0);
[/code]
?

That seems odd to me...