Instantiating Symbols

I was just poking around the API and didn’t see any documentation regarding the ability to dynamically instantiate, manage, or destroy symbols with JS. Has anyone been able to do this?



That's what this thread... Is there a Physics API? 🤔 ...has been about. Hype could be awesome for game development, but it hasn't really leveraged the matter.js API.

There's a "Matter Create" method...

While I'm not sure if that would work wit Symbols, it would be really cool for making games if it did.Yet, a Symbol can be moved and hidden, so a similar effect can be created. It's just not as dynamic.

1 Like

There isn’t a way to instantiate symbols from JavaScript. It is a good feature request (but please don’t hold your breath as the current implementation makes it a lot of work to do!).

If you need to delete them though you can always use the standard .removeNode() DOM method in JavaScript.

1 Like

Hello, I’m producing a dynamic image carousel.
My idea is to use a symbol and create instances based on the number of images retrieved via Ajax.
Can I use a javascript function to instantiate object like
symbol=new symbol(); ?


I think you need to re read this thread. The answer is there is no API to do this

Thank you for your answer, can you suggest any other way to dynamically instantiate elements or scenes?
Thanks again

you can dynamically populate hype-elements with common techniques (javascript, php, ajax), but you can’t create hypeelements itsself on the fly …

As Hans says.

Search this site for clone examples.

One of the main reasons you cannot dynamically create a symbol, is it is in effect a Scene within the main Scene and not a single element.

All the functions/timelines/actions of a Symbol and a Scene are controlled by the Hype javascript which is hard coded when you export the project.

This means that anything with a Timeline or Actions, if duplicated/cloned will not inherit that functionality because the hype runtime and does not know about them from it’s JS and other setting.

You can clone Hype Elements but there are caveats that you need to pay attention to or you will run into issues. Read the threads that mention cloning carefully taking note of how to avoid the pitfalls