I don't get how the sprites are created

0 favourites
From the Asset Store
Tap the ball, control it, avoid touching spikes and score higher!
  • Hi!

    Not posting this in bugs, as it surely ain't one, but maybe more a weird behavior....

    Let's make things simple. Open a new project, create one sprite, draw an arrow left looking, place it on your layout.

    Add an event in your sheet to create one more arrow

    The result is, without doubt:

    Now, mirror the manually placed arrow by using a negative width. (Ban negative width? Give me another way to do it without doubling my frames and being able to see the result on the editor, meaning not having to preview the layout to see the end result)

    Without changin anything in the event sheet, just preview. Weirdly, the result is:

    Now, I say weirdly, why? Maybe it's wanted, but you have to explain it to me then. Programmatically thinking, this looks to me like a static variable conflict. Why? On the right side, we have our Project tree, with our layouts, sheets, and objects. When dragging an object in the layout, we instanciate it, create an instance of it. Thus, all it's attributes are set to the object's default. When we create through code, we do instanciate it too. If it's not that, then the whole idea is really looking like that and so are the guides talking about instances, the functions referencing to the "instance" word etc etc and that really needs semantic fix then

    So, by looking how Instance Variables and Common work, to me it looks like "Layer", "Angle", "Opacity", "Position", "Size" are declared as static in the object (where instance variables are what they are called, non static instance properties), explaining why, after setting one object's width to negative, it spreads and infects the original object. I know the category for those is called "Common", that's a sign.

    It is also easily understandable by looking at the .caproj file:

    Nothing references the base width, height etc etc

    So, anyone has a solution for me to not have my sprites flipped by default when code created if I manually placed one of them and reversed it?. Sorry, the project is very wide, and I won't add setMirrored = false, setFlipped = false and setScale 1 after every sprite creation throughout the many event sheets and sprite creations....

    Cheers!

  • The first sprite is alway a template for all others. If you deleted that sprite from the layout itself, you'll find C2 can't create any more sprites. It always needs one placed in some layout somewhere with the default settings. The common trick is to delete all default sprites in your layout and create new ones. The alternative is to place that one sprite in a utility layout that is never actually displayed. It's just one of the things you have to accept and deal with.

  • But but but, I do get that... But the instance vars aren't copied over either, so why aren't the width and Co non static also? Placing one sprite in a fallback layout is what we do too, but the ones created/manually placed in other layouts took over...

  • What I did to overcome this now is:

    Add to those sprites an instance variable called "layoutPlaced" with default to false.

    When manually creating a layout and placing one of these sprites, we set it to true

    In a super sheet, I do "onCreated / if not layoutPlace setScale 1 setMirrored false setFlipped false"

    This way, all the code generated sprites do fall into that condition and get defaulted where all the manually placed ones stay as we did place them

  • Exactly what blackhornet said. The first sprite created is the main sprite that all instances copy default atributes from. If you notice, in your example, if you change the right sprite's width instead of the left one, only it will rotate.

    When you tell C2 to "create a new object" it really just copies the object from this first instance to use on the others.

    Now, instead of coding you can just create a new layout called "repository" (or whatever you want it to be called) and have the first instance of your sprites be there (to be sure they're the first instance you'll have to delete all other instances from your project). I do this for all my games and I always recommend it.

    After that you can just copy it to any layout you want, while editing it.

    Alternately you can also pick objects by their IID (instance ID), meaning that in your example, the arrow on the left has IID = 0 and the arrow on the right has IID = 1. So if you do something like "pick sprite where sprite.IID = 0" it will pick the arrow on the left.

  • And how exactly is the first instance defined? Is it the one with the lowest UID? Because after a couple of tries, this is not the case...

    I added one of the sprite on a placeholder layout, I manually opened the layouts xml file, made sure this new element gets the UID 0 by swapping with another one in another layout. Still, the problem persists. Even instance variables are copied over, that's totally not ok, they are not to be called instance variables in that case

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • wait so you are saying that if you set the width of the arrow to negative width its not mirroring it anymore?

    cause that is weird... i had made a card flip based on that and using the same inputs and it worked... you sure isn't something you have in the code that stops you from doing that? like setting the width and height to a surtain value everytick(or a Boolean that is always on which acts like everytick basically) ?

    let me test it first though il be right back. im using R240 atm hope you can open it.

  • No, I'm saying that even if the very first created sprite in my project has the default width set positively and is scaled 1:1, the code generated ones spawn reverted. The code generated ones even take the instance variable values from another sprite placed somewhere else, dunno which, but not the very first one. So it's not taking the very first created sprite, but some random others

  • No, I'm saying that even if the very first created sprite in my project has the default width set positively and is scaled 1:1, the code generated ones spawn reverted. The code generated ones even take the instance variable values from another sprite placed somewhere else, dunno which, but not the very first one. So it's not taking the very first created sprite, but some random others

    ah yes now i see ...

    i think was mentioned before...

    i seen this problem myself also but its not really a problem but more of the ordinary things that where not needed to be fixed i guess cause seemed natural, and no1 complained/or everybody got used with it as in my case.

    what i seen is this: when you first place your sprite object in a layout,that is usually deleted on start of layout unless its the main player and u actually use it from the visual editor placement,

    anyway that very first sprite is affecting every other future code generated of same sprites for example if you first create a fish .. and on start of layout you delete it cause you dont need it...

    then you go create a random number of them doesn't matter under what condition... the new fish created will be exact copies as the one that got destroyed upon removal/ start of layout cleanup/ destroyed 1st on start.

    there is no way around it but ask Ashley here about this. or modify the way C2 engine works i guess. its a cache memory issue i supposed, or canvas cache memory history thing that its only saving the first state and form of a sprite.

    however i always patch this thing by adding a new action under the new created sprites if i want them to be flipped immediately after its created.. i added a condition for it to be flipped or if that is to many lines... just add a new line of conditions similar to this code bellow

    Fish on created ---------------- action for size/scale
    ============================
               if someconditiontoflipison - set flipped/height
    ============================
    ============================
              if someconditiontomirrorison - set mirror/width
    ============================                            
    [/code:1ctslyjf]
    
    since now it did not fail.
    
    but you said its taking some random other... that  makes me suspect of the browser cache you have ... do you use SaveGame System Function? or persistent/global objects? 
    
    Edited: i ask about any saving /caching issue because i seen if you save locally something and then try open a new capx version after you closed that or update a game on a website some cache remains are going to affect it.
    
    Edit2: all that explanation above made basically the same point you said just without the error.... lol .... i feel stupid for not stay and read till i get it right.... yes if its not acting as i said above and as you said... then its a cache problem.. that means... your game if its hosted on a website... and u updated a new version of it... you need to clear the cache history media or the data hosted thing... not sure what counts now... but for me cleaning that in chrome was fixing it.
  • That's why I ask, what defines "the first one created".

    As you can see in my screenshot above, the sprite InterfaceElement with UID 1 (uid 0 is something else, we don't care, it's another sprite) is set with positive width and scaled 1:1, placed on a placeholder layout. The layout that loads first also uses this sprite, for the interface, manually placed in layout. Some are normal, others are reversed. Then comes the code, that creates also a few InterfaceElements, but they are reversed and squeezed... So, my point is: What defines "first created element", because obviously it's not the one with the lowest UID

    I am not going to delete all InterfaceElements sprites from my roughly 40 layouts, all together what, 500 InterfaceElements manually placed, and recreate everything. I will rather manually fix that in the xml files

    I talk about local testing, no chaing issues (and browser has caching disabled for testing)

  • uid 0 is the first layout you create, which is the first "canvas editor screen" we create when we open a new template

    so if you add 500 objects in the project sidebar their uid will be counting from uid0+order of object created 1 2 3 etc

    but... while you stop creating objects 123

    and then create layout number 2

    uid of objects that will be added skip another 1

    since the new layout will have uid of last object placed objectuid3+1 which means the layout2 is uid4 which then objects continues with uid 4+1,+2+3 etc...not sure if im making myself understood. or if is the answer your looking for

    however what you are experiencing is more of a memory remain of capture of a first state, but again im not sure what wold you expect from it to do... it seems to be working fine as you explained in the pictures... there is nothing out of the ordinary unless your used with some other coding language that maybe was doing it different or had a different logic programming?

  • I'm asking a simple thing: What defines, in the files, the veryy first instance of a sprite you placed. If you say its UID, then it's bugged

  • I'm asking a simple thing: What defines, in the files, the very first instance of a sprite you placed. If you say its UID, then it's bugged

    now you asked the proper question and i see your problem: see manual here ---> Common Features IID vs UID

    also simple explanation if you dont want to read the manual but i strongly recommend it so you understand better, but anyway this is my version of how i understand it:

    Each sprite type is defined by IID(index id), while UID (Unique id) is more of a counting order which its why it makes it weird for you since i guess when you spawn a new sprite, you also spawn a sprite of a different type or have a uid that is incorrect for that type of object...

    so by using IID instead of UID to get the right same type object expressions . that will get you the index number of the same type object.

    to ask your question simple : IID defines object types in C2 UID counts the total numbers no matter of type.

  • IID is a runtime generated IndexID that is not referenced in the xml files, while UID is a UniqueIDentifier used and referenced in the save xml files

    IID indexes the object according to its runtime creation timestamp, by type, and UID ensures a possibility to reference the object by being sure to never return more than one result. IID is not unique and volatile where UID is unique and by definition should never change (which is not the case in C2, strange, but well, definitions....)

    I'm still asking what defines, for C2, the first placed instance of a sprite

  • I'm still asking what defines, for C2, the first placed instance of a sprite

    I'm pretty sure it's defined by the first layout it appears in. So layout order is important. It's quite common to have a layout where you place all your default instances.

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