Hi Friends.
i have set gravityX & gravityY to Zero.
if i add "super.Create();" like BoxMan class. it also makes gravityY to 10;
could any one plz help me how can i make "listenWhileVisible" like Commands Work ?
thanks for your time.
Arman.
🙁
i explain more:
I have a circle which has MyCircle Class (MyCircle extends Shapes.Circle).
the circle is In the World.
World Gravity is set to Zero On Component Window.
I want To listen to contact of this circle so i have to add a "ListenWhileVisible" Event on MyCircle Class.
But when i Add ListenWhileVisible in Constructor function of MyCircle, it Actually DOSE NOTHING.
So i add a super.create() in my Constructor Function of MyCircle.(because Box Man Have super.create)
it Make Listener Work!
But It Also Adds 10 Y Gravity To the world.
how can i remove this Gravity ?
I write a "this.world.gravityY=0";
but this Dose NOT change any thing 🙁
Don't do things in the constructor function. The constructor is called before the component properties are set. So you are forcing the world to get created before the Flash even has a chance to set the gravity to zero from your component property panel.
Instead, override the create() function (be sure to call super.create()) and do everything in there. That should fix all your problems.
Tanks Mayobutter.
that is exactly the case.
i was able to remove gravity by changing default gravity value to 0; but other problems occured!
so i called ensureCreated() function insted of create() function.
now it'll firs make Bodys and ensure they are created.
it fixed my problem 🙂.
but also taked abut Two days full time work to find that out.
thanks to good comment on code.
and thanks to your good explanation
Arman.
You shouldn't have to call "create()" or "ensureCreated()" ever. These are automatically called when added to the stage. They call "create()" where you can instantiate everything.
if i dont use ensureCreate() or create() in my initilize class then listenWhilevisible wont work.
no error. but it also do not work.
what is the true way?
and when i re start my level it gives error that myCUstomClassExtendsCircle.b2body is null.
but first time it works. i don't know can it be because my use of ensureCreates()?
i almost use it in all the classes which extends BodyShape in my project.
it is not a small project. it is a game with many class. this errors driving me nut 🙁