How do I pick and count image points by name

From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • Hey wonderful people!

    I'm wondering how I can get a count of image points by name.

    Say I have a sprite with some image points named: "left_0", "left_1", "right_0", "right_1"

    I want to find how many image points that contain "left_". In this case it would be 2.

    The reason I need this is so that I can use that number in a Repeat condition to create objects.

    Things I've tried:

    • regExMatchCount on the sprite.imagePointX... but this, of course only gives me the x-coordinate of an imagePoint.

    • picking in various ways but I can't find a way to correctly reference an imagePoint

  • I don't believe it's possible to reference image points by name, only their index (maybe somebody will correct me).

    However, there will certainly be an alternative way to do what you're trying to do. Since you have to manually place the image points yourself anyway, why not add 2 instance variables to the sprite and store the count for left / right image points there? You'll know yourself if you just added four, six, or whatever points to the image, so it's just a matter of writing it down somewhere you can retrieve it later.

    I must admit to not being quite sure why you're trying to do this with image points anyway. Can you give any more information about what you're attempting to create? Perhaps we can find a better way to do it :)

  • Thanks for taking the time to answer!

    Since you have to manually place the image points yourself anyway, why not add 2 instance variables to the sprite and store the count for left / right image points there?

    Great point, and it's what I've ended up doing but it does feel a few steps removed from what I'm trying to achieve.

    Can you give any more information about what you're attempting to create? Perhaps we can find a better way to do it :)

    Sure!

    What I'm trying to create is an easy way for me to quickly specify where I want specific objects to be created based on a sprite. I want to be able to do this in as few steps as possible since I will need to repeat this for each sprite of this type that I add.

    What I'm looking to achieve:

    • I have several sprites representing spaceships.

    • Each spaceship has a number of spots where I want to create certain effects like turrets, thrusters, weapons, and so on.

    • By setting up image points on each sprite, named in a structured way I hoped to be able to create these effects by referencing the image points by name.

    Here's a screenshot of what I have right now. The main issue is the Repeat condition. Currently it's manually set to 2. Ideally it would be dynamic based on the number of image points that match a criteria.

    I'm totally open to other ways of achieving this. In my head, the imagePoint method just seemed like it would require the least steps.

    Thanks again!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ohhh, I see what you're trying to do. Okay.

    From squinting at your ship sprite in the screenshot, the thought occurs that if all of your spaceships are drawn facing in the same direction - and the origin point is set to the centre of the ship - you could determine whether an image point is to the left or right hand side of the ship pretty easily by comparing the Y coordinates.

    You know... maybe something like this?

  • Thanks! Sadly the ships will rotate freely. It's a top down game with where the ships can be at any angle. Your solution looks like it would work great for a side on game though. Again, thanks for taking the time to answer this.

  • Can you not spawn the turrets etc in the first frame when the ship is created and is in a 'neutral' pose, set the left/rights, and then attach them to the ship thereafter so that they continue to be left/right turrets even though the ship later goes on to rotate?

    In other words, always spawn ships at 0 degrees, attach the turrets to the right places, THEN set the angle to whatever you want.

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