How do I put sprites in 2D or 3D array?

0 favourites
  • 9 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hi, i have a question. i am a beginner making game on construct3 (an object finding game, mystery solving). i have 11 mysteries with 11 hints. User have to find the correct object according to the mystery in a given time and after solving one the next will appear. i haven't used arrays before but i've watched tutorials. All these mysteries and hints are sprites added seperately and i am having difficulty in putting the sprites in a 2D or 3D array. And one more thing i want to make appear the mysteries randomly , how can i use random funtion on multi-dimentional array. It would be highly appreciated if anyone can guide/help. thankyou!

  • It's not totally clear what you mean. Do you mean storing the pixel data of a Sprite in a construct array at runtime?

    If not you may need to show an example.

  • It's indeed hard to understand, but I'm guessing what you want to do is have a sprite with 11 frames. The frame number would be part of the array, and you can make them appear randomly. Just pick them by animation frame.

    You could check how to use 3D arrays for example in this tutorial on my youtube channel:

    youtu.be/fMtO7q1Wrus

    Hope that helps. Maybe some screenshots might clarify more

  • Arrays in C3 can only hold values, not objects. So to try to store sprites in an array is impossible...

    If I were going to try and put together a scene with key items placed randomly, that the player needs to spot and then click on, I would probably try this approach first:

    - have a single sprite for all the items in your game ( depending on how many there are, this may be inefficient ), then load the items for a given scene into an animation in that sprite, that way, for a single scene, you're simply creating instances of that sprite, and setting the frame of that scene's animation to match the item you want to display.

    - create those sprite instances with randomized placement ( you can randomize along a tile grid size of your choosing, all the way down to individual decimals between pixels, it depends on what you like the look of )

    - fill the array with the frame numbers (or InstanceID's) of the items you want the play to find

    - when the player clicks on an item, loop through the array to see if any of the stored values match the item clicked. If there's a match, remove the item from the scene ( I like to make things invisible rather than destroy them ) and update the player's progress ( score, items remaining, etc ), and if there's not a match, simply do nothing, or maybe penalize the player somehow ( set a timer so they can't click again until the timer is up to prevent spam clicking, or maybe have strikes where if you have a wrong click, it counts as a strike, 3 strikes and the player it out kinda thing )

    That's where I'd start. I'd only use the array to hold the values to check against when the player clicks an item. Everything else is all is stuff that can be done pretty simply at the start of a scene. Hope this helps :)

    EDIT: I just re-read the initial post and think I may have misunderstood slightly, I'll leave the original reply in case its still applicable

    If you want the array to store the mystery and hint, then I'm assuming you're simply storing text?

    eg:

    mystery = "I sit with my hands on my face"

    hint = "I'll always have time for you"

    answer = image of a clock ( this can be the animation from or InstanceID I was referring to above

    So I'd set this up so that each of these values would have its own Y coord in the array, so Y0 is all of the mysteries, Y1 is all the hints, Y2 is all the InstanceIDs of the item image you want to display.

    Then each X of the array is a different mystery. That way when a new scene starts, you can use smart random ( so it won't pick a number that's already been chosen) to select an X coord in the array, then you just look at each Y value for the different parts of the mystery itself.

    Does that help?

  • okay. there are 11 sprites of mystries in seperate layer, 11 sprites of hints ans in the background, object to find according to the mystry. what method should i use to link them up and make them functional. on the start of the level 1st mystry will appear , the user will read the mystry and click ok button to start the game (start finding the object). the count down starts when he presses ok button.he has to find the object in the given time other wise a popup will appear with "times up". he has 2 lives on the start of the game and three coins.he can buy hint with 3 coins. if he selects the correct object, he will get 2 coins in reward, but if he selects the wrong objject , he will loose one live . at zero lives the game will be over.

    now, i think i am clear. i attached the screenshot for better understanding. i've spent a lot of time to design this game, i am having difficulty in making it functional.

  • brent_hemal yes i get it what you are saying but i don't have values/ text form. i have designed sprites. how do i deal with them or should i change the whole thing.

  • If all of your in-game text are sprites, ie the text for Mystery 1 is a sprite with text in its image, etc. Then you would store them the same way I mentioned storing the item image reference in the array. So either store the frame of animation the mystery sprite needs to display in the array ( Mystery 1 = animation Frame 0, so "0" would be the value stored ) or save the object's instance UID ( sprite_Mystery.iid ) into the array ( though you'll still need to make sure to set the right frame of animation, assuming all Mysteries are saved as seperate frames within a single object ).

    Then as I mentioned before, everything you need for a given Mystery is saved in a given Y position in the array, where each X is storing all the individual parts of the Mysteries.

    So for example:

    MysteryDataArray

    X0, Y0 = "0" ( sprite_Mystery.animationFrame )

    X1, Y0 = "0" ( sprite_Hint.animationFrame )

    X2, Y0 = "0" ( sprite_SolutionItem.animationFrame )

    X3, Y0 = "5" ( sprite_incorrectItem.count )

    So what this does, is it stores the animation frame for Mystery1's mystery text object in the first X position, then it stores the animation frame for Mystery1's hint text object in the second X position, then the frame for the solution item that you need the player to click, and finally the number of "wrong" items that will appear in the scene along with the solution.

    Then when you make your scene. You'd create an instance of your mystery text sprite, and "Set animation frame = MysteryDataArray.At( 0, CurrentMystery )" ( CurrentMystery could be a global variable, or an instance variable for a separate object that keeps track of what mystery the player is on ), then repeat for the Hint and SolutionItem sprites, finally do a "Repeat X Times" loop to create and randomize the frame for the incorrectItem sprites, where X = MysteryDataArray.At( 3, CurrentMystery )

    As a side note, I'm not sure if this is helping, or just confusing you... I'm stupid busy for the next couple weeks, but after that I can look at making you an example.c3p if that would help. I'm sorry I just can't afford the time at the moment :S

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • brent_hamel yes, it is very helpful. i did that just like this and it worked. thankyou so much... it is very appreciated.

  • Awesome :) I'm so glad it helped!

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