English 中文(简体)
物体的位置
原标题:Place an object at another objects current position

我正试图把物体放在我目前的角色上,但在把物体带走给我的参与者的时候。 我知道,为什么它坚持我的角色,但我必须考虑使用任何其他守则。

我的英雄就是在屏幕上移动的人物。

Thanks Lochy

var trap1:trap = new trap();

function keydown(event:KeyboardEvent) :void {


    if(event.keyCode ==32)
    addChild(trap1);
    trap1.x = hero.x;
    trap1.y = hero.y;
最佳回答

完成这项任务有几个途径。 基本上你们必须知道细节。 在闪电中,显示清单负责管理屏幕上的内容。 显示器和显示器课程为接触显示器和操纵显示器清单提供了机会。

冷漠做法

function placeAbove(d1:DisplayObject, d2:DisplayObject):void
{
  if (!d1 || !d2) return;

  d1.x = d2.x;
  d1.y = d2.y;
}

但是,当两台显示器都显示, 物体有不同的父母,显示器具并非同一协调系统的一部分,因此这种很少的方法赢得笔工。 我举了一个小例子:

package {

  import flash.display.DisplayObject;
  import flash.display.DisplayObjectContainer;
  import flash.display.Sprite;
  import flash.geom.Point;

  public class Points extends Sprite
  {
    public function Points()
    {
      const child1:Sprite = createSquare(50, 50, 0xFF0000, .5)
          , child2:Sprite = createSquare(100, 100, 0x0000FF, .5)
          , container1:Sprite = new Sprite()
          , container2:Sprite = new Sprite();

      DisplayObjectContainer(placeRandomly(addChild(container1))).addChild(child1);
      DisplayObjectContainer(placeRandomly(addChild(container2))).addChild(child2);

      placeAbove(child1, child2);
    }

    private function createSquare(width:Number, height:Number, color:uint = 0, alpha:Number = 1):Sprite
    {
      const sprite:Sprite = new Sprite();
      sprite.graphics.beginFill(color, alpha);
      sprite.graphics.drawRect(0, 0, width, height);
      sprite.graphics.endFill();

      return sprite;
    }

    private function placeAbove(child1:Sprite, child2:Sprite):void
    {
      const point:Point = child2.localToGlobal(new Point(0, 0))
              , point2:Point = child1.globalToLocal(point);

      child1.x = point2.x;
      child1.y = point2.y;
    }

    private function placeRandomly(displayObject:DisplayObject):DisplayObject
    {
      displayObject.x = Math.random() * 100;
      displayObject.y = Math.random() * 100;

      return displayObject;
    }
  }
}

申请产生2平方米,并增加为不同的父母。 集装箱(父母)被随意放置在屏幕上,而且有两个儿童显示器。 Above方法具有所有魔力。 它从全球第二个显示物体中计算出位置,并将其地图上标明在母子协调系统中的当地位置。

我希望它能够提供帮助。

问题回答

不清楚你是如何安排展示名单的,但试图将trap锁作为母子的孩子。 i.e:

hero.parent.addChild(trap1);




相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

Red5 Security Tutorial

I am looking for a step by step tutorial on securing Red5 from intrusion. This seems to be a question that comes up alot in a google search, but is never really answered in a way that makes sense to ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

visible property of DisplayObject

For example I have a hierarchy of movie clips. mc1 is a child of mc, and mc2 is a child of mc1. Turns out that when I set mc1.visible = false; mc2.visible stays true. Is that supposed to happen?...

热门标签