如何从形状/图形对象读取数据

发布于 2024-08-13 09:56:49 字数 150 浏览 6 评论 0原文

我想知道是否可以使用 Actionscript 3 获取存储在 Flash 中的形状/图形对象中的数据?

在我的项目中,我希望能够绘制一个形状,然后将该形状中的所有点读入我的脚本中。原因是我需要从这些点生成线条,稍后我可以用它们来检查我的角色速度是否与其中任何一个相交。

I am wondering if it is possible to get the data that is stored in a shape/graphics object in flash using actionscript 3?

In my project I would like to be able to draw a shape and then read all the points in that shape into my script. The reason for that is that I need go generate lines from those points that I later can use to check if my characters velocity intersects with any of them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

想挽留 2024-08-20 09:56:49

您可以读取 Shape 的所有部分。

新功能添加到 Flash Player 11.6 和 AIR 3.6 中:

flash.display.Grapics.readGraphicsData()

< a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html#readGraphicsData%28%29" rel="noreferrer">http://help. adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html#readGraphicsData%28%29

示例:

var s :Shape = new Shape();
s.graphics.lineStyle(2, 0xFF0000);
s.graphics.drawCircle(0, 0, 50)

var gd:Vector.<IGraphicsData> = s.graphics.readGraphicsData(false);

var copy_of_s :Shape = new Shape();
copy_of_s.graphics.drawGraphicsData(gd);

addChild(copy_of_s);

要使用新版本,您必须更新playerglobal.swc

http://www.adobe.com/support/flashplayer/downloads.html

You can read all parts of Shape.

New feature added to Flash Player 11.6 and AIR 3.6:

flash.display.Grapics.readGraphicsData()

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html#readGraphicsData%28%29

Example:

var s :Shape = new Shape();
s.graphics.lineStyle(2, 0xFF0000);
s.graphics.drawCircle(0, 0, 50)

var gd:Vector.<IGraphicsData> = s.graphics.readGraphicsData(false);

var copy_of_s :Shape = new Shape();
copy_of_s.graphics.drawGraphicsData(gd);

addChild(copy_of_s);

To use the new version, you have to update playerglobal.swc

http://www.adobe.com/support/flashplayer/downloads.html

挖个坑埋了你 2024-08-20 09:56:49

形状信息一旦绘制就无法读取。但如果您正在绘制它,您可以在绘制时存储信息并在以后使用。

You cannot read the shape info once it's drawn. But if you are drawing it, you can store the info at the time of drawing itself and use it later.

梦冥 2024-08-20 09:56:49

好吧,看来这是不可能的,太糟糕了。

我正在做一个 2d 自上而下的赛车游戏,我想沿着赛道的墙壁生成线条,并根据这些线条检查玩家的速度。这样我就能够通过围绕碰撞线法线反射玩家速度并使其从墙壁上反弹来实现一些基本的碰撞响应。有谁对如何在没有实际线条的情况下获得相同类型的碰撞行为有任何好的想法吗?

是否有可能以某种方式重载闪存中的图形对象,以便当我绘制某些内容时它会被记录下来?或者flash IDE不使用Graphics绘图api?

问候

OK, looks like its not possible then, to bad.

I am doing a 2d topdown racing game, and I wanted to generate lines along the walls of the track and check the players velocity against thouse lines. That way I would be able to implement some basic collision response by reflection the players velocity around the normal of the line that it collides with and make it bounce off walls. Does anyone have any good ideas about how to get the same type of collision behavior without the actual lines?

Is it possible to overload the graphics object in flash somehow so that when I draw something it is recorded? Or does the flash IDE not use the Graphics drawing api?

Regards

风吹雪碎 2024-08-20 09:56:49

您不能实例化 Graphics 类或对其进行子类化。但您可以使用自己的自定义图形类。

public class CustomGraphics extends Object{
  private static const CLEAR = -1;
  private static const MOVETO = 0;
  private static const LINETO  = 1;
  ...
  ...
  private var _graphics:Graphics;
  private var _actions:Array;
  public function CustomGraphics(g:Graphics):void {
    _graphics = g;
    _actions = new Array();
  }
  private function recordAction(obj:Object):void {
    if (obj.action == -1) {
      _actions = null;
      _actions = new Array();
      return;
    }
    _actions.push(obj);
  }
  public function moveTo(x:number, y:Number):void {
    g.moveTo(x, y);
    recordAction({action:MOVETO, X:x, Y:y});
  }
  ...
  ...
  public function get actions():Array {
    return _actions;
  }
}

Now whenever you want to draw something then you can use CustomGraphics. var cg:CustomGraphics = new CustomGraphics(someDisplacyObject.graphics);
cg.moveTo(0, 0);
cg.drawRect(0, 0, 10,, 200);
...
a:Array = cg.actions;

You can not instantiate or subclass Graphics class. But you can use you own custom graphics class.

public class CustomGraphics extends Object{
  private static const CLEAR = -1;
  private static const MOVETO = 0;
  private static const LINETO  = 1;
  ...
  ...
  private var _graphics:Graphics;
  private var _actions:Array;
  public function CustomGraphics(g:Graphics):void {
    _graphics = g;
    _actions = new Array();
  }
  private function recordAction(obj:Object):void {
    if (obj.action == -1) {
      _actions = null;
      _actions = new Array();
      return;
    }
    _actions.push(obj);
  }
  public function moveTo(x:number, y:Number):void {
    g.moveTo(x, y);
    recordAction({action:MOVETO, X:x, Y:y});
  }
  ...
  ...
  public function get actions():Array {
    return _actions;
  }
}

Now whenever you want to draw something then you can use CustomGraphics. var cg:CustomGraphics = new CustomGraphics(someDisplacyObject.graphics);
cg.moveTo(0, 0);
cg.drawRect(0, 0, 10,, 200);
...
a:Array = cg.actions;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文