zoukankan      html  css  js  c++  java
  • 用EC5/EC6自定义class的区别及用法 -- Phaser3网页游戏框架

     
    custom class
    custom class

    EC6 自定义class

    class Brain extends Phaser.GameObjects.Sprite {
    
        constructor (scene, x, y)
        {
            super(scene, x, y);
    
            this.setTexture('brain');
            this.setPosition(x, y);
        }
    
        preUpdate (time, delta)
        {
            super.preUpdate(time, delta);
    
            this.rotation += 0.01;
        }
    
    }
    

    EC5 自定义class

    var Bunny = new Phaser.Class({
        Extends:Phaser.GameObjects.Sprite,
        initialize:function Bunny(scene,x,y,speed){
            Phaser.GameObjects.Sprite.call(this,scene);
            this.setTexture('bunny');
            this.setPosition(x, y);
            this.setScale(0.3);
            this.speed = speed;
            
        },
        preUpdate(time,delta){
            this.rotation += (0.01+ this.speed * 0.0001) ;
        }
    });
    

    完整代码:

    var Bunny = new Phaser.Class({
        Extends:Phaser.GameObjects.Sprite,
        initialize:function Bunny(scene,x,y,speed){
            Phaser.GameObjects.Sprite.call(this,scene);
            this.setTexture('bunny');
            this.setPosition(x, y);
            this.setScale(0.3);
            this.speed = speed;
            
        },
        preUpdate(time,delta){
            this.rotation += (0.01+ this.speed * 0.0001) ;
        }
    });
    var config = {
        type: Phaser.AUTO,
         600,
        height: 480,
        parent: 'phaser-example',
        scene: {
            preload: preload,
            create: create
        }
    };
    
    var game = new Phaser.Game(config);
    
    function preload (){
        //http://www.ifiero.com/uploads/ifiero-logo_512x512.png
        // this.load.image('bunny', 'http://www.ifiero.com/images/ifiero-logo_512x512.png');
         this.load.setBaseURL('http://labs.phaser.io');
         this.load.image('bg', 'assets/pics/purple-dots.png');
         this.load.image('bunny', 'assets/sprites/bunny.png');
         
    }
    
    function create (){
    
        this.add.image(0, 0, 'bg').setOrigin(0).setScale(0.8);
        this.add.existing(new Bunny(this, 150, 150,100));
        this.add.existing(new Bunny(this, 250, 250,200));
        this.add.existing(new Bunny(this, 350, 350,300));
    }
    
    

    更多游戏教学:www.iFIERO.com -- 为游戏开发深感自豪

  • 相关阅读:
    C语言寒假大作战04
    C语言寒假大作战03
    C语言寒假大作战02
    C语言寒假大作战01
    C语言I作业12—学期总结
    C语言I博客作业11
    C语言I博客作业10
    预习非数值数据的编码方式
    计算机组成与系统结构作业01
    C语言||作业01
  • 原文地址:https://www.cnblogs.com/apiapia/p/10064773.html
Copyright © 2011-2022 走看看