andengine - Is it possible to have an Kinematic Body that moves along x axis, but still responds to user input to move it in y direction -
using andengine i'm trying create ball move across screen @ set velocity, want able move ball when user swipes or down. have move in x direction
fixturedef boxbodyfixturedef = physicsfactory.createfixturedef(20f, 0f, 0.5f); kinematicbody = physicsfactory.createboxbody(mphysicsworld, mmarblesprite, bodytype.kinematicbody, boxbodyfixturedef); mphysicsworld.registerphysicsconnector(new physicsconnector( mmarblesprite, kinematicbody)); kinematicbody.setlinearvelocity(1f, 0f); kinematicbody.setangularvelocity((float) (-math.pi));
and in onscenetouchevent have
mmarblesprite.sety(pscenetouchevent.gety());
i move sprite before, since adding velocity in x direction not respond swiping screen. help
if connecting sprite physics world have update body sprite follows:
kinematicbody.settransform(pscenetouchevent.x/ptm_ratio, pscenetouchevent.y/ptm_ratio, 0);
then have update sprites position every time in update handler follows: bodies in world position of body update sprite position
iterator<body> = bxworld.getbodies();` while(it.hasnext()) { body b = it.next(); object userdata = b.getuserdata(); if (userdata != null && userdata instanceof sprite) { //synchronize sprites position , rotation corresponding body final sprite sprite = (sprite)userdata; final vector2 pos = b.getposition(); sprite.setposition(pos.x * ptm_ratio, pos.y * ptm_ratio); sprite.setrotation(-1.0f * ccmacros.cc_radians_to_degrees(b.getangle())); } }
Comments
Post a Comment