Actionscript 3 can';t在flash actionscript中存储对象x和y坐标
似乎无法使用此代码存储坐标Actionscript 3 can';t在flash actionscript中存储对象x和y坐标,actionscript-3,flash,Actionscript 3,Flash,似乎无法使用此代码存储坐标 var collisions:Array = _collisionList.checkCollisions(); if(collisions.length) { var tempX:Number = 0; var tempY:Number = 0; _speedX = 0; _speedY = 0; _wheel.vx = 0; _wheel.vy
var collisions:Array = _collisionList.checkCollisions();
if(collisions.length)
{
var tempX:Number = 0;
var tempY:Number = 0;
_speedX = 0;
_speedY = 0;
_wheel.vx = 0;
_wheel.vy = 0;
if(tempX==0 || tempY== 0){
trace(_wheel.x+" "+_wheel.y);
if(_speedX>0) tempX = _wheel.x - .5;//GOING RIGHT
if(_speedX<0) tempX = _wheel.x + .5;
if(_speedY>0) tempY = _wheel.y - .5;//GOING DOWN
if(_speedY<0) tempY = _wheel.y + .5;
trace(tempX+" "+tempY);
}
//_wheel.x = tempX;
//_wheel.y = tempY;
}
else{
//_wheel.vy += GRAVITY;
//Moves Hero
_wheel.vx += _speedX;
_wheel.vy += _speedY;
//Slows down hero's motion.
_wheel.vy *= FRICTION;
_wheel.vx *= FRICTION;
//Updates hero's position.
_wheel.x += _wheel.vx;
_wheel.y += _wheel.vy;
if(_wheel.x > stage.stageWidth) _wheel.x = stage.stageWidth;
if(_wheel.x < /*0*/stage.stageWidth*-1) _wheel.x = stage.stageWidth*-1
if(_wheel.y > stage.stageHeight - (_wheel.height >> 1) )//reset ball.
{
//_wheel.y = 10;
//_wheel.x = 30;
//_wheel.vx = _wheel.vy = 0;
}
}
这就是speedX和speedY值的变化方式 您的值未被存储的原因是因为从未满足
if
条件:(请参阅我的代码注释)
\u speedX=0//你不想在这里设置这个
_速度=0//还是这个
_车轮vx=0//可能也不是这样
_wheel.vy=0;//还是这个
如果(tempX==0 | | tempY==0){
轨迹(_-wheel.x++u-wheel.y);
//由于上面您刚刚将_speedX设置为0,因此将不满足此条件。
如果(_speedX>0)tempX=_wheel.x-.5;
//由于上面您刚刚将_speedX设置为0,因此将不满足此条件。
如果(_speedX0)tempY=_wheel.y-.5;
//由于上面您刚刚将_speedY设置为0,因此将不满足此条件。
如果(| speedy不能做布尔运算或类似的运算,如果我正确地阅读了你的代码-必须做tempX==0 | | tempY==0
将它从if((tempX | | tempY)==0)更改为if(tempX==0 | | tempY==0)仍然无法存储坐标。您是否遇到了错误,或者只是意外行为?错误/行为是什么?此外,出于好奇,如果,为什么会这样做?您只需将它们设置为0-这将始终是真的。\u wheel.x
,\u wheel.vx
和\u wheel.y
,\u wheel.vy
是否应该不同,或者这是一个典型的问题o?在if语句之前,您正在将\u speedX
和y设置为0,因此在执行if(\u speedX>0)
private function keyPressed(e:KeyboardEvent):void
{
var collisions:Array = _collisionList.checkCollisions();
if(collisions.length)
{
_speedX = 0;
_speedY = 0;
_wheel.vx = 0;
_wheel.vy = 0;
}
// _speed* increments the longer the key is pressed.
else
{
if(e.keyCode == Keyboard.LEFT) _speedX = -.5;// -.5 axisX/sec
if(e.keyCode == Keyboard.RIGHT) _speedX = .5;
if(e.keyCode == Keyboard.UP) _speedY = -.5;
if(e.keyCode == Keyboard.DOWN) _speedY = .5;
}
}
private function keyReleased(e:KeyboardEvent):void
{
_speedX = 0;
_speedY = 0;
}
_speedX = 0; //you don't want to set this here
_speedY = 0; //or this
_wheel.vx = 0; //and probably not this either
_wheel.vy = 0; // or this
if(tempX==0 || tempY== 0){
trace(_wheel.x+" "+_wheel.y);
//Since above you just set _speedX to 0, this condition will not be met.
if(_speedX>0) tempX = _wheel.x - .5;
//Since above you just set _speedX to 0, this condition will not be met.
if(_speedX<0) tempX = _wheel.x + .5;
//Since above you just set _speedY to 0, this condition will not be met.
if(_speedY>0) tempY = _wheel.y - .5;
//Since above you just set _speedY to 0, this condition will not be met.
if(_speedY<0) tempY = _wheel.y + .5;
trace(tempX+" "+tempY);
}