Collision between two instances of the same sprite

0 favourites
  • 3 posts
From the Asset Store
This is a Dungeon Master tool & the 1st of 12 Combat Engines from the Building Combat Engines for Browser Games workshop
  • Hey folks, my question might end up being one of those easy things that's just difficult to figure out how to search.

    I have multiple instances of a sprite with an instance variable called "Value," which is a different number for every instance. I want to make it so that when two instances of the same sprite collide, I add their values together and store it in a variable.

    How do I differentiate between the two instances of the same sprite in the "is overlapping" event? If it were two different sprites, it would be Sprite1.Value + Sprite2.Value in the resulting action, but if they are both instances of Sprite1, how do I get the value from each? (Sprite1.Value + Sprite1.Value doesn't work)

    I'd know how to do this if it were two different sprites colliding or if I were scripting it traditionally, but I'm stumped here.

    Let me know if you can help, thanks!

  • For a bit more clarification of what I mean, here's a screenshot of some debugging. The text set for Sprite0.Value is inconsistent on which instance it's pulling the variable from (sometimes it's the sprite being dragged, sometimes it's the one collided with).

    Is there a way to differentiate between these two instances in the Event sheet so that I can get both of their values?

    <img src="http://storage.wertle.com/constructQuestion.JPG" border="0" />

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can use the 'System: Pick nth instance' conditions to pick the individual sprites involved in the collision.

    +Sprite0: On collision with Sprite0
       -> Text2: Set text to "0"
       +System: Pick Sprite0 instance 0
          -> Text2: Set text to int(self.Text) + Sprite0.value
       +System: Pick Sprite0 instance 1
          -> Text2: Set text to int(self.Text) + Sprite0.value
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)