Spawn an object for each letter in a string

Get help using Construct 2

Post » Thu Oct 31, 2013 6:04 pm

I got kind of a weird one. I need to something like what is described here, but a little different.

I have a string of up to 25 letters in a global var. Something like "DAFGHABCDEFDAFGHABCDEFDAFGHABCDEF".

At the start of the layout, for each letter in the string I want to spawn a sprite object for each letter at a spawn point for that letters position. So if the first letter was "D" I want to spawn a "D" sprite from the "LtrSprites" family at position 1, and so on.

Anyone got an idea on how to do this?
B
5
Posts: 8
Reputation: 366

Post » Thu Oct 31, 2013 6:18 pm

http://s000.tinyupload.com/index.php?file_id=26457981229369840871

If each letter has their own sprite-object, you ofc need to pick in respect to your family (add an instance variable to the family, that corresponds to the letter; then pick by comparison in the while-loop).

If you have specific positions planned for your letters that follow no simple order, specify them in an array.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Thu Oct 31, 2013 6:51 pm

OK I kinda see what your getting at. If I fill and array object with the letters and loop through it I can get what letter is at which position, but what I don't get is how to spawn a "D" sprite vs a "X" sprite based on the my current position in the loop.
B
5
Posts: 8
Reputation: 366

Post » Thu Oct 31, 2013 7:06 pm

Guess pick by comparison doesn't affect which element of the family is spawned?
And creating sprites by name sadly is not possible.
The easiest solution would probably be to put each letter into an animation of one sprite like in my example and then just set the correct animation.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Thu Oct 31, 2013 7:35 pm

If you just want to spawn letter sprites, why not use the spritefont? You can manipulate the text easily to just show the one letter of the string you want.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Nov 01, 2013 5:13 pm

@thagr8stone If I am understanding correctly, you're trying to spawn a regular sprite object based on the current letter in the global variable string? So letter "D" might correspond to a "house" sprite, and not necessarily a the letter "D"?

In that case, you could create a Dictionary with the alphabets as the keys and put in the corresponding sprite as the values. So when you loop through the string, use Dictionary.Get("A") to spawn the correct sprite.

Otherwise if you're just showing the actual letters in the sprite, I'd just do what LittleStain said.
B
10
S
3
G
1
Posts: 11
Reputation: 1,554


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 18 guests