Re: Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(HTMLImageElement or HTMLVideoElem

1,830 views
Skip to first unread message
Message has been deleted

Dillon

unread,
Oct 13, 2015, 9:54:46 PM10/13/15
to melonJS - A lightweight HTML5 game engine
when i remove this.addChild(new game.HUD.RevivalBtnControl(10, 10));  no error.
Basically I just want to add a button.

在 2015年10月14日星期三 UTC+8上午9:45:00,Dillon写道:
I have an error when add button to container:

game.HUD.RevivalContainer = me.Container.extend({

    init: function() {
        // call the constructor
        this._super(me.Container, 'init');
        // make sure our object is always draw first
        this.z = Infinity;

        
  this.addChild(new me.ColorLayer("revival_background", new me.Color(0,0,0,0.6), 0));
  this.addChild(new game.HUD.RevivalBtnControl(10, 10));
    }
});



game.HUD.RevivalBtnControl = me.GUI_Object.extend({
    /**
     * constructor
     */
    init: function(x, y) {        
        this._super(me.GUI_Object, "init", [ x, y, {
            image: game.texture,
            region : "revival_btn.png" // ON by default
        } ]);
        this.anchorPoint.set(0, 0);
        this.setOpacity(0.8);
console.log("init revival btn.");
    },
    
    /**
     * function called when the pointer is over the object
     */
    onOver : function (/* event */) {
        this.setOpacity(1.0);
    },
    
    /**
     * function called when the pointer is leaving the object area
     */
    onOut : function (/* event */) {
        this.setOpacity(0.8);
    },
    
    /**
     * function called when the object is clicked on
     */
    onClick : function (/* event */) {
        console.log("click");
        return false;
    }
});


error:

Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap)'
me.CanvasRenderer.me.Renderer.extend.drawImage @ melonJS-2.1.3.js:13422
me.Sprite.me.Renderable.extend.draw @ melonJS-2.1.3.js:7595
me.Container.me.Renderable.extend.draw @ melonJS-2.1.3.js:9438
me.Container.me.Renderable.extend.draw @ melonJS-2.1.3.js:9438
me.game.api.draw @ melonJS-2.1.3.js:1871
_renderFrame @ melonJS-2.1.3.js:10132

melonJS

unread,
Oct 14, 2015, 12:03:26 AM10/14/15
to melonJS - A lightweight HTML5 game engine
are you working on the master branch ? 

where did you declare game.texture ?

Dillon

unread,
Oct 14, 2015, 2:43:40 AM10/14/15
to melonJS - A lightweight HTML5 game engine
sorry , I wrote it wrongly ,  replace game.texture to me.loader.getImage("revival_btn").  worked!

在 2015年10月14日星期三 UTC+8下午12:03:26,melonJS写道:
Reply all
Reply to author
Forward
0 new messages