2 instances, same object type, 2 different vectors

0 favourites
  • 4 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I am trying to solve an issue, for 3 hours straight and seem to be getting nowhere.

    Im not sure if this can be achieved thus I decided to ask here all you gurus.

    I have 2 instances of the same object type, lets say 2 balls.

    Both are spawned randomly, at 2 different locations, one on left half of the screen the other on the right half.

    So far so good.

    Now comes the tricky part.

    Is it possible, in order to save memory to spawn the ball on the left side of the screen to always move right, and the ball on the right side on the screen to always move left, all using 2 instances of same object type, no behaviours and done in events?

    Ive been trying to find some sort of variable that could be manipulated from withing the event sheets, that could be manipulated seperately for each instance that has been created.

    Ive tried families, but manipulating family instances from the event sheets cant focus on one instance, rather changes all the values for all the instances when manipulated.

    I worked some time ago in another program smillar to Construct2 (will not mention which one for obvious reasons), and what I did there is I managed to add each instance created to a list, and name each instance seperately as it was created. In that way I was able to call out by name each instance and get a hold of each instance seperately (the list wasnt long, it had 5 places and the instances that left the screen had been removed from that list).

    Either this is very easy and Im getting tired and my mind isnt working anymore, or its hard and the only solution is to create another object type of that object which travels right, and give it another variable seperate from that instance that travels left.

    In Construct 2 I find it tricky to get a "hold" of a "unique" instance to be able manipulate only it from directly from event sheet once it was loaded by events.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Either of the following would work. Either you just specify what way you want the object to do when you create it, or you can pick it by "pick nth instance" or "pick by uid" or something.

    Start of layout:
    --- create: ball at (random(320),random(480))
    --- ball: set angle to 0
    --- create: ball at (random(320,640),random(480))
    --- ball: set angle to 180
    
    every tick:
    --- ball: move forward 100*dt pixels[/code:26fx4ael]
    
    [code:26fx4ael]Start of layout:
    --- ball: destroy
    --- create: ball at (random(320),random(480))
    --- create: ball at (random(320,640),random(480))
    
    system: pick 0 instance of ball
    --- ball: set x to self.x+100*dt
    
    system: pick 1 instance of ball
    --- ball: set x to self.x-100*dt[/code:26fx4ael]
  • R0J0hound

    Wow brilliant!

    Regarding the uid, that is unique so its 1 per instance, how can one get the uid of an object when an object has been spawned inside a game for the nth time?

    Once again thanks for the help!

  • The uid is unique per object. You can find what a created object's uid is with the .uid expression of the object. The new object is picked for the rest of that event or until another create action.

    Every 1 seconds

    --- create: Sprite at (random(100),random(100))

    --- text: set text to Sprite.uid

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