0 Favourites

How do I change image object on a function

  • 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?

  • 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 thought about it but it doesn't work on Construct2.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • It doesn't work in Construct2?

    Could you explain why it doesn't work, because I never encountered that issue..

  • 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

    }

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)