Spawn an object for each letter in a string

0 favourites
  • 6 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • 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?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • s000.tinyupload.com/index.php

    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.

  • 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.

  • 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.

  • 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.

  • 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.

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