Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rotation 1

Status
Not open for further replies.

Brian56

Programmer
May 29, 2003
66
CA
Hi All,

I am having some trouble with an effect I am trying to achieve. What I want is to do is have an arrow rotate in the direction of a keypress.

This is what I have and it doesnt quite work correctly

Key.addListener(arrow)
arrow.onKeyDown = function(){
if(Key.Left) this._rotation = 270;
if(Key.Right) this._rotation = 90;
if(Key.Up) this._rotation = 0;
if(Key.Down) this._rotation = 180;
}

Just changing the values does not help.

Any ideas,


Brian
 
not sure if this will be dependent on the registration point or not

works ok with a quick arrow i made with a reg. point at the bottom of the arrow. arrow not a good choice for instance name (reserved word)

Key.addListener(myArrow);

myArrow.onKeyDown = function(){
myArrow._rotation = Key.direction();
updateAfterEvent()
}

Key.direction = function(){
var UD = Key.isDown(Key.DOWN) - Key.isDown(Key.UP);
var LR = Key.isDown(Key.RIGHT) - Key.isDown(Key.LEFT);
if (UD) return 270-90*UD;
if (LR) return 180-90*LR;
}

UD (up/down) and LR will be -1,0 or 1 depending on what is clicked (boolean test)

 
Many Thanks, Bill.

Once again I owe you one. Best of all I understand the solution.


Brian.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top