How do I change an image of an object

0 favourites
  • 5 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • I'm very new to all this and it's a lot more complicated than people make it look. So this is my goal, i'm basically just trying to make a deck of cards. But to start out the only thing i'm trying to do is have one random card drawn from the deck of cards. This should get me to the point of being able to move forward.

    What I have so far is two objects, the first object being the deck of cards, the second object being where I want the card to be placed.

    I have the deck of cards object being used as a container for all of the card images.

    I also have the deck of cards object set to being able to be drag/drop.

    With this I made it so that when the deck of cards object is dragged to the placement object it will destroy this card and create a new deck of cards object at it's original location.

    My problem now is how do I make the placement object show the random card from the deck of cards.

    I have each object in the container with a different initial variable. I don't know if this was the right thing to do or not, but at this point, i'm lost as to where to go from here.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So you move a card from the deck to a destination where it is revealed as random. Then there are few ways to do it:

    • Create separate sprites with individual face and init cover animations for each card, create an object "DECK" and use it as container for each of them so they are all spawned at once and at same image point. By shuffling Z order you'll get a lot of cards on top of each other and you can drag them without destroying, just swap cover to face when it's overlapping placement zone. It's even more convenient if you plan to have two or more decks on layout, but not the best solution because all cards will be on screen simultaneously causing theoretical lags. On the other hand it may provide you extra gameplay features.

    • Use single sprite with many frames which are picked via array. Initial array should contain, for example, 52 items with value 1 which means all cards are present. When a card is drawn - a random item with value 1 is chosen and set to 0. By inverting the array you may find what cards are on another side. If you are using animations - then dictionaries are more preferable since you are referring to animation names as strings.

    • Here's also a lazy way to manage cards - just upload all images to the project and have two arrays with their names as values, initial one with everything in it and second, empty on start, where you'll transfer picked items. Use instances of single sprite with only cover image. Whenewer a card is drawn - assign random picture to it via "Load image from url" action using array.at(floor(random(array.count))) & ".png", then pop it in first array and add to second.

  • The second method you have seems to be what I have been trying to do. Unfortunately when it comes to using the event screen i'm at a loss as to where to begin and what to use. It's like you need coding knowledge to use this program even though it claims no coding knowledge is necessary. In order to get it to do what you need it to do, you need to know the coding behind each event option.

    I had already had made the deck a container for all the cards, they all had a variable 1 instance variable added to them and each had a different initial value. 0, 1, 2, 3, 4, etc. - Was I right as far as having to give each card a different inital value with Variable 1? Or should they all be set to the same initial value?

  • When it comes to dumb or routine actions you'll probably want to find a way to automate it. In this case it's possible with just a single card - on the trigger let application create instances for each card and apply individual variables to them in same event and then just set images according to these variables.

    Check this capx.

    I've added only 4 images, it must work with any animation named in deck array.

  • Thanks Myrmex, i'm going to take a look through this and try to make sense of it.

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