Can you make entirely new objects at runtime?

For questions about using Classic.

Post » Mon Aug 30, 2010 3:51 am

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!
B
1
G
2
Posts: 4
Reputation: 633

Post » Mon Aug 30, 2010 4:17 am

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.
B
3
G
2
Posts: 31
Reputation: 737

Post » Mon Aug 30, 2010 5:33 am

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.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Mon Aug 30, 2010 6:24 am

[quote="madster":30c0vb36]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.[/quote:30c0vb36]

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.
B
3
G
2
Posts: 31
Reputation: 737

Post » Mon Aug 30, 2010 7:05 am

[quote="madster":34ceb3v6]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.[/quote:34ceb3v6]

You can also import them as a separate animation, if you want them animated.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Wed Sep 01, 2010 3:42 am

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!
B
1
G
2
Posts: 4
Reputation: 633


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 7 guests