egret 旋转发射子弹

在这里插入图片描述
需要注意的是 要在按下发射按钮后 创建子弹 在按钮函数中 加入timmer 控制子弹方向

 function button(){
            jiaoo=ang.jieguo;
            var aa=new a7();
            aa.run(ang.jieguo);
               let enemy = this.createBitmapByName("bg_jpg");
        this.addChild(enemy);
   
        enemy.x=sky.x;
        enemy.y=sky.y;
        var timer6:egret.Timer=new egret.Timer(100,0);
        timer6.addEventListener(egret.TimerEvent.TIMER,cont66,this);
        
        timer6.start();
    
     function cont66():void{
            enemy.x=Math.cos(aa.shou)*10+enemy.x;
        enemy.y=Math.sin(aa.shou)*10+enemy.y;//Math.cos(ang.jieguo)*10
        }
      
      }

子弹的方向是触摸时摇杆的弧度
这里的弧度 需要通过类传过来
var aa=new a7();
aa.run(ang.jieguo);

enemy.x=Math.cos(aa.shou)*10+enemy.x;

类a7

 class a7{
       
        public chuan=null;
        public shou=null;
    
    
    
        public run(chuan){
        this.shou=chuan;
        }
    }

不然的话会这样的
在这里插入图片描述

还有一些 出错 图片
在这里插入图片描述
这是因为 在timer中 新建的子弹 所以每秒都会画

function cont66():void{
            let enemy = this.createBitmapByName("bg_jpg");
        this.addChild(enemy);
       // let stageW = 160;
      //  let stageH = 160;
    //    enemy.width = 160;
      //  enemy.height = 160;
        enemy.x=sky.x;
        enemy.y=sky.y;
            enemy.x=Math.cos(jiaoo)*10+enemy.x;
        enemy.y=Math.sin(jiaoo)*10+enemy.y;//Math.cos(ang.jieguo)*10
        }

下面是所有代码

   //
        //
        //  Copyright (c) 2014-present, Egret Technology.
        //  All rights reserved.
        //  Redistribution and use in source and binary forms, with or without
        //  modification, are permitted provided that the following conditions are met:
        //
        //     * Redistributions of source code must retain the above copyright
        //       notice, this list of conditions and the following disclaimer.
        //     * Redistributions in binary form must reproduce the above copyright
        //       notice, this list of conditions and the following disclaimer in the
        //       documentation and/or other materials provided with the distribution.
        //     * Neither the name of the Egret nor the
        //       names of its contributors may be used to endorse or promote products
        //       derived from this software without specific prior written permission.
        //
        //  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
        //  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
        //  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
        //  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
        //  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
        //  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
        //  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
        //  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
        //  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
        //  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        //
        //
        class angle67{
            public jieguo=null;
            public neix=null;
            public shpwaix=null;
            public neiy=null;
            public shpwaiy=null;
        
        
        
            public run(neiy,shpwaiy,neix,shpwaix){
            this.jieguo=Math.atan2(neiy-shpwaiy,neix-shpwaix);
            }
        }
        
        class a7{
           
            public chuan=null;
            public shou=null;
        
        
        
            public run(chuan){
            this.shou=chuan;
            }
        }
        class HomeScene extends eui.Component{
                private vj:VirtualJoystick = new VirtualJoystick();  //虚拟摇杆
                private player:eui.Rect;    //人物
                private speedX = 0;         //人物移动速度
                private speedY = 0;
                private speed = 10;
         
                public constructor() {
                        super();
                        this.skinName = "HomeSceneSkin";
                }
         
                public childrenCreated(){
                        //开启虚拟摇杆
                        this.vj.start();
                        this.vj.addEventListener("vj_start",this.onStart, this);
                        this.vj.addEventListener("vj_move", this.onChange, this);
                        this.vj.addEventListener("vj_end", this.onEnd, this);
                }
         
                //摇杆启动,人物开始根据摇杆移动
                private onStart(){
                        this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
                }
         
                //触摸摇杆的角度改变,人物的移动速度方向也随之改变
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值