0

我只是想让一个实体在圆圈中移动,有没有办法在不使用 physicBox 扩展的情况下实现这一点?也许是一些实体修饰符?

感谢您的回复,我在 AndEngine 锚中心工作。

4

2 回答 2

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;
}



} 

可以帮助你..

于 2013-09-14T08:42:29.443 回答
-1

你可能想要喜欢

圈冲

正确的?

于 2016-01-25T09:53:59.070 回答