[solved] How do I place text automatically?

0 favourites
  • 10 posts
From the Asset Store
Spooky Places game assets for 2D endless runner action adventure game.
  • For example in this game 'simple idle game' in the arcade, which I cannot post a link to for lack of repuation, each object has three numbers neatly paced by each of the objects.

    Either the writer painstakingly placed a number of text boxes or he had some automatic method where the code made them. I had a search but couldn't find anything that didn't reference just changing the contents of a manually placed text box.

    So how did the programmer do that? Thanks!

  • Hey Callan,

    Have you tried the create object? it will let you pick the spot to spawn it...

    You can pair that with cords for where you want to spawn it. (If you need a example just ask.)

    Justin

  • Hi antares,

    But how do we distinguish each text box from one another? If an object spawns two text boxes, how do we make one contain X and one contain Y, when they are both 'text box'?

  • Many ways to do this..

    If you can see the difference between one instance and the other, you are able to tell the computer which one you mean..

    I usually give the text-object an instance variable "function" on creation and set the variable to whatever the function is: "highscore" "time" etcetera..

    Sometimes it's easier to have an object in a container, so it is automatically picked when picking the other object..

    Other times you might want to change the contents based on where the text-object is on the layout..

    Picking the right instance consists of knowing which instance you mean and making that known to the computer in the event..

  • https://goo.gl/xnWwrv (r215)

  • This is the easiest way I found when working on my project...

    Let's say you have a item you want text over, and be able to change it...

    Give your other item a instance variable of Text_UID (or something similar)

    Then create your Text object.

    Then set your other item's instance variable to that text object's UID.

    That way, when you want to change it, just find that text, with "Pick by Unique ID" (it will be the UID in the instance variable)

    Sorry, this seems kinda complicated... I might make a video next week, explaining this...

  • I don't understand why some engines have to make this stuff hidden away - stencyl was like this too.

    In game maker you could just do 'worker=instance_create(x,y,object);'

    And worker would equal the objects ID.

    Then you could just do 'worker.x=400;' to change the value x or whatever value inside the object. Really easy.

    Why other game engines have to make it really hard to do the same thing, I do not know?

    RamPack - what happens if any instances are created that aren't recorded in that global (say instances which you don't want to manipulate)? It'd seem the system wouldn't work if any instances get created but aren't tracked?

  • Instead of using a global variable you could just give the text boxes the UID of the "lamp" that is creating them - my example was to try to show the idea of tieing /grouping several objects together using instance variables.

    As LittleStain said there are many ways of doing this including the built in container (not sure if containers are in the free version of construct ?)

  • here you go an updated capx using containers.

    https://goo.gl/XaQv7C

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks, RamPackWobble!

    Containers are in the free version and I added a container to a practice object, put a text object inside it and in a simplified form copied parts of your code and managed to get it to work - two objects using a text box, but with a random number sent to their text boxes, and they showed different numbers than each other as they should.

    I'd still really like to just be able to have one object directly manipulate the variables of an object. But this solves my initial problem!

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