Create Text Dynamically and set to follow sprite

0 favourites
  • 4 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • I'd like to create multiple instances of a sprite, then attach a text object to each of them (representing the health) but each one will be unique. Each time you click one of the sprites, that specific objects health text value goes down by 1.

    Is there a way to parent a text object to a sprite, and to be able to refer to the child object (text) as a variable?

    eg: when i click the sprite, find the text field child and subtract 1 from its health variable and update the text?

    thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • On the creation of each sprite.. in the same event, create the text object and also set this variable:

    Sprite.TextID to Text.UID

    and then to keep each text updated:

    for each Sprite

    pick Text by UID = Sprite.TextID

    that'll single out the corresponding text object for the actions such as:

    -> set text to Sprite.Health

    -> set text position to sprite.x, sprite.y

    etc

  • I understand the last part, but im still not clear about the first step "Sprite.TextID to Text.UID"

    Sprite.textID can't be a variable because it contains a . in it. And textID isnt a valid property of Sprite. So how to do set it?

    Can you wip me up a quick screenshot of the setup? I'm sure its something tiny im missing.

    The sprites are already on the layout,

    Here's what sorta works already.

    The it checks each of the sprites in existance, creates a text field for each of them, aligns them to the center, then changes their text to the area (width*height) and divides by 100 to make the numbers smaller, then updates the text.

    How i want to subtract 10 lets say from each sprite/text combo each time a sprite is clicked. I tried making it a whole other event (system/on clicked object subtract 10), but it kept subtracting that value from all of the boxes, not just the one i clicked.

    see pic below

    imgur.com/wtdFH

    thx for your continued help.

  • Store the textfields UID in an instance variable of the sprite, so you have it handy when needed.

    Also use the "PIN" behaviour to pin the textfield to the sprite, so it follows the sprite.

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