Ignore visibility of sprites if object is template
krumza

Hi! 

I got a constuction with template object:

            var a = new Sprite('images/noise2.png',16);//it gray
            var activeMarker = new Sprite('ui/activemarker.png',16);//it green
            activeMarker.setVisible(false);//not working
            var b = new SceneObject(a);
            b.addSprite(activeMarker,0,1);
            b.getSprite(1).setVisible(false);// not working
            b.setName('Marker');
            b.setAsTemplate(true);
            wade.addSceneObject(b);

then in code i insert 

var newMarker = wade.getSceneObject("Marker").clone();  
newMarker.setPosition(RowWidth*j,RowHeight*i/2);
wade.addSceneObject(newMarker,true);

And all is green.

Understandably, that if i try 

var newMarker = wade.getSceneObject("Marker").clone();
newMarker.getSprite(1).setVisible(false);  
newMarker.setPosition(RowWidth*j,RowHeight*i/2);
wade.addSceneObject(newMarker,true);

All be gray.

Question - this is BUG or feature?

All 5 Comments
Gio

Hi

From the documentation of SceneObject.isTemplate:

"A template is a scene object that never receives any events, and is set to be invisible as soon as it's added to the scene"

So yes, it doesn't matter whether you set the template's sprites to visible or invisible, they all become invisible once the template is added to the scene. And they're all made visible when you create a regular (non-template) object by cloning the template.

So to control the visibility of each sprite, you'd have to call setVisible after cloning the object, like you're doing in your last code snippet above.

Gio

Just to add something to my reply above - your original object does not have to be a template. It can be a regular object, as long as you don't add it to the scene it will not be visible anyway. That way, the visibility of each individual sprite will be preserved.

krumza

One more question - .usePixelPerfectMouseEvents() is working on template objects?

Gio

It should do. If it doesn't work for you let me know and we'll fix it.

However keep in mind that template objects will not receive any events, ever. Only their clones will.

krumza

Sorry usePixelPerfectMouseEvents() seems to work correctly if configured for all sprites. It just carelessness/

I keep in mind this, I generate a map of 100*100 and put a rhombus in each node
Diamond just the same pattern for the tiles.

If you want I can give a link to this project))) Although there is particularly nothing to show

 

Post a reply
Add Attachment
Submit Reply
Login to Reply