java - andengine setPosition not working -


i have tried following code when click on mman1 second time move 520 422(in x), nothing (when click first time, setposition works fine).

    \\ in oncreatescene     mline1 = new sprite(422, 321, this.mline,             getvertexbufferobjectmanager());     mline2 = new sprite(274, 321, this.mline,             getvertexbufferobjectmanager());     scene.attachchild(mline1);     button bu1 = new button(1, 139, 174, this.mbuttontextureregion,             getvertexbufferobjectmanager()) {          @override         public boolean onareatouched(touchevent pscenetouchevent, float x,                 float y) {             if (pscenetouchevent.isactionup()) {                 scene.attachchild(mline1);                 scene.detachchild(mline2);                 mline1.setvisible(true);                 mline2.setvisible(false);                 setc(true);                 if (b == false || mman1.getx() == 277) {                     mman1.setposition(422, 249);                     setb(false);                 }             }             return true;         };      };      button bu2 = new button(2, 500, 174, this.mbuttontextureregion,             getvertexbufferobjectmanager()) {          @override         public boolean onareatouched(touchevent pscenetouchevent, float x,                 float y) {             if (pscenetouchevent.isactionup()) {                 scene.attachchild(mline2);                 scene.detachchild(mline1);                 mline1.setvisible(false);                 mline2.setvisible(true);                 setc(false);                 if (b == false || mman1.getx() == 422) {                     mman1.setposition(277, 249);                     setb(false);                 }             }             return true;         };      };      mman1 = new man(3, 520, 249, this.mman, getvertexbufferobjectmanager()) {          @override         public boolean onareatouched(touchevent pscenetouchevent, float x,                 float y) {             if (pscenetouchevent.isactionup()) {                 if (mman1.getx() == 520 && c == true) {                     mman1.setposition(422, 249);                     setb(false);                 } else if (mman1.getx() == 238 && c == false) {                     mman1.setposition(277, 249);                     setb(false);                 }                 if (mman1.getx() == 422 && mline2.isvisible() == false                         && mline1.isvisible() == true && b == false) {                     mman1.setposition(520, 249);                     setb(true);                 }                 if (mman1.getx() == 277 && mline1.isvisible() == false                         && mline2.isvisible() == true && b == false) {                     mman1.setposition(238, 249);                     setb(true);                 }             }             return true;          };      }; 

boolean 'b' , 'c' default, true. in advance.

the problem in conditions.

possible scenarios:

1st click: mman1 > moves 520 422 in x

2nd click: mman1 > 1st , 2nd 'if' won't execute because of position, 3rd , 4th won't execute because of line.isvisible()

.............

1st click: bu1 > 1 line not visible , 1 visible. position of player not changed

2nd click: mman1 > 1st 'if' set position 422 in x, , (because you've written 'if' instead of 'else if') next 'if' execute because x 422 , lines condition true. position set 522 can't see it.

.............

if start bu2 instead of bu1 nothing happen second time because lines condition true last 'if' position won't equal 277.

ps it's more clear if use:

mline2.isvisible() 

instead of

mline2.isvisible() == true 

for booleans (! - false).

you should check 'if's , 'else if's. guess mean 'else if' in case.

ps2 if you're happy solution mark post answer , vote please (tick , up-arrow):)


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -