Can you make entirely new objects at runtime?

This forum is currently in read-only mode.
From the Asset Store
Create your game with this complete pack of images and animations!
  • Hi everyone,

    I need to make about a hundred sprites, and I don't want to make each object by hand, right-clicking and selecting "insert an object" and loading the image, etc. It would be much easier to be able to do it in a Python script, because then I could just index through all of the images in a loop and assign each to each new object, and ideally store each object in an array. Is this possible?

    Here is what I want to do: in the game I'm making, the player leaves behind a trail of text as she moves, spelling out various things from a text file. Each letter is itself a rather elaborate, though small, image (with color) and I don't know if I could make it into a font (I have no experience with making fonts). And, besides, if I made it a font, every letter would have to be its own text box anyway because each will need its own rotation to follow your movement accurately, and each letter might not fall in line with the letter before it, so I figure that, in terms of programming and resources, there is no difference between 100 separate sprites and 100 separate text boxes of one letter each. And if I can make 100 separate sprites at run time and store all of these in an array (from which I could create and index instances), it'd be pretty easy to do. But I am open to other suggestions on how to do this.

    Hopefully that was clear. Thanks a bunch!

  • If I'm not mistaken, you probably just want to use one of the various Create* functions.

    You can do this quite simply in python with System.CreateByName.

    There is an event also under System (amazingly, called CreateByName!)

    Hope this helps.

    EDIT: About your brain dump second paragraph, if letters are going to be a integral part of your game, make them sprites. Text boxes are handy dandy, but you should get better performance using sprites as... well, sprites.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • What I suggest is put all of your letters in a long strip, tiled at a uniform size.

    Use a SINGLE SPRITE and import them as animation, with speed 0. You can use the import animation panel to chop them up automatically.

    Choose the frame number at runtime, right after creating the sprite.

    This will be much more manageable, in terms of not having a jillion objects, no unwieldy text rendering and you get to control the letters behavior as individual sprites.

  • What I suggest is put all of your letters in a long strip, tiled at a uniform size.

    Use a SINGLE SPRITE and import them as animation, with speed 0. You can use the import animation panel to chop them up automatically.

    Choose the frame number at runtime, right after creating the sprite.

    This will be much more manageable, in terms of not having a jillion objects, no unwieldy text rendering and you get to control the letters behavior as individual sprites.

    If construct does batch rendering like opengl, this will be much faster as well. If not, I agree with them being more manageable at least.

  • What I suggest is put all of your letters in a long strip, tiled at a uniform size.

    Use a SINGLE SPRITE and import them as animation, with speed 0. You can use the import animation panel to chop them up automatically.

    Choose the frame number at runtime, right after creating the sprite.

    This will be much more manageable, in terms of not having a jillion objects, no unwieldy text rendering and you get to control the letters behavior as individual sprites.

    You can also import them as a separate animation, if you want them animated.

  • Thanks for the responses guys; madster, your recommendation seems great, I'll give it a go. I'm still figuring out collision masks because I don't think these letters will all have the same width, but I assume I can have a strip of collision masks to go along with the strip of letters, or something similarly easy - it seems figure-out-able. Good to know this isn't suicide performance-wise, too. Thanks!

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