Use an Array for Image Loading?

0 favourites
From the Asset Store
Elevate your games with our AI Chatbot Integration! Seamlessly connect your Construct 3 projects with GPT-4 for dynamic,
  • Hi,

    I got a layer with 500+ same size Sprites, which must be set in continued rows and columns.

    In Flash I would give a value in an array the parameter "image" and "position", like array[0][0].image = "myfolder/image.png".

    My question is, Is there a way in c2 to handle multiple Sprites in an Array?

  • Hi I'm a bit confused by your message, I'm not sure exactly what you want to do.

    Your title leads me to suggest that you want to load images in sprite during runtime. (which I believe isn't available in C2 at the moment, was in CC with an event like "Animation: set image at frame").

    But the rest of the message makes no reference to this and speaks about "handling" multiple sprites ?

    I'm a bit lost, would you care to explicit what is it that you want to achieve and the method you would like to use to achieve it ?

  • The sprites need to be loaded at runtime, because these are many sprites and they could change by file.

    But the first thing i would know, if there is a way to automatically place inserted sprites in rows an columns at specific distances, in this case the height/width of the sprites.

  • The sprites need to be loaded at runtime, because these are many sprites and they could change by file.

    As I said, this is not implemented in C2 yet I think.

    You need to have at least one sprite containing all your images.

    You could then create instances of this sprite, stop the animation and set the animation frame to the sprite you want to display.

    But the first thing i would know, if there is a way to automatically place inserted sprites in rows an columns at specific distances, in this case the height/width of the sprites.

    Automaticly as an event "Map grid", no. You would need to code some loop.

    A loop that would go through each sprite instance and position (set its X and Y) accordingly to what you tell it to. (a function referencing its row, its column and using its width and height as parameters)

    (action Sprite:Position, field X and Y)

    You could also set the animation frame to this instance to display the image you want.

    Is a tile map what you have in head ?

  • So the duplicated Sprites do have instance numbers? That would help a lot! I am new at construct, could you tell me how to access an instance of a Sprite for the loop?

    And I could make the map with the Tile Editor too, yes. But I think c2 does not support these maps at this time.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You have the event System:Pick the nth instance self explanatory in which actions you code will only affect the one object (sprite in our case) picked.

    Else I will link you to Ashley's post which explained me how C2 handles events and which is a good post to bookmark ^^

  • Thanks, this help a lot.

    For creating the columns the easiest way would be a second "for each" inside the first. But how can I put a "for each" inside another one?

    (interleaved loops)

  • For each (object) will go through every instances of an object.

    For your columns, you might prefer using a "for" loop (similar to the "for" structure in many coding languages) as a subevent.

    You are asked Name (as the name for the loop), the starting and ending index.

    Use the expression "loopindex" to have the actual index in the loop.

  • So I need to put the for Each as Event, and the for as subevent of this Event? I'll try this right now.

    Another question is, is there a way to automatically set exact positions for every Sprite after they where put in? I dont speak about the ground Sprites with the for-loop. I mean that all Objects on a layer should be auto set in a raster, on dependence in which "square" x and y of the Sprite is pre-set per Drag and Drop. I hope you know what I mean, my english is not the best. :D

  • So I need to put the for Each as Event, and the for as subevent of this Event? I'll try this right now.

    Well as explained in Ashley's post, acting on an object will automaticly behave as a for each loop. So in theory you would only need the for "column" loop in which you'd have an action sprite:set position that will automaticly apply for each instances of this sprite.

    Another question is, is there a way to automatically set exact positions for every Sprite after they where put in? I dont speak about the ground Sprites with the for-loop. I mean that all Objects on a layer should be auto set in a raster, on dependence in which "square" x and y of the Sprite is pre-set per Drag and Drop. I hope you know what I mean, my english is not the best. :D

    I'm sorry I'm lost there. ^^

    From what we've talked so far I guess that you have a full grid of sprites (those we've been making so far) and you would like to use some of them as reference point on top of which other elements (different sprites) will be draged/dropped ?

    So far C2 hasn't a Drag/drop plugin yet (unlike CC) so to have such a behavior you would have to emulate it in code. (code the interaction between the events of the object mouse and some destination sprite).

    But maybe I'm missing the point. Try to explain what you want to do step by step. Also what is your language ? I speak French, English and a bit of German.

  • I am from Germany. At this Point Thanks for your fast support. :)

    Made the ground now as tiled background, and as a symbolic grid. On the ground are many (transparent) PNG's on the upper layer. These are so much, that it would take too long to arrange them manually with click->x,y.

    I am gonna try this with an array. In the array I set the square postitions. Then I check for every sprite instance if it's near the upper left position of any square to be pointed at listed in the array. I think this is the best solution until tiled maps are supported.

  • X and Y positions are the dot in the middle of your sprite (not it's left upper corner)

    You should try to post a .capx with some comments in it I think. That would help me visualize what you are up to.

    EDIT: More about arrays and loops

  • Are you looking for something like this ?

    I create 100 tiles with a simple repeat and then order them in a 10x10 grid layout using 3 different (but similar) ways.

  • That helps a lot, Thanks! :)

    I did put the coordinates in an Array before, to use them later again for checking the nearest position to the square midpoints.

    But how can I access the single values now in this filled array? It is one-Dimensional and has 2 "Instance Variables", in which I hope they are the values for EVERY element, not for the whole array. ^^ If its global I dont see a way to solve this problem.

    (If I made this, I will create a little Tutorial about adjustment with nooby-placed objects. :D )

    <img src="http://85.214.39.20/shared/arrayAccess.jpg" border="0" />

  • What exactly are you storing inside the array ?

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