How do I spawn different objects from same image point?

Get help using Construct 2

Post » Wed Jun 17, 2015 9:42 am

Hello. This is my first post here asking for help. I'm new to programming, but Construct 2 is inviting and I love the wealth of resources posted to this site and youtube, etc.

Here's my issue:

I am creating a game where a gun shoots different types of balls (ping pong, basketballs, beachballs, etc). The ammo types (balls) are displayed in a column in the UI, and the player selects the ball type by moving a square sprite ("BallSelector") over the desired ball (the BallSelector snaps into place using the ball-obects x,y coordinates).

My ultimate goal is to have the same gun spawn (i.e. shoot) whichever ball type is selected by the BallSelector. My thought would be that I could use the "on overlap" condition to have Construct 2 figure out what type of ball the BallSelector is on and then pass that info along to the gun to spawn this object when fired. However, I am not finding how to do this very intuitive. I have tried using families but only get the gun firing random objects from the family randomly. The core of my issue seems to be a general lack of understanding how the read an objects "ID" and then issue a spawn command based on that ID. Again, I am very new to this, and ANY help is appreciated. Thank you!
B
6
S
2
Posts: 7
Reputation: 478

Post » Wed Jun 17, 2015 10:05 am

Give each ball a ID, and create a variable to have the ID of the selected ball.

Every time the player shoots check the value of the variable and spawn the ball with the same ID.

Hope this helps :D
B
17
S
7
Posts: 277
Reputation: 2,514

Post » Wed Jun 17, 2015 10:52 am

If the main difference between your projectiles is their textures, you can put them all as part of a single animation in a sprite and set the speed of the animation to 0.
From there, when creating that Sprite object, only display the frame that is the correct texture for the projectile.

Example capx r207
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
289
S
112
G
94
Posts: 7,333
Reputation: 69,293

Post » Wed Jun 17, 2015 5:58 pm

Thanks. Each ball has its own physics, so I cannot use different animation frames. :)

I suppose my problem is that I can't figure out how to do RayKi's suggestion. I use the on overlap condition with ball_family, but what actions/means read that object's ID from the family, and how (when selecting to spawn later) do I reference that ID? It seems that whenever I try to create an action to spawn anything it only gives me sprites to choose from to spawn, and I cannot figure out how to get it to spawn an object based on some value in a variable. That, and I cannot figure out how to draw an ID of an object from a family. I'm admittedly a newb, thanks for any help.
B
6
S
2
Posts: 7
Reputation: 478

Post » Wed Jun 17, 2015 11:13 pm

Ok, big THANK YOU, Kyatric. I couldn't view your file because I didn't have your version of Construct 2 installed. Once I got connected to wi-fi I was able to download, install, and view your file.

If, instead of choosing an animation frame of "Proj" object, is there a way you could demonstrate how to have different objects (Proj1, Proj2, Proj3, etc) created instead?

Thank you!
B
6
S
2
Posts: 7
Reputation: 478

Post » Thu Jun 18, 2015 9:39 am

Well your issue is actually a non-issue.
On creation of an instance you can set the parameters of the instance.
Which means that you can actually have a single object type, with several frame, that contains a physic behavior and to which, according to the selected ammo type you set the parameters of the physics behavior accordingly.

This is the same logic as demonstrated in my capx, only pushed a bit further.

Here's a new example.
As previously, the selection of the ammo type goes through the clicking on an instance of a text object, and getting a value of its variable instance.
This value is stored in the global variable "ProjTypeToShoot" that will be used when actually shooting.

In the example, instead of using the physics behavior, I've only modified the parameters of the bullet behavior, but you can notice it gives different behaviors as well and doesn't require a new object type at all.

At the moment of shooting, there is a test to see what is the value/expected ammo type to be shot. From there, for each ammo type I apply different parameters and set the appropriate texture.

I'm still convinced in your case you don't need to go for separated object types.
Also don't hesitate to post your capx publicly. No one is going to steal it, and other people can actually learn from it.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
289
S
112
G
94
Posts: 7,333
Reputation: 69,293


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot], zenox98 and 14 guests