How can I handle my Object instances?

0 favourites
  • 7 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • Hello,

    with "Create Object" I have created 5 Objects.

    Now I want to move every single Object into different directions.

    How to do that?

    It must be something like:

    Object(0).x += 5

    Object(1).x += 2

    Object(2).x += 1

    Object(3).y += 2

    Object(4).y += 1

    ... (example)

    I cant handle the names.

    The first Sprite I created is for example: ENEMY.

    But when I create an instance(via CreateObject), what is the namen then...?

    Kind regards

    Jogi

  • jogibaer5000

    the name doesn't change. if you used Create Object to make an instance of Enemy, then its name is still Enemy.

    if there are other instances of Enemy, then you have to be careful how you "pick" them, otherwise any actions you do may apply to all instances - not just the one you expected.

    you can use instance variables to distinguish between them, or their UID, or Enemy(0).x or events such as Is Overlapping...

    in your example, you could use the "Self" reference, so it would be:

    Object(0) Set X to self.x + 5

    Object(1) Set X to self.x + 2

    etc...

    without the self reference you could also say:

    Object(4) Set Y to Object(4).Y + 1

  • Thank you very much.

    I will try that out.

    Kind regards

    Jogi

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hello again,

    That did not work for me.

    Maybe I am too stupid...

    I cant move the singel objects into different directions...

    an you please check the capx file?

    Kind regards

    Jogi

  • jogibaer5000

    event 4 refers to all instances. so they all will add 2 to their Y position.

    if you want to have them move in different directions, you have to decide what the rules are for their movement, and then set up a way to tell each one what it needs to do, and there are many ways to do that.

    you could give them Bullet behavior and give each one a random angle and bullet speed when they are created. Or you could give them each an instance variable that tells them what type of object they are, and make rules for each type. you could loop through them using a For Each loop and always have the first instance do one thing, the second something else, etc...

    I adjusted your sample slightly to give them each a random X and Y speed.

    there are lots of other ways - you just have to get your head around all the various ways to "Pick" the instances so you can tell each one what to do...

    https://www.rieperts.com/games/forum/movesprites.capx

  • Hello,

    thank you very much.

    Your post gives me some good ideas.

    Unfurtunately I could not open your CAPX.

    It's because me construct2 is too old.

    I already made an update 5 Minutes ago, but

    it only updated to 2.65.

    But it says, that your file seems to be made with 2.66...

    So i can't open it.

    Where did you get your 2.66 Version from?

    Kind regards

    Jogi

  • Oh sorry, i had an old Update Link.

    Now I have 2.67 installed and i could load your file.

    The idea is good, but i want to manipulate them like this:

    After 2 seconds, the first object should move down.

    After 5 seconds, the second object should move down...

    and so on.

    The way you did it, lets me not control the objects anymore...

    Hope you know what i mean...

    Kind regards

    Jogi

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