Using the same action for multiple objects

Get help using Construct 2

Post » Sat Oct 05, 2013 3:58 pm

Hello everyone, I'm new here and I need some help from you guys. I'm coding a quick demo from the old NES video game Super Mario Bros and despite everything looks kind of smooth and cool so far I cannot understand how to accomplish some feature. When Mario hits some blocks a few of them are supposed to spawn a coin which will add some points to the final score. Now I actually got it to work with the first block but if I keep using the same method with the others the coin will always be spawned in the first block only. What is the best approach to use the same animation of the first block over and over for the rest of the other blocks? I guess I should be using a function or a global variable or something rather than just copy/paste my assets.

Here is my capx file https://dl.dropboxusercontent.com/u/1481984/supermariobros.capx
Thank you all in advance!

Luca
B
2
Posts: 4
Reputation: 158

Post » Sat Oct 05, 2013 6:42 pm

two things:

- remove block2 and block3, use only block1

- block2 and block3 dont' have any actions.
B
12
S
3
G
1
Posts: 347
Reputation: 2,866

Post » Sat Oct 05, 2013 6:43 pm

for your question: how to use the same action for different objects, for that you need to use Functions (first needs to be inserted to be able to use them)
B
12
S
3
G
1
Posts: 347
Reputation: 2,866

Post » Sat Oct 05, 2013 8:36 pm

Thank you Ghost. As of now I kind of managed to achieve the spawn coin thing although I'm still in trouble with the blank block that pops in after that. The whole process should be as follows: Mario hits one block which triggers the coin spawn feature which then turns the initial block into an unusable block. Now the problem is when Mario hits any block the coin does spawn correctly but all blocks turn into blank which is clearly inconvenient.

You were previously mentioning to get the block's IID. How do I do that?

Anyway here is my updated capx
https://dl.dropboxusercontent.com/u/1481984/supermariobros.capx

Thank you very much for your help!
B
2
Posts: 4
Reputation: 158

Post » Sat Oct 05, 2013 10:25 pm

@Luca11,

There are a couple of ways you could achieve the effect you want. First, there's a subtle but important point with respect to C2's event system which is causing your problem. On line 9 where you set the blankblock visible, you are selecting all blankblocks - you need to specify a particular instance for C2 to only change an individual's characteristics.

So, you could use containers which would make this very easy (have a read of the manual and, after a bit of experimenting you'll never look back - wouldn't need any code change to your events, I think) or you could add a sub event to what you have already and pick the closest blankblock to the Block1 in the collision.

There is another method you could follow. You could have the blocks as different frames of the same sprite. Check the frame of the collision block on collision - if it's 0 spawn a coin, if it's 1 do nothing, on collision change frame to 1...
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,188

Post » Sat Oct 05, 2013 10:35 pm

Add Event > On Mario Colliding With Another Object
Condition : BlockObject > Pick by unique ID

Add Action > Spawn Coin At Co-ords

B
45
S
15
G
73
Posts: 2,006
Reputation: 43,394

Post » Sun Oct 06, 2013 5:51 am

Here's a few notes from me. I'm a complete newb to Construct 2, so there are probably better ways to do everything than the way I may suggest!

First, I noticed that your Background image was on the main layer. I moved it to the "Background" layer since I figured it belonged there.

Secondly, I noticed that your block sprites are 32x32 pixels, yet in your level they're only 25x25? I don't know if that's intentional or not, but I thought I'd mention it just in case. Also with your level layout, it's usually easier to line things up if you use the snap to grid function. (Which is another reason I mentioned the size difference from 32x32 to 25x25.)

There were also some hidden "landing_objects" placed under some of your coin blocks. I removed them since they were causing problems with the player hitting the coin boxes.

Lastly, I changed the event where the player hits the box so that it changes to the "blankblock" without you having to place both in the scene overlapping each other.

There's still some things that need to be worked out, but hopefully this gets you going in the direction you wanted to go!

https://dl.dropboxusercontent.com/u/98323832/Construct2/supermariobros-altered.capx
B
10
S
1
Posts: 12
Reputation: 476

Post » Sun Oct 06, 2013 8:30 am

Thank you guys, I really appreciate your effort to help me figure out how to do this thing! All of your suggestions seem to do the trick!

@Mcflygold

Yes, the stage was quite messy when I shared my work with the community but now it's all cleared up in pretty much the same way you suggested. I didn't realize I didn't need to overlap the blocks so thanks for that as well! :)

Now everything works correctly, I'll keep you guys posted with any improvement! :)
See ya and have a nice sunday!
B
2
Posts: 4
Reputation: 158


Return to How do I....?

Who is online

Users browsing this forum: Malhog and 18 guests