Hello,
I've checked the forum and I couldn't find a solution. I want to place some
defined sprites on the screen with random numbers. Is there an easy way to
couple a random text to a sprite on the screen. The sprites are 3D block
drawings and I like to add text to these blocks. The text is changing from
time to time.
Thanks,
Marc
Comments
In TextField object, you could also change text dynamically.
-I will create some texts inside some txt file. Every line will be my separate text.
-So wherever i want i can read those strings(texts) to some array.
-I will give my sprites(assets) following by a an arbitrary number. Like sprite1,sprite2,sprite3.
-I will take random number and concatenate it with my sprite asset name like;
sprite+random number that i generate.
-I will do this method for the array of texts also.
-Then i will dynamically add them to stage on the scene init.
Hope it is understandable.
Take care
Generally I would add the bitmap/sprite/character on the screen and then I just add a textfield on top of it centered on the width and height of the sprite. Like the following. I built a simple function that drops text on any sprite, you could easily use a loop to name them all and add a number etc with it. Here is an example of it working and of course the function.
P.S. For a random number you can always use math.random()
Thanks for your great help. The sprites I will put on the screen are rectangles with numbers. These numbers are changing in time and if I touch the rectangle and do a move, both rectangle and number must move as if they are one object. The above sample will do the trick I guess. I will try it out and keep you informed.
Best regards,
Marc
Than both number and the rectangle will move as you wanted.
(In the ex @Teranth shared, label is already child of parent_sprite in your case rectangle. So it is like a holder.)
cleaner code. This is what I did with your suggestions:
------------------------------------------------------------------
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill