Actor Goes Out of Scene [Solved]

Edge123

  • Posts: 62
Alright so lets refer to the actor I'm having a problem with as actor 1 and the actor that has no problems as actor 2

I've been using this code to keep actor 1 in a scene:
if x < 0
set x to 0 for self
if x of self > scene width (pixels) - width of self
set x to scene width (pixels) - width of self
For some reason it works for when the actor's x < 0 but not for when the actor is out of bounds on the other side of the scene. I have this exact code for actor 2 and it works for them. Any idea as to why actor 1 is not working with me?

« Last Edit: January 17, 2020, 12:38:57 pm by Edge123 »

MrD69

  • Posts: 235
What is the width of your screen compared to the width of the scene. Most likely the scene is wider than the screen so the actor appears to go out of bounds but exists still within the screen. No idea why it would work for one actor but not the other.
Games: Arrow Mania, Breakout/Outbreak, Water Drop

NickamonPoppytail

  • *
  • Posts: 1110
Go into the Behaviours tab of Actor 1 and click "Add Behaviour". Under the Motion tab, you'll find Stencyl has a pre-made behaviour called "Cannot Exit Scene" for actors. Attaching it to your actor should hopefully fix the issue.
Upcoming Projects
Poppytail 5 and Pixeltail: Fifth and sixth main instalments in Poppytail series. A Game About Trimming Hedges: Final Version: An updated version of the original AGATH. Easter Fun 2: A sequel to the original Easter Fun. One Million: Last-one-standing style small project. The Poppytales: RPG using characters from other stuff I've made/am making. Skies n' Fall: Boss rush shooter prequel to Rise n' Brawl.

Bombini

  • *
  • Posts: 1368
Sometimes your described method doesnt work because the actor is already outside of the scene.
I use it in the way that i will prevent the actor from even moving outside of the scene (so cheking where the actor will go to and checking if thats inside the scene or not).

Edge123

  • Posts: 62
Sorry about the very late reply but I just looked at my code again after a while and realized the scene is bigger than the resolution you play in  :-[. I appreciate the help though.