Space Shooter (YouTube video)
echar
var shot=wade.getSceneObject('playerShot').clone();
shot.setName();
console.log(shot.getName());
shot.setPosition(this.getPosition().x,this.getPosition().y-100);
wade.addSceneObject(shot);
shot.moveTo(this.getPosition().x,-wade.getScreenHeight()/2-shot.getSprite().getSize().y,200);

Uncaught TypeError: Cannot read property 'split' of undefined

Why this  line:  console.log(shot.getName()); don't work?

All 8 Comments
Gio

Hi

SceneObject.setName() expects a string. So to remove the name you would do something like

shot.setName('');

 

echar

In video is only shot.setName();

Why?

Why I need this line of Code? I uncommented it and  game  works ...

echar
var shot=wade.getSceneObject('playerShot').clone();
shot.setPosition(this.getPosition().x,this.getPosition().y-50);
wade.addSceneObject(shot);
shot.moveTo(this.getPosition().x,-wade.getScreenHeight()/2-shot.getSprite().getSize().y/2,300);

shot is SceneObject, but  Help is for Sprite:

Gio
  1. You don't need setName(), probably a mistake in the video. When you clone a scene object, the clone will have no name by default.
     
  2. With JavaScript being a dynamic language, it's often impossible to know what type an object is without executing the code. So when hovering your mouse over a function name, you get the help for any library function that's got that name. The code editor cannot know that it's a scene object and not a sprite. I've been thinking of ways to improve it (e.g. show the help for all functions that have got the same name), but I'm not sure how it would work in terms of user interface. We can't have all the descriptions one after the other, it would take too much space. Any suggestions are welcome.
echar

autoListen property is not cloned by default.

I suggest to have clone() with parameter clone(autolisten).

 

Gio

When you clone an object, the clone is never added to the scene automatically. So it doesn't really matter what autoListen is set to, because it's overridden when you add the object to the scene ( it's the second parameter of wade.addSceneObject() ).

echar

I can`t add a custom function:

jquery-1.9.1.js:507 Uncaught Error: cannot call methods on selectmenu prior to initialization; attempted to call method 'refresh'

jquery-ui.min.js:11 Uncaught TypeError: Cannot read property 'index' of null

Gio

You are right, it's a bug that's been introduced in WADE 3.1. Thanks for pointing that out. Easy fix, it will be alright in WADE 3.2.

However, even if it says that in the console, you should still be able to add a custom function and edit it. In the worst case you may have to deselect and reselect the SceneObject. Other than that, you can just ignore the error, it should be safe.

Post a reply
Add Attachment
Submit Reply
Login to Reply