Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 在AS3中,如何使相机仅跟随播放器的X轴?_Actionscript 3 - Fatal编程技术网

Actionscript 3 在AS3中,如何使相机仅跟随播放器的X轴?

Actionscript 3 在AS3中,如何使相机仅跟随播放器的X轴?,actionscript-3,Actionscript 3,所以我有一个代码,相机跟随我的播放器,但它同时跟随x轴和y轴。我正在制作一个像as3中的超级马里奥一样的游戏,所以我希望相机只跟随x轴。有什么建议吗? 这是我的密码: import flash.events.Event; import flash.geom.Rectangle; addEventListener(Event.ENTER_FRAME, gameLoop); stage.addEventListener(Event.ENTER_FRAME, cameraFollowCharact

所以我有一个代码,相机跟随我的播放器,但它同时跟随x轴和y轴。我正在制作一个像as3中的超级马里奥一样的游戏,所以我希望相机只跟随x轴。有什么建议吗? 这是我的密码:

import flash.events.Event;

import flash.geom.Rectangle;

addEventListener(Event.ENTER_FRAME, gameLoop);
stage.addEventListener(Event.ENTER_FRAME, cameraFollowCharacter);

function cameraFollowCharacter(evt:Event){
root.scrollRect = new Rectangle(player.x - stage.stageWidth/5, player.y - stage.stageHeight/1.27, stage.stageWidth, stage.stageHeight); 
}

“root.scrollRect”不应依赖于player.y。 为y属性使用固定值

function cameraFollowCharacter(evt:Event){ 
    root.scrollRect = new Rectangle(player.x - stage.stageWidth/5, 0, stage.stageWidth, stage.stageHeight); 
}
您可以使用“相机容器”代替