我只是想让一个实体移动到圆圈,有没有办法实现这个而不使用physicBox Extention?也许是一些实体修饰符?
感谢回复,我在AndEngine anchorCenter工作。
答案 0 :(得分:1)
围绕固定点移动精灵
http://www.andengine.org/forums/gles1/moving-sprite-around-a-fixed-point-t4063.html#p49789
你可以这样实现。
package com.circular.demo;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.handler.IUpdateHandler;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.FillResolutionPolicy;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.ui.activity.SimpleBaseGameActivity;
import org.andengine.util.color.Color;
import android.view.WindowManager;
public class Main extends SimpleBaseGameActivity{
public static final int CAMERA_WIDTH = 800;
public static final int CAMERA_HEIGHT = 480;
Camera _camera;
double _radius = 150;
double _angle = 0;
double _center_point_x = 400;//(CAMERA_WIDTH/2)
double _center_point_y = 240;//(CAMERA_HEIGHT/2)
float _speed = 1;
Rectangle _r;
Rectangle _g;
@Override
public EngineOptions onCreateEngineOptions() {
// TODO Auto-generated method stub
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
this._camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
final EngineOptions _eo = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,
new FillResolutionPolicy(), _camera);
return _eo;
}
@Override
protected void onCreateResources() {
// TODO Auto-generated method stub
}
@Override
protected Scene onCreateScene() {
// TODO Auto-generated method stub
Scene _s = new Scene();
_s.setBackground(new Background(Color.BLUE));
_g = new Rectangle((float)_center_point_x, (float)_center_point_y, 15f, 15f, getVertexBufferObjectManager());
_g.setColor(Color.GREEN);
_r = new Rectangle((float)_center_point_x, (float)_center_point_y, 10f, 10f, getVertexBufferObjectManager());
_r.setColor(Color.RED);
_s.attachChild(_g);
_s.attachChild(_r);
_s.registerUpdateHandler(new IUpdateHandler() {
@Override
public void reset() {
// TODO Auto-generated method stub
}
@Override
public void onUpdate(float pSecondsElapsed) {
// TODO Auto-generated method stub
_angle+=pSecondsElapsed * _speed;
final double _x = _radius * Math.cos(_angle) + _center_point_x;
final double _y = _radius * Math.sin(_angle) + _center_point_y;
_g.setPosition((float)_x, (float)_y);
}
});
return _s;
}
}
可以帮到你......
答案 1 :(得分:-1)