How do I create a matrix with images?

0 favourites
  • 4 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • Hi all, very new to C3. How can I make a simple 2x2 matrix that looks like tiles and each tile will have a simple image/sprite...except one. That one will be a different sprite but should be located at random location of the tile. So I'm thinking a 2D array but not sure how to link the array in memory to the sprites/images' location. I know C/C++, Python and others, but this paradigm is new to me.

    example: I want an image of a happy face (image_ repeated and shown in a tile of a 2x2 matrix. Then at a 0-index based array's random location (e.g. 0,0 at first cell once, then at 1,1), I want a sad face (image) appear. Then when the user clicks on the sad face sprite object the game does something, like score (I can do that part).

    A simple example would be VERY appreciated and make the difference between buy/not-buy.

    I need to populate the array with a for loop (I think I can figure out the loop part on the array object) but with the images (this part I'm confused about). Then pick a random location and insert (push?) an image to that random location and keep track of that specific tile (so I can track user-click on it).

    P.S. I'm trying out on free account before buying, so I can only do 2 layers max and 50 events.



  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • See this example (made in the latest beta release, execute r263 to open this file).

    I've made the array thing you asked for, but it is not required in regards to what you have described, and you can handle things through Sprites and Touch directly pretty simply.

  • Thank you Kyatric for the example. The reason I wanted array implementation is because I'd like to increase the size to say, 15x15 matrix and not have to manually put 225 tiles on the I'm hoping that I can have just 2 sprites: 1 happy, 1 sad.

    Then in a loop I'd like to create 225 (n) number of cells of the happy sprite, and just 1 cell with the sad face...the objective is to only identify a click/touch on the sad one.

    I see your example and is very helpful and will go through it more---but I wonder if tiles creation can be done for the larger matrix (maybe for-loop and createobject or cloneobject method in the loop)?

  • Hello again Kyatric, I delved into the details of the code and details of each object. Very clever! I like it. The instance variables for x,y coords associated with each tile uniquely and that each sprite's images animation frame can be accessed at will was my X factor. Well done! I think I can figure out the array part on my own from this point on if I choose to scale out at large matrices. Cheers.

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