1
Ask a Question / Changing actor position via scene behaviour reset speed of the actor
« on: July 12, 2013, 03:05:52 pm »
Hello,
Some time ago I have returned to stencyl and I'm working on a new project. I have stumbled across a problem that I don't understand. I probably can (and probably will have to) make a workaround, but first I would like to understand why things aren't working the way I think they should.
Here is what I want to accomplish - this is a top-down game about ships, regular battle "map" is just a sea that I want to be quasi infinite in all directions.
So, what I did:
- I created quite big scene (3 screens wide square).
- camera is following the player's ship
- when player's ship is 1 screen-distance to any edge, all actors (of the group "actors") are moved 1 screen-distance in the opposite direction (it happens through scene behaviour). Later on I would make sure actors that are outside of the scene would be killed/recycled now.
- it seems to work well, actors are moved like they should, however they loose their velocity - their x and y speed is set to 0. I'm not sure, but I guess it may be a normal behaviour when you use "set x/y" block.
- I tried to fix this by adding a code that runs in the same loop "for each actor of group actors" where I change x/y position of those actors. The new code first remembers x and y speed of an actor, then apply set x/y blocks, then set x/y speed to what it remembered.
It doesn't change a thing.
After more research with some print blocks I have found out that in fact speed is not reset just after changing x/y position - it happens on the next frame. What is the most strange for me is that it looks like while normally in each frame scene behaviour and actors behaviours act one after another, when I'm moving the actors via scene behaviour, the actor behaviour is not executed this frame. It looks like this:
Starting game
scene behaviour execution
actor behaviour execution
...
scene behaviour execution
actor behaviour execution
scene behaviour execution - here I move actors, at the end of this frame actors' speed is not reset
scene behaviour execution - at the beggining of this frame actors' speed is 0.
I'm thinking of a workaround now - save x and y speeds of each actor in a table(s) in the scene behaviour before changing their positions, then at the beggining of the next frame set x/y speed of each actor according to the tables (I hope the order of actors in "for each actor" loop is always the same). Before I try that I would still want to know why the thing that happens, happens and maybe what am I doing wrong.
Also, if you think my approach to the problem of "invite" sea is wrong, tell me how else I could do it .
Some time ago I have returned to stencyl and I'm working on a new project. I have stumbled across a problem that I don't understand. I probably can (and probably will have to) make a workaround, but first I would like to understand why things aren't working the way I think they should.
Here is what I want to accomplish - this is a top-down game about ships, regular battle "map" is just a sea that I want to be quasi infinite in all directions.
So, what I did:
- I created quite big scene (3 screens wide square).
- camera is following the player's ship
- when player's ship is 1 screen-distance to any edge, all actors (of the group "actors") are moved 1 screen-distance in the opposite direction (it happens through scene behaviour). Later on I would make sure actors that are outside of the scene would be killed/recycled now.
- it seems to work well, actors are moved like they should, however they loose their velocity - their x and y speed is set to 0. I'm not sure, but I guess it may be a normal behaviour when you use "set x/y" block.
- I tried to fix this by adding a code that runs in the same loop "for each actor of group actors" where I change x/y position of those actors. The new code first remembers x and y speed of an actor, then apply set x/y blocks, then set x/y speed to what it remembered.
It doesn't change a thing.
After more research with some print blocks I have found out that in fact speed is not reset just after changing x/y position - it happens on the next frame. What is the most strange for me is that it looks like while normally in each frame scene behaviour and actors behaviours act one after another, when I'm moving the actors via scene behaviour, the actor behaviour is not executed this frame. It looks like this:
Starting game
scene behaviour execution
actor behaviour execution
...
scene behaviour execution
actor behaviour execution
scene behaviour execution - here I move actors, at the end of this frame actors' speed is not reset
scene behaviour execution - at the beggining of this frame actors' speed is 0.
I'm thinking of a workaround now - save x and y speeds of each actor in a table(s) in the scene behaviour before changing their positions, then at the beggining of the next frame set x/y speed of each actor according to the tables (I hope the order of actors in "for each actor" loop is always the same). Before I try that I would still want to know why the thing that happens, happens and maybe what am I doing wrong.
Also, if you think my approach to the problem of "invite" sea is wrong, tell me how else I could do it .