How to change an existing object with a new object.

Get help using Construct 2

Post » Sat Apr 29, 2017 2:21 am

How to change the object when we click on the objet, for example I click object A and I want to replace object A with object B when in click?
B
5
Posts: 8
Reputation: 241

Post » Sat Apr 29, 2017 2:31 am

irwandwiyanto wrote:How to change the object when we click on the objet, for example I click object A and I want to replace object A with object B when in click?



do you need them to be two separate objects? if not this it may help

https://www.dropbox.com/s/fx83pgmokj1dspa/ChangeObject.capx?dl=0
B
40
S
22
G
81
Posts: 297
Reputation: 44,735

Post » Sat Apr 29, 2017 11:19 am

@irwandwiyanto Adding to @tarek2's solution, you can also swap the animation or destroy the first object and spawn the second object in its place:

https://www.dropbox.com/s/1sd6pvw1iwtkk ... .capx?dl=0

One thing to be careful of: if you use the destroy/spawn solution and the second object is also set up to swap for a third object, then your initial click may also trigger the second object. A way around that happening is to add an instance boolean to the object (e.g. isActive), and set it to true after a slight delay when the objected is created, then on the check for clicking the object also check if isActive true.
B
20
S
9
G
4
Posts: 473
Reputation: 4,260

Post » Sat Apr 29, 2017 1:45 pm

thanks all it's ok and run, but how if click object show random object
B
5
Posts: 8
Reputation: 241

Post » Sat Apr 29, 2017 2:12 pm

@irwandwiyanto

If you are using the swap animationFrame/animation method instead of setting to a specific frame use the "choose" expression e.g. set animation to choose("A","B","C") or set animationFrame to (0,1,2,3).

If you are spawning a new object you'll need to use a local variable:

On object clicked set local variable to choose(0,1,2,3)
>If local variable = 0 spawn object A
>If local variable = 1 spawn object B
etc.
B
20
S
9
G
4
Posts: 473
Reputation: 4,260


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 21 guests