melonjs / melonJS

a fresh, modern & lightweight HTML5 game engine
https://melonjs.org
MIT License
5.91k stars 644 forks source link

[1.0dev] Error when adding a me.GUI_Object on me.game.world.AddChild() #421

Closed ellisonleao closed 10 years ago

ellisonleao commented 10 years ago

Hi guys.

I'm experiencing a strange bug. I've created a simple Gui button entity and when i'm trying to add an instance of this button on the world i get the following error:

Uncaught TypeMismatchError: The type of an object was incompatible with the expected type of the parameter associated to the object.

The me.GUI_Object:

var Share = me.GUI_Object.extend({
  init: function(){
    settings = {};
    x = me.video.getWidth()/2 - 100;
    y = me.video.getHeight()/2;
    settings.image = "share";
    settings.spritewidth = 214;
    settings.spriteheight = 75;
    this.parent(x, y, settings);
  },

  onClick: function(event){
    var shareText = 'Just made ' + game.data.steps+ ' steps on Clumsy Bird! Try online here!'
    var url = 'http://ellisonleao.github.io/clumsy-bird/';
    window.open('http://www.facebook.com/sharer.php?u='+ url +'&t='+ shareText, 'Facebook Share', 'height=300, width=300');
    return false;
  }

});

the code part when i'm trying to add it:

this.share = new Share();
me.game.world.addChild(this.share, 12);
parasyte commented 10 years ago

Use the var keyword to define the settings, x, and y variables.

Everything else looks ok ... ? :confused:

ellisonleao commented 10 years ago

same results :worried:

obiot commented 10 years ago

Probably due the the fact that the width and height properties are now mandatory, try adding them in the settings parameters

On 12 févr. 2014, at 21:33, Jason Oster notifications@github.com wrote:

Use the var keyword to define the settings, x, and y variables.

Everything else looks ok ... ?

— Reply to this email directly or view it on GitHub.

ellisonleao commented 10 years ago
settings.spritewidth = 214;
 settings.spriteheight = 75;

This ones?

obiot commented 10 years ago

Just add settings.width and settings.height with the same values

agmcleod commented 10 years ago

Can you tell us the full stack trace if chrome gives you one? Also what line number is the error being thrown on? Use the development non-minified build if you need to :)

obiot commented 10 years ago

Can you also try to compile and use the very last vesion of melonJS? We did fix a few bugs since yesterday, and i don't remember exactly which version I used when i updated clumsy bird. My here abobe comment still apply anyway .

ellisonleao commented 10 years ago

Same error with the latest build.

The stacktrace is the following:

Uncaught TypeMismatchError: The type of an object was incompatible with the expected type of the parameter associated to the object. 

melonJS-1.0.0.js:4481
me.SpriteObject.me.Renderable.extend.draw melonJS-1.0.0.js:4481
me.ObjectContainer.me.Renderable.extend.draw melonJS-1.0.0.js:6470
me.game.api.draw melonJS-1.0.0.js:1344
_renderFrame melonJS-1.0.0.js:7718
agmcleod commented 10 years ago

Add a console.log above the context.drawImage() call. Output the this.image and the this.offset. Something there is either returning undefined or null. Im leaning more towards the image being the problem.

obiot commented 10 years ago

The issue is here : https://github.com/melonjs/melonJS/blob/1.0.0-dev/src/renderable/GUI.js#L73-74 GUI_Object has not been updated to reflect last change and shoud pass width and height to the parent constructor instead of spritewidth and spriteheight.

I could fix it now, but i'm in a bar enjoyign some good belgian beers :)

ellisonleao commented 10 years ago

i could do the fix and open a PR myself. Could be the first of many contributions hehe

agmcleod commented 10 years ago

If there's any excuse worthy of not fixing a bug, it's having some belgium beer.

ellisonleao commented 10 years ago

Amem to that :+1:

ellisonleao commented 10 years ago

Turns out the error was a missing image on the resources. But i've notice that the settings.spritewidth and settings.spriteheight is used in many places. Is it gonna change its typo to width and height? If yes i could do this change here.