[Solved] Character maps with Spriter on start of layout

  • Hello,

    I have been trying to use Spriter in one of my projects, but am having some difficulties with changing character map after spawning. I created an example to pretty much mimic the project and for some reason it works better with similar logic... <img src="{SMILIES_PATH}/icon_e_confused.gif" alt=":?" title="Confused">

    The problem I am having is I create some Spriter objects and then attempt to change scale or character maps in a sub event. (Also have problem with Sprite Fonts). For some reason it doesn't work until the next time the function is called. I ended up creating a function to apply the scaling and character maps after the objects are spawned. However, having 2 functions in consecutive order would not change the character map. I thought since the events are read top to bottom and that they are both top level events then it should work...

    Call function Spawn objects

    Call function Setup objects

    Instead I used a boolean to trigger the "Setup Objects" function after the function that spawns finishes.

    [Edit] Boolean did not solve the problem. Seemed like it was working correctly, but further testing shows that some sprite's maps did not change. Clicking the spawn button afterwards seemed to work correctly.

    Anyhow, in the example .capx I am creating Spriter objects on start of layout with a loop. Every other object gets resized and changes character map from "Pink" to "Green".

    Should look like the image below.

    https://drive.google.com/file/d/0B_14V9 ... sp=sharing

    [/img]

    However, on start of layout they are all Pink, but should alternate color. Clicking the "Next Layout" button shows what it should look like using the same logic. Clicking the "Previous Layout' goes back to the original layout and it is now displayed correctly. I am not sure why they are all pink when I first preview it, but changing layouts seems to work.

    I am using C2 R205.2 and latest Spriter plugin.

    https://drive.google.com/open?id=0B_14V9jZl-I2SE03dVVNdGlXaVU&authuser=0

    Thank you!

  • Your capx is missing Layout 1.xml and some animation frames, so it won't run. Are you setting the scale using the Spriter object On Initialised trigger or using an On Created trigger? Created a spriter object takes more than one tick, so referencing the object directly in sub events will not work correctly. I'm just guessing without seeing the capx, though.

  • Your capx is missing Layout 1.xml and some animation frames, so it won't run. Are you setting the scale using the Spriter object On Initialised trigger or using an On Created trigger? Created a spriter object takes more than one tick, so referencing the object directly in sub events will not work correctly. I'm just guessing without seeing the capx, though.

    Oh man I uploaded the wrong file! I have updated the link. I thought I read somewhere about Spriter objects and using wait 0 or more. Do you know how many ticks it takes or just usually more than 1?... hmm. Anyhow, the linked capx was basically for testing character maps and scaling. I don't see why first running the project shows pink boxes with scaling instead of alternating colors and scaling.

    I have tried in my other project to update character maps in the triggered event on creation, but they did not update.

  • I think that the problem is caused because you're commanding character map changes on the first layout before the spriter Test object has been initialized. The object(s) only needs to be initialized once per game run (so the trigger will not fire on 2nd layout - this has caught me out before) and I suspect that that is why the On-Start-Of-Layout commands work the second time over. Good logic on the demo to order the objects on screen .

  • I think that the problem is caused because you're commanding character map changes on the first layout before the spriter Test object has been initialized. The object(s) only needs to be initialized once per game run (so the trigger will not fire on 2nd layout - this has caught me out before) and I suspect that that is why the On-Start-Of-Layout commands work the second time over. Good logic on the demo to order the objects on screen .

    Thanks for you help! You got me thinking and in my other project I had an "object destroy" in setup that caused the "on initialized" to not trigger with that instance.The next instance triggered the On Initialized, but caused the character map to not change to what I wanted. Anyhow, removed that destroy and now it is working as expected.

    The demo however... I would need to think about that more how to alternate character maps during setup...not sure if its possible.

    Thanks again!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Excellent! Remember you don't need to initialise your spriter objects in the first layout they appear in the final game - where it will cause a momentary delay. Assuming you have a start level you can place them all there hidden away where any delay doesn't matter (although doing that just might not make l your game logic more complicated because you'll still have to preview each layout and so will still need an on initialised there too). Glad it's sorted!

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