How do I change image object on a function

Get help using Construct 2

Post » Wed Sep 03, 2014 4:34 am

I am trying to make a game where I need to change an Sprite with 6 frames with another one using a function.
In the beginning of the game the user needs to select which set of image he/she wants to use in the game.

Basically that's the idea:
function change image
if "animals" selected
change Sprite to animals
else if "blocks" selected
change Sprite to blocks
else
change Sprite to default.

The problem relies on the fact that I need to click on the Sprite image inside the function.
However, when I do what I show above it doesn't work because I don't want to duplicate the Code.
I just want to have the same code with different Sprite object.

Is it possible?
B
115
S
48
G
24
Posts: 401
Reputation: 22,177

Post » Wed Sep 03, 2014 10:52 am

Why not use a placeholder sprite and when image selected pin the animated sprite to it?

The placeholder sprite would have all the events..

Another way that comes to mind is putting all sprites in a family and having the events on the family..
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 » Thu Sep 04, 2014 5:53 am

I thought about it but it doesn't work on Construct2.
B
115
S
48
G
24
Posts: 401
Reputation: 22,177

Post » Thu Sep 04, 2014 5:57 am

It doesn't work in Construct2?
Could you explain why it doesn't work, because I never encountered that issue..
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 » Thu Sep 04, 2014 3:14 pm

The problem is that the image(s) will receive a click after it is selected in the previous screen.
Because of that, I can't use one code for all the images.
Basically I need to repeat the code for the image selected.
I thought about combining all the images using frames but the code would be too complex to make it work.

In a language like Javascript, I could do something like:
var useImage = document.getElementById("myImage").src = "landscape.jpg";

onClick (useImage) {
Do something with the image
}
B
115
S
48
G
24
Posts: 401
Reputation: 22,177


Return to How do I....?

Who is online

Users browsing this forum: stevenode and 11 guests