Tilemap doesn't show if no other sprite instances on layout

0 favourites
  • 9 posts
From the Asset Store
Enchanted Forest & Cave 16x16 Tilemap with Environment Sprites
  • Basically, the statement above. I am testing with several capx (from me and from many examples on tutorials and posts) and it always happens the same.

    When having a Tilemap, it shows up correctly on the layout. But at preview, if no other sprite instance is inserted on the project (not at runtime), tilemap never shows up.

    This is an example of mine, but you can try with any project woth a tilemap and some sprite.

    1drv.ms/u/s!AojCIgmN1VlPiXHgVYT1aGqqT9-6

    If you delete the troop, arrow and line which are outside the viewport and then prev, screen is blank (black, actually :p). Were any of them onto the layout, tilemap shows up as it should.

    Maybe I am missing some point on how tilemap works? Or some parameter I didn't notice had to be set up on the properties bar?

    I know it could be worked around by adding a destroy action into the first event, since I do know they all have IID 0, due to being the first ones created. But it's a bit odd.

  • First, your project is in C3, and you are posting in C2 forum.

    Secondly, I can't open your project, getting "Failed to open" error. Probably because of the MoveTo addon, try removing it and re-uploading the file.

    Also, your project is using Construct 3 runtime, where did you get MoveTo addon compatible with C3 runtime?? I thought there are no addons for C3 runtime available yet.

  • dop2000

    Sorry, I didn't notice I was posting on the wrong place. I'll ask there.

    The plugin is from chadorireborn. Some other pal told me about it when asking about plugin compatibility and linked.

    It's a public post from him/her, offering some addon ports to the community for free, so I guess- feel free to welcome MoveTo again!

    construct.net/en/forum/construct-3/plugin-sdk-10/construct-3-runtime-a-few-cons-137539

  • I can't download that plugin. You really should remove all addons from the file before posting on this forum..

  • dop2000

    Here is a pretty basic example. Just a tilemap and a sprite. No addons nor behaviours.

    1drv.ms/u/s!AojCIgmN1VlPiT9oKnbUiHXCBSpG

    The issue comes when creating objects.

    In the event sheet, I just have so far:

    On start of layout >

    Repeat 5 times >

    - create troop

    Now, the problem:

    - If there is at least 1 sprite instance on layout, tilemap shows up and those other 5 sprite instances get created.

    -If there is no other sprite instance on layout, tilemap doesn't show up at all and no object/instance is created.

    -If there is no sprite instance on layout and neither the system object creating event in the event sheet (or having it disabled), tilemap shows up (with no other sprites, for I didn't inserted on layout nor created through events).

    Possible workarounds:

    - I have to recalculate every pick and count with a -1 or +1 depending on which evaluations/comparisons are needed for the events to trigger and later on it causes several issues when adding subsequent events. Also adding some event at first to reposition that first ibstance in the way the rest are, set its same sngle, etc...

    - If I add an event to destroy that very first instance, it seems even not to create the other instances.

    - Disabling that only event (creating objects) makes tilemap shows as it should, even if the troop instance was deleted and no sprite instances are left onto the layout. But I need to have those sprites on screen, so it oblies me to insert in advanced every instance that will appear on game and keep changing visibility/opacity all the time, etc...

    Main concern:

    There is some relation between tilemaps and creating instances on layout I don't get.

    As much as I read, can't find the point I'm missing.

    Why would the existence of an instance onto the layout screen interfere with an event whose condition doesn't involve that object?

    Even worse- Why would the existence of an instance (sprite) on the layout screen interfere with the visibility of another object (tilemap) in a different layer, with no event relating them?

  • Construct requires at least 1 instance of every object to be added to any layout (in the editor). This instance is used as a reference when you are creating new instances of the same object with events. For example, if you set angle=30 to that instance, all new instances will be created with angle=30 degrees.

    If there is no "reference" instance, then Construct doesn't know how to create new instances. That's why your project doesn't work when you delete the sprite from the layout - it simply stops with an error (if you open browser console, you'll see it).

    You don't need to add that reference instance to your main game layout. A common approach is to create an unused layout called "Assets" and keep all such instances there.

    If I add an event to destroy that very first instance, it seems even not to create the other instances.

    It works if you do it like this:

  • dop2000

    Thanks very much for the explanation. It totally makes sense now. With no indenting, I was destroying at the very time of creating.

    So, may I ask, according to your experience, which way would be less likely to create incoherences for the future?

    I have tried both ways you told me and after adding all the rest of the events, they behave correctly. So I don't know which road to take.

    I am not using any IID for picking, so destroying the first instance does not make any difference, as the game runs as it should. But I might need to add some more loops to the sheet and still worried about how transitioning from and towards the layout would affect. I think this is due to my little understanding of loops and sub-events. That destroying event in the way you showed should be always the first thing to happen, no matter the rest of the event sheet, ain't it?

    On the other hand, something on my mind keeps telling me that having the 'ghost' sprite on the unused layout could affect the sprite.count at some point, when adding more events that use that trigger (have already a boolean variable instance and a pick by comparison for that). I have lots of conditions like "when every instance is locked", "when there are no available instances left", "when every instance is on their variable position", ... some 'for each' loops,...

    I'm trying to find on the web whether the triggers, loops, picks and counts takes into account every layout or not, with no result so far. Layers are mentioned everywhere, yet not layouts. Now reading about layouts to find out. Anyway, I guess by your words that it only checks active layout. So I would be worrying about nothing.

    If only taken active layout, it seems a rather stable solution, since being static and not rendered, as opposed to having some rendered instances on start, which must be removed through an event storing/deleting data into memory, managing logic and checking triggers. But I could be wrong.

    I am afraid to go on working in some fashion and then after a time realizing that will have to write back the entire event sheet because of the approach I had chosen was not right.

    So, as a practical advise for a newbie- sprite on assets layout or destroying on start ???

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Objects on an unused layout don't affect instance counters or anything else. The project is cleaner this way, and you don't have to remember to destroy such instances. So I'm using the Assets layout in most of my projects.

    Of course, there is no point in dumping everything onto the Assets layout, only put objects which you need to spawn during the runtime and which don't already exist on other layouts.

  • dop2000

    That's great!!! So, as you say, it's a rather simple, elegant and clean method. Even helps organizing sprites and clearing the layout up.

    You are my savior, man! To be honest, several of the ways I am managing my project come from your tips on different posts around the forum. I'll stop bothering you straight forward and reading more your words to others.

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