Fill Array with Sprites

0 favourites
From the Asset Store
An educational game for Fill in the Blanks. An easy to use template for developers to build larger games
  • rojohound thanks for your reply. Ive tried it with the pick by comparsion event and settet to each footstep a persist behaviour. Works well - thanks for this! If we currently talking about this case ive got another question (of course ).

    So now i got all my footsteps with their special footstep.IID - thats cool but now i want to fire events on special footstep1.IID´s position. Lets say Ive reached the footstep 5 and i want to start an event on its X and Y location. Something like a speech bubble which pop´s up right next to this position.

    My Function is: System -> nextFootstep = 5 -> Create object "Speech Bubble" on layer X at (footstep1.IID.X, footstep1.IID.Y)

    Now i cant use footstep1.IID.X to specify on which coordinate iam on the stage. It would be great if i could use something like get footstep1.IID(5).X or footstep1.IID(5).Y and create the object with an offset nearby. Basically the Coordinates of the current footsteps are needed.

    Should i use an array to store the coordinates of each footstep - or would there be a smarter solution whitout using an array? (Like we did)

    I hope you can understand my description.

    Thanks to you!

  • All Just another question: Ive got objects which i disabled on one layout (ingame). Now iam trying to enable them again from my menu layout (reset button) but this does not effect. Is there a special thing i have to pay attention for? Like communication between layers or something for objects?.

    on the reset functioin iam using: For each footstep1/2/3/4 order by 0 ascending -> Set collisions enabled. (Ive tried some other events to lick pick all or only a for loop etc.)

    Thank you!

  • The general way to use values from a particular instance is to pick it with a condition the footsteps1.x will be the X of the one that's picked.

    You could also not use picking and use footsteps1(5).x to get the X of the fifth instance. But picking is probably easier to read.

    You can use an array of you like, I mean if it's easier to understand. It probably isn't needed though since the object list can be thought of as an array too. Reading the manual sections on how events work could be a useful reference.

    Generally you need global variables or global objects to pass information between layouts. The persist behavior saves an objects state so it's the same if you leave a layout and come back. If the events are overwriting the state then you'd need to rework the logic of the event sheet.

    The overall logic of your game should be pretty much the same as if you made it in any other language. My solutions are probably too terse to be useful since the logic is obscured away so it's not obvious to others.

  • rojohound - thanks again .

    Ive a book as background, and on this ive placed some symbols (sprites). Now to the question: Is there a simple way to make something like a hierachy? I mean if i blend out the book, the symbols have to blend out too. Or do i have to make an event for each symbol on this book too?

    In unity for example - it works if i blend in/out the parent object, it effects the child objects too. So thats basically it. Maybe there is a possability i havent found yet.

    Tomorrow i will create an array to set each symbol active or inactive - it depends on if this symbol was found or not. but if i open or shut the inventory book, the symobls have to appear/disappear too.

    Thank you very much!

  • 99Instances2Go


    Hey guys!

    Ive got another big problem...i run into - and i hope you can help me out with this. At first i should descripe my layout to make it more clear.

    Ive got a level_1 layout. This layout has a size with 11800x6600 px. The window size is 1180x660px. The layout got 10 differend layers, filled with sprites. All of them, except the first layer (this is my gui layer) got a parallax with 100,100 to keep scrolling possible.

    Basically this level is splitted into two possible perspectives. The first is the map mode. The other is the search mode.

    Right at the beginning "On start of layout" iam scaling all this dynamic layers to 0.1 to get the complete stage visible (this is the map mode). My goal: If the player is touching to a specific position, the camera (or better the dynamic layers) should scroll to this position and zooming in at the same time. Ive written two differend events. One for touch input in map mode and one for touch input for the search mode. If iam in map mode, the search mode input is deactivated and vice versa.

    So now to my question:

    Iam using Touch.X / Touch.Y inputs for both modes (Touch.AbsoluteX/Touch.AbsoluteY doesnt work, because i would need the world space, not the screen space (i think)). To zoom onto a specific position doesnt work. At the moment i can zoom in and out (from 0.1 to a scale factor of 1 and vice versa). this works great. But i dont get it to find a solution how to scroll onto the right position when iam switching from the map mode into the search mode.

    Does someone got an idea how to handle this? Or maybe an excample for this kind of problem? Iam absolutly clueless right now, because ive tried so many differend things (scroll to behaviour and and and). But if iam using this option, my target camera objects got an weird parallax/offset.....and......lets forget about this... i think i need the right formula for handling positions, if i got a scalefactor on my layers or something like that.

    Every solution would be great. Sorry for the long post. If you need more informations, please tell me.

    Summary of my problem: (to make it more understandable )

    large stage (11800 x 6600), window size (1180 x 6600)

    scrolling and zooming in/out depends on mode.

    If mapmode to searchmode: Zoom in from scalefactor 0.1 to 1 (for all dynamic layers)

    If searchmode to mapmode: Zoom out from scalefactor 1 to 0.1 (for all dynamic layers)

    if you are in mapmode and youre taping for example to the coordinate 7545x, 3456y - the window should zoom and scroll to this position. (smooth camera movement that would be important)

    if you are in the searchmode (high zoom level) there should be only small position transitions (all touches you do right in the window canvas (tap and scroll to position nearby, tap and scroll to position nearby and so on)). The small camera movements should be also smooth.

    Thats basically it.....this thing is driving me crazy, i hope you can help me out!

    Thank you very much for your awesome support in this community!

  • Expressions :



    XAt(index, "layer")

    YAt(index, "layer")

    XForID(id, "layer")

    YForID(id, "layer")

    Return the current position of a touch in layout co-ordinates, with scrolling, scaling and rotation taken in to account for the given layer. The layer can be identified either by a string of its name or its zero-based index (e.g. Touch.X(0)). The At expressions can return the position of any touch on a layer given its zero-based index, and the ForID expressions return the position of a touch with a specific ID.

    Richard, instead of using Touch.AbsoluteX and Touch.AbsoluteY, have you tried using Touch.X("HUD") and Touch.Y("HUD")? These give you X and Y co-ords that are adjusted for the scale, parallax, etc. of the specified layer ("HUD" in this case?

    Here is a capx that works (I think) ... nnett.capx

    Docs on the touch object including the Touch.X("Layer") and Touch.Y("Layer") functions can be found here.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 99Instances2Go OMG! I didnt knowed i could do that! This my incredible friend - solved my problem! THANK YOU SO MUCH!

    I can now check the Background Layer, and because of my fix stage size (11800x6600) iam able to get the real world co-ordinates based on this size (not the scale world co-ordinates like before and wich didnt where matching for the two game modes). Now my zoom works and it gets on the damn right position! AWESOME AWESOME AWESOME!

    Thats the thing i was talking about at my very first post (or one of the following): Lerning from the best! 99Instances2Go

  • Okay of course iam now on the next step. And again - its a little bit weird.


    After my zoom in i set the clicked world space coordinate to Touch_X_Old and Touch_Y_Old, to save the touch position i zoomed in (this works fine). The camera zoomes in and now iam on the search view.

    Now to my search Input problem:

    On any touch end -> i set Touch_X and Touch_Y to the current position. (The position is inside my window screen, so lets say on the map view i was touching the point 3500x 3500y and iam on this place right now and iam touching nearby, for excample to 4000x 4000x). The camera should move smooth to this location - but it makes weird things.

    My setup:

    Touch_X_Old/Touch_Y_Old are the position co-ordinates i get from my map view (witch zoomed into search view right now)

    Touch_X and Touch_Y will be set if i fire the touch end event. So far so good - i got two positions - the Touch_X/Y and the Touch_X/Y_Old positions. Now i sould be able to set up a simple lerp function right?

    Here it is: On every tick -> System -> distance(Touch_X_Old, Touch_Y_Old, Touch_X, Touch_Y) > 20 ->->-> Scroll to (lerp(Touch_X_Old, Touch_X, 0.5), lerp(Touch_Y_Old, Touch_Y, 0.5). If i remove the distance check it doesnt move ... so i think my lerp function is the problem....

    Then: On every tick -> System -> distance(Touch_X_Old, Touch_Y_Old, Touch_X, Touch_Y) < 20 -> Set Touch_X_Old to Touch_X and Set Touch_Y_Old to Touch_Y (If the distance is smaller than 20 i have to set the current Touch_X/Y to Touch_X/Y_Old for the next scroll right?)

    And basically thats it...but this doesnt work. What is wrong with this events? Ive removed the distance check to see if the lerp function works - but this isnt the case...and i dont know why.

    Be a wizard again 99Instances2Go (or others)

    Much of thanks!

  • I have a lot of things to tell you.

    Starting with Delta-time. Speed = distance/time. If you move something pixel by pixel/tick, it will move faster on fast machines. That is because on fast machines the time a tick takes is shorter. As a result there are more ticks in a second. And so, it moves 'the thing' more pixels in a second. If you dont care for that. No problem. But it is just courtesy towards to player to account for that. In the expressions you will find the expressin 'dt'. Want to know what it stand for, search for Delta-time. But the use is simple, in a lerp that would be ...


    All behaviors are Delta-time corrected by default.

    About A & B. A is in fact the start value. B is the end value. And both should be static. If not, the lerp will not reach the end. Because, see. It devides A to B with steps. The result of that is the distance it moves. But if A is getting closer to B in the mean while, you just devide a shortening distance by the same steps. So it moves less and less and less, not ever reaching the end. You will see this, when the lerp is almost done, there gonna be a lot of 'wringle' happen in the pixels. You can solve this by checking the distance from A to B while you lerp. If the distance is less than 4 pixels, dont lerp. But that is not the best solution. Later more.

    About the touch x/y. The camera looks at a certain point. To move the camera, you move that point. But, the camera is never ever (maybe once in year) looking at the point the player is touching the screen. You just want the camera to move from current position to the end of the touch. But next touch, the player will not start touching on exactly the point where he stopped touching before. The player is not touching the point where the camera is looking at.

    Now, the point where the camera is looking at, you will find in the expressions scrollx & scrolly. What you want to do is scroll from that point the the X&Y from the touch on touch end.

    We need 4 variables (or an array, you know how easy that is by now) startX, startY, endX & endY.

    On touch end you set startY to scrolly and startX to scrolly.

    Also on touch end you set endX to touch.X and endY to touch.Y.

    Now the lerp is ...



    As long as there is no touch end happening those are static, not changing.

    Is there a new touch end, the point where camera is right on that moment, is updated, the destination (touchX/Y) is updated. And again they are static for a while. No 'cant reach the distination' problems.

    Still suprised you understand my English.

  • 99Instances2Go Thank you very much again and again and again for your description ive made a screenshot of my event_sheet how it works for me:

    (ive to less reputation points to post an url and if i use the image-url function the file does not appear - so there is a snippet of the link you would have to copy paste)

    Thank you!

  • Edit:

    Dude, i have no idea why i wrote all this, i think i reacted on an old post. Deeply sorry, to proud to just all delete it.

    Tired from work i guess.

    I dont recall using visible/invisible in any of the examples i gave you. I do recall using 1 sprite with all items as a frame in an animation, and a empty frame (frame zero) to represent the 'not found yet' condition, for the book. That simplified a lot of things, including the situation where you would decided to use an array.

    I have no idea how you do this now, iffen you talk about setting an object visible/invisible.

    The sprite.IID is an index. An index means a position in a list. All lists in construct are zero based. Wich list ? In case of the IID it is the position of a sprite in the picklist. If you made footsteps in the layout, and you made them in order, then, when you pick them all, the IDD returns that order. So IID zero is the first one you made in the layout, IDD 1 is the second one you made ... and so on. Hence, you have to create them in the right order.

    Again stressing this 'picklist'. Would you pick the steps that are 'visible', then you make a total other picklist. With other (probaly less) objects in that list. So, those picked objects have another IDD.

    The same objects are in another position (in the picklist) when you 'pick all' compared to 'pick visible'. See it this way. There are 10 appels on the table. When you take them all, you 10 apples picked. If you make a list of those 10 apples, then this list contains 10 apples and each apple is in a postion in the list = IDD. Now if you take only the last 5 apples. You have 5 apples picked, and the apple that was in the list on position 4 when all apples picked is now on position zero.

    In short: IDD depends on wich objects are picked.

    For your collectables, if they are in the new layout made in a differend order, then they have differend IID's in both layouts, when you pick them all. That is probaly your first problem.

    The easy way to go with this is like .... Make a start layout with all the global objects in, on dedicated layers. Global objects !. And just go to the first game layout. The global objects will go with you. For the collectables, this the solution. All collectables must be in that 'start layout'.

    But that means also that you have place each object in an event. Better is to drop the IID construction. And give each instance a instance variable with a unique number. And use that to identify it.

    The book and its sprites must be global. If you use no array, the book does not need to updated when changing layout. Its just fine.

    When using a global array + global objects, the book does not need to be updated when changing layout. (not to my knowledge)

    About the array. Getting things out of it.

    First you must understand that an array is a list. Lists go with indexes. A value sits on a certain index. The index is in the form of city,street,housenumber (x,y,z). The value can be number (3 dogs living there). Or a string ("Lukaku" living there)

    Forget the z. You wil kinda never need to use it. So from now on i speak about x,y.

    Now, the X axis is any position in the array (number,zero)

    (7,0) lays on the X-axis. So does (12,0) and (9999,0).

    As you see, the X-as is using the zero index on the Y-axis. Or, an array containing only values on the X-as (1Dimensional) must have a size of (amount of x,1,1).

    This is what you have, and there is no room for additional values on the Y-position. I do not talk about the Y-axis, because using the term Y-axis has only sense in a 3D array, when (ofcourse) the Y position is using the zero position of the Z-position.

    So we talk about the X-axis and about Y-postions. X-axis any position in the array where the Y-positon is zero (x,0).

    X-axis and Y position.

    So if you want to store values on Y-positions, the size of the array must be (amount of x, amount of y + 1). Else there is no (5,1) or (5,7) or (5,9999) available. (5,0) = de X-axis.

    Why is this importand ? Because we usaly want to loop on the X-axis. We usaly want to push and pull on the X-axis.

    Okay, back to index and value. To start with the expressions. There are expressions for values. And there are expressions for the index.

    For the in index ....




    The current zero-based index for each dimension in a For each element loop.

    For the value ....


    At(X, Y)

    At(X, Y, Z)

    Retrieve a value at a position in the array. Indices are zero-based. Reading values outside the array returns the number 0. If the Y or Z indices are not provided then 0 is used.

    CurX has only a meaning when using a array > 'For each element' loop condition. CurY and curZ i only use when dealing wit a 3D array.

    So, when you use the loop 'For each element X', this loop is running over each POSITION on the x-axis.

    The expression CurX returns the position where the loop is at that moment.

    So the value is at Array.At(CurX,Y-position)

    But you can use any loop. If you have instances with a instance variable containing a number (dont forget first number should be zero, not 1) then you can ....

    For Each Ordered (by that instance variable)

    The value is now at Array.At(sprite.instancevariable,Y-positon)

    You can use a regular For loop.

    From "i" 0 to sprite.count - 1

    value = Array.At(loopindex("i"),Y-positon)

    pick nth instance .. n = (loopindex("i"))

    action ... set sprite.somevariable to value

    But you dont need a loop to retreive one item from the array.

    The value is just at Array.At(X-position,Y-postion)

    Storing in the array is just the same. Same conditions, only now we need ACTIONS.

    You can use a regular For loop.

    From "i" 0 to sprite.count - 1

    Set at XY ... x =loopindex("i") ... y =Y-positon ... value = the value you want to store

    Or a For Each Ordered (by that instance variable)

    Set at XY ... x =sprite.instancevariable ... y =Y-positon ... value = value you want to store

    Or just, with no loop

    Set at XY ... x = X-position ... y =Y-positon ... value = value you want to store

    Hope this clears some things out so you can manage what you want to. I have no idea what you are actual dooing. But i see that the size of your array is to small. And i see that you try to set the 'numbers' or the 'IDD' on the Y-Axis, and that will make it to complicated, also for me.

    If you want a numberd list, trow them in the X-axis (x,zero).

    Any other value goes on the Y-position. (x,y-position)

  • 99Instances2Go wooooooooooohow that was unexpected

    There is one last thing remaining iam onto code for this game. The last step. After your supprot iam much better in understanding the tools and events in construct2 thanks for that!

    Basically level_1 is done. This is the level, where you have to find the footsteps and fill your inventary book with some informations (or random events) you can collect durring the playtrough.

    Currently iam on level_2. In this level you have to find the right path trough a cave. This cave has 3 "doors" you can choose. Basically level_2 is splittet into 3 Rounds. In round 1 you got one symbol on each "door". in round 2 you got 2 symbols on each door and of course in round 3 you got 3 symbols on each door. In each round, there is only one symbol, which is the right one. Therefore you can check your inventary book to compare the complete symbols with eachother.

    Iam writing down the tasks, maybe you got an idea how to handle this straigth (like you did before on the other tasks, i had problems with (Thanks again for your awesome support by the way) )


    Ive created spawning areas (sprites) whit its dimensions are dynamicaly changable. Inside this areas the symbols should spawn, so when i change the size or the position of the sprites, the symbols will be spawn on the changed values too. This works perfectly so far - but not for the whole game logic i would need. Currently i can spawn objects i have "fixcoded" from a "non array based" event.

    Now the difficould part:

    If you want to start level 2, round 1 should set up three symbols (one on each door), which will be loaded from an array (i think now i have to use arrays (later more)). This symbols have to be spawned on each spawning sprite (i told above) on a random position (this works but like i said not with arrays but with fix coded sprites).

    But now i have to choose the sprites more "controlled" because in level 1 there is one "correct" footstep you have to follow, and on which you can find the specific symbols too. so basically there are four different footsteps, with three specific symbols you can find, and which are filled into the inventory book. One of this paths is the right one but you have to find out which one.

    in level 2 you have to find the right way, but if you didnt found the symbols, youre maybe lost, because you cant know which symbols are the right one.

    So in round 1 there will be one right symbol on a door and two false symbols on the other ones. in round 2 there are two symbols on each door, but one of them is the right one. in round 3 its basically the same thing except there are 3 symbols (and one of them is the right one - so you have to check your inventory book and compare the symbols)

    now the main thing is - you can leave level 2 to find more symbols if you didnt found them before to make you inventory book complete, but if you return in level 2 the symbols should be on the same place.


    Ive created 4 arrays.

    Array 1: My basic symbol pool: All symbols i have to use from my main sprite with the differend animation sprites (your idea ).

    Array 2 - 4: Basically the array with the specific informations about which symbol was randomly choosed, and on which position it was placed (the position should be saved and loaded, if i leve level 2 and return into because it is a different layer and a part i forgot to tell is that you cann fall back into round 1 if you fail in round 2 or 3 (because its a cave and you choosed the wrong path you will walk into nothing and start again)). But the symbols in round 1,2 and 3 should be on the same place. Thats the reason i would have to store this informations about it.

    I know its not easy to understand or may my description is not so good . But iam currently working on this task and i would be very happy if you could give me some adivices how i could solve this. Maybe your workfolw will be much more better than mine. (Iam sure it will)

    Currently iam on the step:

    Fill the Arrays for each round with baically one right sprite and two other ones.

    99Instances2Go - if this game is finished you will be one of the first gamer if you want to

    Thank you very much!

  • Ps: i use your informations you gave me in your last post for this task so its very usefull for my current task!

    ive got 12 symbols, i saved in this "array_pool" and 3 of them are the "right" symbols (symbol 1- 3). For each round i have to take out one of the "right" smybols (to avoid they will be used two times). The other symbols can appear two times on differend rounds - that wouldnt be dramatic.

    in the next round (round 2) there are only two right symbols (for example symbol 1 was used in level 1 now the system should choose between array position 1 and 2 for symbol 2 and 3). The rest symbols could be the other array slots (4 - 11 or symbol 4 to 12). In round 3 the last "right" symbol should be choosed - the rest can be filled again with the rest symbols (again array position 4 - 11 or symbol 4 to 12).

    The advanced task is to save each round like i descriped in the post before, if the player failes in one level and has to do round 1 - 3 again. puuuuuuuuuuuuuuuuuuuuuh crazy stuff....

    Thats difficould in my oppinion.

  • The symbols need numbers (instance variables) that correspondent with their framenummers. This way you have the right face by the right index in the array. On the y-positions, you store things like if they are found (1 or zero), wich level they are .... and so on.

    But also a number that correspondents with the doors. The doors (their spawners) need numbers (instance variables). All of them and unique. So, 1,2,3 for the first level. 4,5,6 for the next level.

    Now you have (on a y-postion, lets say position 1) on array(symbolnumber,1) the info that its found or not. A 1 means found. A zero means not found. If it is 1 it goes to show in the book.

    You can do the same with the doors. Say on array(symbolnumber,1) you set door number. And say, if it is a zero, the door is not chosen yet. Else it is chosen. Not chosen yet, choose. And display. ... .capx?dl=0

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