[Solved] Character maps with Spriter on start of layout

Get help using Construct 2

Post » Sun May 24, 2015 9:04 pm

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... :?

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.

[img]
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!
Last edited by Exile03330 on Mon May 25, 2015 3:44 am, edited 2 times in total.
B
12
S
2
Posts: 22
Reputation: 648

Post » Sun May 24, 2015 10:00 pm

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.
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,230
Reputation: 44,892

Post » Mon May 25, 2015 1:56 am

Colludium wrote: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.
B
12
S
2
Posts: 22
Reputation: 648

Post » Mon May 25, 2015 2:23 am

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 :).
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,230
Reputation: 44,892

Post » Mon May 25, 2015 3:42 am

Colludium wrote: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. :D

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!
B
12
S
2
Posts: 22
Reputation: 648

Post » Mon May 25, 2015 10:50 am

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!
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,230
Reputation: 44,892


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 40 guests