How to destroy object using Browser -> execute JavaScript

0 favourites
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hello) I find this function in the code of fade behavior:

    this.runtime.DestroyInstance(this.inst);[/code:3n247k40]
    Question: what I need to write instead "this", to delete sprite using Browser -> execute JavaScript
  • I solved this!!!!!!

    "this.runtime.DestroyInstance(this.runtime.objectsByUid[2]);"[/code:1vr2063s]
    
    instead "2" you need to write object's UID that you want to destroy)
  • Have you really thought this through?

  • Have you really thought this through?

    Yes, I am. I spend a lot of time reading source code of C2. I need it because I want make action that unload unnecessary animations from memory. So I started from picking certain sprite. To make question easier to understand I chose "destroy" function.

    I hope that I understood the question correctly, because English isn't my native language)

    ?????)

  • We already have a destroy action.

    You know that, right?

  • This isn't a good idea. Minifying the script changes all the names so will break any cases you make runtime calls by executing JS.

  • This isn't a good idea. Minifying the script changes all the names so will break any cases you make runtime calls by executing JS.

    Well, could you give me advice on how to unload unnecessary animations from memory. I now create a fairly large space simulator, accordingly I have lots of large animations (gas planets and stars), and they take up a lot of RAM, although they do not use everything at the same time. I already did a selective download of animations, but now I need to do their unloading

    P.S thank you so much for such a cool engine

  • We already have a destroy action.

    You know that, right?

    Yes I know. I chose this function to facilitate the issue. It was important for me to understand how to use the "execute JavaSript" to call a function from the c2runtime.js

  • I don't think highjacking a function will get you where you want. Normal unloading is done layout by layout.

    Also, you would have some issues with using the uid like that. Those ids get recycled.

  • I don't think highjacking a function will get you where you want. Normal unloading is done layout by layout.

    Also, you would have some issues with using the uid like that. Those ids get recycled.

    UID is not problem. Because we can pick certain sprite and then:

    "this.runtime.DestroyInstance(this.runtime.objectsByUid["&Sprite.uid&"]);"[/code:2adnzed0]
    Ashley is right, after minimizing the code, I can not call the functions that I need. I will try to create a plug-in or behavior that will do this.
  • Ashley I would be infinitely grateful if in the next update there will be function of unloading unnecessary animations

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You could use the SDK to write a plugin to do this, and not break minification. It'd also integrate more nicely with events.

    I'm a bit skeptical of unloading objects - in many cases it won't reduce the peak memory usage, so won't help avoid out-of-memory crashes. What are you doing that requires this?

  • You could use the SDK to write a plugin to do this, and not break minification. It'd also integrate more nicely with events.

    I'm a bit skeptical of unloading objects - in many cases it won't reduce the peak memory usage, so won't help avoid out-of-memory crashes. What are you doing that requires this?

    Ashley if I understand the meaning of your question correctly. I already wrote about this, I'm doing a space simulator. Because of that, the generated stars and gas giants did not look very cost-effective, I had to do their animation. For example, one animation of a gas planet has 150 frames, each frame has a 192 * 192 resolution. After simple calculations we learn that one animation will occupy 22 Mb (although it seems to me that it takes up more memory). At the moment I have 10 such animations, to the output of the game I'm going to increase this value 2-3 times. At the same time, no more than 6 animations are displayed, so others just take up memory. Initially, I was going to do an object for each animation and then unite them into a family, but it's very inconvenient. But I figured out how to download animations from project files. And now I'm thinking about how to unload them from memory

  • ST314 I use this plugin https://www.scirra.com/store/construct2 ... emory-3812

    It works like a charm and I can unload a ton of stuff that I don't need anymore when they are destroyed and saves a lot of image memory in my game. You can unload whatever you want with one single action. It is not free but I use it in all my projects so it is totally worth it.

  • Might as well turn those animations into video files.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)