Start/Stop moving actors outside screen camera area
JCFord
Member Posts: 785
I'm sure I read on this forum somewhere sometime ago that there was a discussion about being able to stop actors moving when they are out of the active camera/screen area to help improve frames per second.
I would love to be able to do this, I have a large scrolling area but it would be great if anything outside the immediate screen/camera area was stopped and then only started moving again when they move into the active screen/ camera area.
Thanks
I would love to be able to do this, I have a large scrolling area but it would be great if anything outside the immediate screen/camera area was stopped and then only started moving again when they move into the active screen/ camera area.
Thanks
Comments
Easy Way: Create an invisible actor that is just a bit bigger than the screen. Then Constrain its x and Y to the actor that controls the camera. Then in the moving objects you want to control you put a rule around the movement rules that says when actor overlaps with invisible screen actor do movements.
Otherwise you can do the same thing but use magnitude math expression (go to firemaplegames profile for a magnitude demo). With this method you don't need the extra actor, but you will need some extra actor and game attributes (again, see firemaple's demo)
the screen is obviously 480x320, but my game area is larger with the Player scrolling around the screen.
As Scitunes mentioed above I set up an invisible actor that tracks/moves with my player and when this invisible actor is in contact with enemies they move but when the enemies are not in contact with this invisible area they stop moving which is exactly what I want.
But the problem is that when my player moves say over to the right hand edge of the screen before the area starts to scroll the invisible actor that follows it over to the right is then half on screen and half off so only half the enemies are moving on the visible screen which is not what I want.
Any advice please?
Sorry also forgot to mention that if I just add this invisible area to my non scrolling HUD so it DOES follow the camera perfectly it also doesn't work the enemies are just frozen and don't move when they come in contact with the invisible area?
If you double-click on the invisible collision Actor that is in the Scene, and click the padlock to unlock it, you will now have access in the expression editor to Scene Attributes, among them the Camera. Prototypes do not have access to Scene Attributes, only Instances on the Stage.
Two of those Scene Attributes, Camera.Origin.X and Camera.Origin.Y represent the lower left corner - at all times - regardless of the scrolling.
So in the INSTANCE of the invisible actor, instead of constraining him to the Player, I would Constrain him like this:
Constrain Attribute
self.Position.X To Camera.Origin.X + 240
Constrain Attribute
self.Position.Y To Camera.Origin.Y + 160
I am assuming that the invisible actor is 480x320.
That should do the trick. That will keep the Actor locked to the center of the Screen at all times.
Delete all of the code from the prototype of the invisible actor and paste it into the instance instead. In the Actors panel, the invisible actor should simply be a 480x320 box with the visibility turned off. No Behaviors in it.
Hope this helps!
Joe