How do I pin sprite to spawned sprite?

0 favourites
  • 9 posts
From the Asset Store
2d mushroom sprite 2d game character enmy sprite game art
  • Hi,

    I have enemy sprites spawning every 1-4 seconds and am trying to figure out how to pin a thruster to them. Works perfectly when it's pinned to an already existing object.

    I have: For ever 1-4 seconds, spawn enemy sprite, set bullet to 90 and speed to a variable. Set thruster sprite to visible and pin to enemy sprite (Position & Angle).

    What am I doing wrong?

    Thanks heaps!

  • How do you identify which thruster you want to pin, or is there only 1 for C2 to choose from? As long as you have both identified in the same block of event code then it should work. Just a thought as well, if you're using just one thruster then you will need to reposition it after each enemy spawn.... Its hard to help without a capx to view....

  • Are you creating or spawning the thruster sprite as well?

    Are they in a container with the enemy?

    Why aren't you setting the thruster position before pinning, is it automatically at the right spot?

  • I'm not really sure, I haven't done any pinning of sprites to spawned objects. Collodium, it's just the one thruster sprite but would be spawned unlimited times. LittleStain, I looked into containers and that looks amazing except I can't see a way of positioning the extra sprites to an image point. So the thruster sprite loads but it loads smack bang in the middle of each ship sprite. Is there a way around that?

    Also, here's the capx. Any help is greatly appreciated!

    Thanks!https://www.dropbox.com/s/dib7adr7u6bseu4/Space%20Game.capx

  • OK, there are a couple of extra things you need to do and then you're done:

    1. C2 works with 0 degrees angle facing to the right, so angle all of your thruster flame images 90 deg to the right in the sprite editor.

    2. Change your space ship so that all images face to the right as well. (although these first 2 steps aren't strictly required for a simple project, this will help you when your projects become more complicated).

    3. Add a new image point to EVERY frame of the spaceship where you want the thruster to be pinned.

    3. Add 2 events in your spawn spaceship event:

         Set spaceship.angle to 90 degrees (so it faces down)

         Spaceship:spawn thruster at imagepoint 1

    That should do it. Let me know if you get stuck.

    If you set them both into a container then you won't need the spawn thruster command, but you will still need to position the thruster to imagepoint 1 before pinning it.

    Edit - the imagepoint 1 on every frame is just where the thruster will be set to. If the space ship animation frame doesn't have the imagepoint 1 when the thruster's position is set then it will move to the default instead. The pin location will then be set irrespective of where the next imagepoint 1 position is set (ie it doesn't pin to the imagepoint number, only the x,y position).

  • have you tried to trigger it with

    "on sprite spawned" -> pin thruster to it

    ?

    there is an example space shooter in C2 where they use thrusters too, have u had a look at that yet?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Keep in mind:

    As soon as you spawn ANY object, you can reference it directly in the same set of actions.

    for instance:

    actions:

    create object rocket on x,y

    rocket spawn object thruster on image point 1 //thruster image point

    thruster pin pin to rocket

    At this point the newly created rocket has its new spawned thruster pinned to itself.

  • Thanks for the help guys. I've now successfully got my thruster sprites attached (although I couldn't figure out the container option).

    However, now after I click on an enemy sprite I've added sprite3.destroy to destroy the thruster sprite when the enemy ship is destroyed. The problem is this destroys every instance of sprite3 on the screen?

    Capx is here.

    Also, would you have any tips or tricks to make this a viable commercial option? First game so any advice is appreciated! I'm adding music, sound effects, and replacing the green ground sprite with a cityscape. And will plan to sell it for free, with in-app purchases.

    Thanks heaps!

  • You could add an extra condition to the overlaps event thats triggered to destroy the rocket:

    condition : object thruster, pick nearest   rocket.X rocket.Y

    action: destroy thruster

    The container should work best though, it should destroy the thruster created with the rocket.

    Building the container is easy.

    Select the rocket, in the propperties bar click edit container, and add the thruster.

    Next when you create a rocket, the thruster is created too.

    I always use an objects layout, and place my thruster already on the position it should be. when the new rocket gets created, the thruster is already in place as I did on the objects layout. Only requiring me to pin it after creating the rocket....

    Hmm, wasnt the container a paid feature ? I forgot -,-

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