Set up wraparound effect in libGDX with Box2D -
i have been having trouble trying set wraparound in libgdx using box2d, example want player appear @ left side of screen after exiting right side, not working here code:
public void setwraparound(){ //if player goes out of bounds vertically if(body.getposition().x < 0){ body.settransform(new vector2(4.8f, body.getposition().y),body.getangle()); }else if(body.getposition().x > 4.8f){ body.settransform(new vector2(0, body.getposition().y), body.getangle()); } //if player goes out of bounds horizontally if(body.getposition().y < 0){ body.settransform(new vector2(body.getposition().x,8f), body.getangle()); }else if(body.getposition().y > 8f){ body.settransform(new vector2(body.getposition().x,0), body.getangle()); } }
then call method in gamestage class this:
public gamestage() { setupworld(); setupcamera(); setuptouchcontrols(); player.setwraparound(); renderer = new box2ddebugrenderer(); }
anyone me out?
the place call setwraparound
method wrong. need call after collision of player screen border happens. suggest following
- create static bodies each screen border (you use example edgeshape that)
- add
contactlistener
box2d world , check inbegincontact
method if player & wall touch. - now after touch detected call method
setwraparound
alternatively create sensor matches screen size , detect if player touches sensor borders. or check every frame player's x/y positions , see if out of screen, better use box2d collision detection.
Website Design Qatar
ReplyDeleteBusiness Setup in Qatar
ReplyDeleteCompany Formation in Qatar
Accounting Services in Qatar
Audit Services in Qatar
PRO Services in Qatar
Visa Services in Qatar
Certifiate Attestation in Qatar
Legal Translation Services in Qatar
Apostille Services in Qatar
Virtual Office in Qatar