How do I spawn specific sprite from family?

Get help using Construct 2

Post » Tue Aug 05, 2014 7:48 pm

Hello,

In this capx is easy thing similar to:

Code: Select all
IF family.ItemId = 1 THEN spawn sprite from family with ItemId 1


But it works differently. It will spawn just whole family and that means it will spawn random sprite from family. Regardless on number in ItemId.

Question: is there any way how to spawn sprite with instance variable ItemId = 1 from family?
B
5
Posts: 8
Reputation: 241

Post » Tue Aug 05, 2014 8:31 pm

Sadly, Construct 2 doesn't allow you to dynamically name the sprite you want to create. I have implemented a work around using a Function. You can check it on the following .capx:

createObjects.capx

Left-click adds blue squares
Right-click adds yellow squares
Middle-click adds random item from family
You do not have the required permissions to view the files attached to this post.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
15
S
3
G
1
Posts: 329
Reputation: 2,012

Post » Tue Aug 05, 2014 8:42 pm

Thanks for reply.

Your solution works but still there is needed to specify blue and yellow sprites separatedly. If I will have 150 sprites then I need to use 150 events.

Really there isn't any other way? For example foreach all objects in family and check ItemId or foreach all completely all items or similar thing? I can't believe that such genial program like Construct 2 does not have such thing :(
B
5
Posts: 8
Reputation: 241

Post » Tue Aug 05, 2014 8:49 pm

I never understood why this wasn't supported: it seems trivial, and would be very useful. Am I missing something?
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,187

Post » Tue Aug 05, 2014 9:06 pm

Same here... I don't know why you cant create "Sprite"+id. But, unfortunately, you can't.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
15
S
3
G
1
Posts: 329
Reputation: 2,012

Post » Tue Aug 05, 2014 9:07 pm

Another work around people sometimes use is making each sprite as an animation frame for the same sprite instead. And setting the frame according to the id.

For instance. A sprite that has 150 animation frames, each with a different sprite. Or in your example, a sprite called square that has frame 0 as a blue square and frame 1 as a yellow one.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
15
S
3
G
1
Posts: 329
Reputation: 2,012

Post » Tue Aug 05, 2014 9:53 pm

There is a third party add-on "nickname". You can look that up.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Aug 07, 2014 7:53 am

Using sprite with animation frames is possible probably for display only. But if I want to display sprite with ItemId = 150 and do damage defined in that sprite then I think solution with animation frames not help. Also I need to have two same sprite images on two places and edit them on two places.

Nickname plugin looks good. It is still not best thing (you need to insert picked items into family and work with that family = same object in two places) but I think it will be still better than 150 conditions.
B
5
Posts: 8
Reputation: 241

Post » Thu Aug 07, 2014 8:20 am

rotacak wrote: (you need to insert picked items into family and work with that family = same object in two places)


Hi can you explain what you mean by this? I've just started experimenting with Nickname but there doesn't seem to be a drawback using a family this way.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Aug 07, 2014 11:14 am

codah: look at attachment. You need to have one your family (Items) but also new family (SelectedItem) with exactly same content. When you will pick one sprite and you want to do with it something (rotating...) you will access it through family SelectedItem.
You do not have the required permissions to view the files attached to this post.
B
5
Posts: 8
Reputation: 241


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], jkmalau and 13 guests