BUG with JSON?

  • Hello, in this program the variable Z of the sprite does not recover the value with which it is saved in JSON.

    The sprite should not be destroyed.

    The sprite is destroyed because its variable Z does not match the state saved in JSON.

    https://www.dropbox.com/s/mr9ec14ekmubbg2/testJSON.capx?dl=0

    If this is a bug and someone wants to report it, then you can use my capx file, I do not speak English and it is complicated to fill out a report so that it is understandable.

  • Please, can anyone give a review to this?

    Is it a bug that can be solved ?.

  • You can look at the json to see what's different. I imagine the uid of an object is part of the json but it's not used when loading.

  • You can look at the json to see what's different. I imagine the uid of an object is part of the json but it's not used when loading.

    The problema is the variable "zi", this is Z INDEX.

    When the state is loaded in JSON the variable ZI is not assigned then the difference occurs.

  • Well, the z index is probably something that isn't loaded either. I mean no two objects can have the same z index.

  • But this causes me a problem, I need this value to be saved and assigned correctly.

    I'll check if this has a solution.

    The variable ZI is saved in JSON but then it is not assigned correctly and the difference occurs.

    The UID is not saved in JSON.

  • A new instance cannot have the same Z as another already existing.

    Otherwise you could not precisely order instances in the Z Order Bar.

    I don't think this is a bug.

    @Ashley, Nepeo, DiegoM any of you guys could confirm this theory please ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So the utility of saving the variable zi in JSON is questionable.

  • I don't think it's a bug. As mentioned, you can't create two instances at the same Z index, so it doesn't try to restore it. For example if you didn't have the 'Destroy' action then it's impossible to restore the correct Z index when you create another instance. It's also not possible to restore if you save it with a Z index of something like 100, but there are only 10 instances.

    One workaround could be to save the Z index to an instance variable and figure out how you want to deal with these edge cases after loading the instance.

  • Ok well I think I have a solution but the truth is that I find it a bit useless what happens with Z Index.

    Currently you can not compare states in JSON because Z Index does not match and the status will always be different in my case.

  • Hello, why does the sprite not recover its initial Z ?.

    Initially the sprite was behind the other sprites but although I reorder its ZIndex, now the sprite appears in front.

    https://www.dropbox.com/s/amvfnuxteajdjwl/testJSON2.capx?dl=0

  • I think it's because you're not sorting the other two purple Sprites along with the blue Sprite.

    If you put Sprite and Sprite2 into a family, and then apply the ZIndex based on your variable, and then sort the family, you should get the expected result.

  • I think it's because you're not sorting the other two purple Sprites along with the blue Sprite.

    If you put Sprite and Sprite2 into a family, and then apply the ZIndex based on your variable, and then sort the family, you should get the expected result.

    But I have objects of various types.

    Tilemap and sprites.

    Would I have to create families for everything just to order the Z axis ?.

  • I think Families can only hold one type of object, so sorting via the System plugin is limited to that. Are you saying that, for example, a Tilemap object can be on top of a Sprite?

    If so, the only thing I can think of is to use Rex's ZSorter, which enables you to sort for the whole layer. However, I myself haven't tried this with multiple object types but I think it might work. You also must use the Sort by Function feature, as you are using instance variables as a basis for sorting. However, in my experience, ZSorter is slower than C2's sorter.

    You may want to compromise mixing object types and keep it simply to Sprites when it comes to sorting. Let Tilemaps sit on the bottom or at the top, and not in between.

    On the other hand, if you had a simple situation where you had a TilemapSortFamily and a SpriteSortFamily, then perhaps you can do a System sort on the SpriteSortFamily first, and then loop through the TilemapSortFamily which checks each SpriteSortFamily's z-index. Then if it finds the proper z-index to insert itself you can 'Move to object > SpriteSortFamily > In front/behind'.

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