egret 子弹类

感谢这位大哥给的启发

a7是获取摇杆角度

class a7{
   
    public chuan=null;
    public shou=null;



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

下面是子弹类 继承egret.sprite
主类添加子弹图片 timer
constructor(x,y,r)通过这个 传进来 子弹的xy及摇杆角度r
public jiao=null;为了下面的

 this.x=Math.cos(this.jiao)*10+this.x;
            this.y=Math.sin(this.jiao)*10+this.y;//Math.cos(ang.jieguo)*10

获取角度其中this.x是

class bullet extends egret.Sprite{
    public jiao=null
    public constructor(x,y,r){   //构造函数。
        super();  //继承
var timer6:egret.Timer=new egret.Timer(100,0);
     timer6.addEventListener(egret.TimerEvent.TIMER,this.bullet_move,this);
        this.jiao=r;
        timer6.start();
var enemy:egret.Bitmap = new egret.Bitmap();
enemy.texture = RES.getRes("bg_jpg");
    //  var bullet_obj=new egret.Shape();
        enemy.x=x;
        enemy.y=y;
        this.addChild(enemy);
    //    this.bullet_move();   //每创创建一个bullet就移动
    }
public bullet_move(){
    
    this.x=Math.cos(this.jiao)*10+this.x;
        this.y=Math.sin(this.jiao)*10+this.y;//Math.cos(ang.jieguo)*10
}
}

最后当按钮点击时 新建类将 人物当前xy及角度传给bullet类

  function button(){
            jiaoo=ang.jieguo;
            var aa=new a7();
            aa.run(ang.jieguo);
             var bu=new bullet(sky.x,sky.y,aa.shou);
             this.addChild(bu);
      }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值