旋转不需要对角,几乎反射?

发布于 2024-10-21 08:08:38 字数 1967 浏览 2 评论 0原文

所以我得到了这个bulletContainer类,它可以发射所有这些子弹,并且它可以工作。当我将班级放入 moveiclip 中以添加到舞台时,拍摄效果非常好。我不能将它放在影片剪辑中,因为当我调用bulletClass 的函数时,它会向我显示一个错误,说它不存在。现在,我的问题是,当我将Child(bulletClass)添加到舞台上时,除了运动/动画之外,它将完全按照其编程方式工作。子弹移动得很好,除了当我射击时,它会向相反的方向射击,而不仅仅是以相反的方式射击,它会稍微向左射击(如果我指向垂直向上一点向左),那么如果我完全指向右侧,它就会旋转到跟我一起射击。所以它基本上在各个方面都很低音,就像我说的,只有当我 addChild() 和一个类(扩展 Movieclip)时才这样。我不知道为什么我给你我的代码,因为它只会让你更加困惑,因为一切都检查过了;我认为在某个地方有一个转换,就像扩展Movieclip的类的方向可能与Library MovieClips不同?

此代码位于bulletAdder() 函数中,它是在bulletContainer 中创建项目符号的唯一位置,

var localPlayer = Object(root).localSurvivor;

//Select what movieclip should go into the bullet
var newBullet;
    newBullet = new bullet1;

//Create a local movieclip for this
var newBulletMC:MovieClip = new MovieClip;
    newBulletMC.addChild(newBullet);
    newBulletMC.x = setX;
    newBulletMC.y = setY;
    //trace(localPlayer.rotation);

//Create the newBullet class for movement
var localPlayerRotation = Object(root).localSurvivor.rotation;
trace(localPlayerRotation);
var newBulletClass:bulletClass = new bulletClass(localPlayerRotation, bulletLifetime);

//Add bulletMC to the bulletClass
    newBulletClass.addChild(newBulletMC);

//Add to array
    bulletArray.push(newBulletClass);

//Add to stage
    localStage.addChild(newBulletClass);

这是bulletClass,即在屏幕上移动的项目符号

package  com{
        import flash.display.*
        import flash.utils.*

    public class bulletClass extends MovieClip{
            public var lifetime = 0;
            public var dir = 0;
                    var animationInt;
        public function bulletClass(playerRotation, bLifetime:Number = 1){
            dir = playerRotation
            //Start life
            animationInt = setInterval(animateBullet, 40);

        }

        private function animateBullet(){
            this.x += 10 * Math.sin(dir * (Math.PI / 180));
            this.y += 10 * Math.cos(dir * (Math.PI / 180));
        }

    }

}

So i got this bulletContainer class that shoots all these bullets it works & shoots perfectly fine when i put the class in a moveiclip to add to the stage. I can't have it in a movie clip because when i call the bulletClass's function it will shoot me an error saying it dosent exist. Now, my problem is when i addChild(bulletClass) onto the stage it will work exactly how its programmed to except for the movement/animation. The bullet moves fine, except when i shoot it shoot the opposite way, and not JUST shoots the opposite way it shoots a little to the left (if im pointing straight up a little to the left), then if i point completely right it will rotate to shoot right with me. So its basically bass-akwards In every way like I said and its only when i addChild() with a class(that extends Movieclip). I don't know why im giving you my code as it will just confuse you more that everything checks out; I think theres a conversion somewhere, like maybe classes that extends Movieclip are orientated differently then Library MovieClips?

This code is in the bulletAdder() function its the only place bullets are created in the bulletContainer

var localPlayer = Object(root).localSurvivor;

//Select what movieclip should go into the bullet
var newBullet;
    newBullet = new bullet1;

//Create a local movieclip for this
var newBulletMC:MovieClip = new MovieClip;
    newBulletMC.addChild(newBullet);
    newBulletMC.x = setX;
    newBulletMC.y = setY;
    //trace(localPlayer.rotation);

//Create the newBullet class for movement
var localPlayerRotation = Object(root).localSurvivor.rotation;
trace(localPlayerRotation);
var newBulletClass:bulletClass = new bulletClass(localPlayerRotation, bulletLifetime);

//Add bulletMC to the bulletClass
    newBulletClass.addChild(newBulletMC);

//Add to array
    bulletArray.push(newBulletClass);

//Add to stage
    localStage.addChild(newBulletClass);

This is the bulletClass, the bullets that move on screen

package  com{
        import flash.display.*
        import flash.utils.*

    public class bulletClass extends MovieClip{
            public var lifetime = 0;
            public var dir = 0;
                    var animationInt;
        public function bulletClass(playerRotation, bLifetime:Number = 1){
            dir = playerRotation
            //Start life
            animationInt = setInterval(animateBullet, 40);

        }

        private function animateBullet(){
            this.x += 10 * Math.sin(dir * (Math.PI / 180));
            this.y += 10 * Math.cos(dir * (Math.PI / 180));
        }

    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十秒萌定你 2024-10-28 08:08:38

看来你已经解决了?

我建议的一件事是——当你做这样的事情时,使用显示列表并不总是有意义的。如果舞台上发生了很多事情,那么速度就会变慢,表演也会变得很快。

如果您正在构建游戏,我强烈建议至少检查一两个大型 Flash 游戏框架。他们在幕后为你做了很多优化,甚至很多游戏逻辑都为你抽象出来。例如,查看 Flixel - 超级容易快速启动和运行,并且有很多教程。

只是我的两分钱,希望有帮助!

Looks like you got it sorted, then?

One thing I will suggest - when you're doing stuff like this it doesn't always make sense to use the display list. If you have a lot of stuff happening on the stage it's going to slow down and performance is going to get sketchy fast.

If you're building a game, I strongly recommend at least checking out one or two of the big Flash Game Frameworks. They do a LOT of optimizations for you behind the scenes, and even much of the game logic gets abstracted out for you. Check out Flixel, for instance - super easy to get up and running quickly, and lots of tutorials out there.

Just my two cents, hope it helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文