Skip to main content

Strange Binding issue

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

Hi all, I have a strange issue with bindings that I hope you can clarify for me.

Im trying to generate a random, rock shape using basic maths and render the rock on the screen. The rock is a Polygon made up of a generated array of Number's. (i.e. Number[]).

When I create the number[] for the x and y positions of each of the points on the Polygon, I use the bind keyword to create an xpos/ypos variable, which I then insert into the Number[].

The custom function()'s i use to create the x and y pos get a variable passed into it called velocityX and velocityY, which I then increment over and over in a Timeline variable. But when I incrememn the velocityX/Y var's and then I print out the values in the Number[], nothing changes.

Here is the cut down version of the code:

<br />
for(val in numOfPoints){<br />
    //... code omitted</p>
<p>    //get x and y of line<br />
    var xpos = bind calcXPos(velocityX, angle);<br />
    var ypos = bind calcYPos(velocityY, angle);</p>
<p>    insert xpos into asteroidPoints;<br />
    insert ypos into asteroidPoints;</p>
<p>    //... code omitted<br />
}</p>
<p>function calcXPos(velocityX, angle){<br />
    ((cirRadius * java.lang.Math.cos(angle * (java.lang.Math.PI / 180))) + cirCenterX) + velocityX<br />
}</p>
<p>function calcYPos(velocityY, angle){<br />
    ((cirRadius * java.lang.Math.sin(angle * (java.lang.Math.PI / 180))) + cirCenterY) + velocityY<br />
}</p>
<p>asteroid = Polygon {<br />
    points: bind asteroidPoints;<br />
    stroke:Color.BLACK<br />
}</p>
<p>var movementTimeline = Timeline {<br />
    repeatCount: Timeline.INDEFINITE<br />
    keyFrames : [<br />
        KeyFrame {<br />
            time : 20ms<br />
            action : function() {<br />
                velocityX += 15;</p>
<p>                for (num in asteroidPoints){<br />
                   java.lang.System.out.println("{num}") ;<br />
                }<br />
                java.lang.System.out.println("-----------------------") ;<br />
            }<br />
        }<br />
    ]<br />
}<br />
movementTimeline.start();<br />

so the movementTimeline changes the velocityX variable, but the values in the asteroidPoints array do not change, even though the elements in the array are bound to a result using the velocityX variable.

Any ideas??? Does it have something to do with the fact that I am using a function() to get the xpos and ypos values??

Thanks
Mark

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

What does the code below print?

[code]

for(val in numOfPoints){
//... code omitted

//get x and y of line
var xpos = bind calcXPos(velocityX, angle);
var ypos = bind calcYPos(velocityY, angle);

insert xpos into asteroidPoints;
insert ypos into asteroidPoints;

System.out.println(asteroidPoints);

}
[/code]

What is your code that draws the asteroid?

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

Im not at my PC with the code, so I will give you the output tonight. but the code for the drawing is the creation of the asteroid:

asteroid = Polygon {
points: bind asteroidPoints;
stroke:Color.BLACK
}

which is just an element in the content[] of the Frame{} of the app, like any other polygon would be...