How do I pin sprite to spawned sprite?

Get help using Construct 2

Post » Tue Feb 04, 2014 11:22 am

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!
B
5
S
1
Posts: 44
Reputation: 465

Post » Tue Feb 04, 2014 11:38 am

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....
A big fan of JavaScript.
B
76
S
20
G
74
Posts: 2,253
Reputation: 46,480

Post » Tue Feb 04, 2014 11:38 am

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 told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Feb 04, 2014 12:03 pm

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
B
5
S
1
Posts: 44
Reputation: 465

Post » Tue Feb 04, 2014 12:52 pm

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).Colludium2014-02-04 12:55:59
A big fan of JavaScript.
B
76
S
20
G
74
Posts: 2,253
Reputation: 46,480

Post » Tue Feb 04, 2014 12:54 pm

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?
B
23
S
6
G
5
Posts: 132
Reputation: 4,487

Post » Tue Feb 04, 2014 1:00 pm

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.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Wed Feb 05, 2014 11:23 am

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!
B
5
S
1
Posts: 44
Reputation: 465

Post » Wed Feb 05, 2014 7:04 pm

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 -,-
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 22 guests