English 中文(简体)
我的AS2博爱的问题
原标题:Problems in my AS2 Game

Hey guys, I m试图使2D风格的平台游戏类似于以下游戏:

rel=“nofollow” http://www.gashed.com/Puzzle-Games/Blockdude/play.html

我已经完成了大部分制图、地区以及碰撞,但我们的特性仍然无法干活。 我混淆了用什么法典,以便我的特性能够留下来。 我需要帮助我们如何使自己的特性成为他面前的一块块,条件是这些块子没有任何东西。 这使我现在感到困惑,任何帮助都将受到高度赞赏。

问题回答

我深思熟虑地记得我第一次AS2游戏。 正如我所解释的那样,最佳办法可能是一种面向目标的做法。

在AS2中,有自动输入物体的检测方法。 基尔库帕岛有一个良好的教学:

rel=“nofollow” http://www.kirupa.com/developer/actionscript/hittest.htm

并且

http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001314.html

首先,你希望用盒子生成你的箱子。 您的班子需要研究如下内容:

//Box.as pseudo-code
class Box {
    var x_pos:Number;
    var y_pos:Number;
    var attachedToPlayer:Boolean;

    function Box(_x:Number, _y:Number) {
        this.x_pos = _x;
        this.y_pos = _y;    
    }

    //other code here

}

See this tutorial on how to honour a section to a Object in the Library:

To create a new Box, you d then use something like box1 = new Box(100,200); // creates a box at position 100x,200y

However, you ll 并且 want to store the blocks you want to pickup into some sort of array so you can loop through them. See http://www.tech-recipes.com/rx/1383/flash-actionscript-create-an-array-of-objects-from-a-unique-class/

例:

//somewhere near the top of your main method, or whereever your main game loop is running from - note Box.as would need to be in the same folder import Box;

//...then, somewhere before your game loop

//create an array to hold the objects
var boxArray:Array = new Array();

    //create loop with i as the counter
    for (var i=0; i<4; i++)
    {
        var _x:Number = 100 + i;
        var _y:Number = 100 + i;
        //create Box object
        var box:Box = new Box();

        //assign text to the first variable.
        //push the object into the array
        boxArray.push(box);
    }

同样,你们需要一个班子,在你们的游戏开始时,例如,创造新的运动员。

var player = new Player(0,0);

然后,你可以针对你在主要游戏圈子(即更新你的角色位置和其他游戏特性的圈子)的阵列,对你们的参与者进行点击。 这样做可能有更有效的方法,例如,目前被筛选的区块只有排位。

您的阵列一旦建立,就利用旁听器,对你们的游戏中的角色,例如,进行打击。

//assuming you have an array called  boxArray  and player object called  player 
for(var box in boxArray){
    if (player.hittest(box)) {
        player.attachObjectMethod(box);
    }
}

对于“我们进入阵列的每一箱子,如果参与者正在触动箱子,则检查”来说,这基本上是假装。 如果盒子正在打上,则将盒子作为参与者类别中的一种方法(我任意称“ObjectMethod”)的理由。

随函附上“Method”,你可以界定某种行为,将盒子贴上角色。 例如,你可以在盒子中为你的箱子的x和头寸以及像托帕莱尔这样的叫作的 b豆制造一个固定和固定的方法。 当有人叫随ObjectMethod时,它将放下箱子,如在运动员中。

//include Box.as at the top of the file
import Box;

//other methods, e.g. constructor

//somewhere is the Player.as class/file
public function attachObjectMethod (box:Box) {
    box.setattachedToPlayer(true);
    //you could 并且 update fields on the player, but for now this is all we need
}

现附上 参与者与盒子的灯泡相勾结是真实的。 回到我们的游戏圈子中,我们会改变我们的路面,更新箱子的位置:

//assuming you have an array called  boxArray  and player object called  player 
for(var box in boxArray){
    if (player.hittest(box)) {
        player.attachObjectMethod(box);
    }
    box.updatePosition(player.get_Xpos, player.get_Ypos);
}

在我们的方框中,我们现在需要界定最新的经验:

//Box.as pseudo-code
class Box {
    var x_pos:Number;
    var y_pos:Number;
    var attachedToPlayer:Boolean;

    function Box(box_x:Number, box_y:Number) {
        this.x_pos = box_x;
        this.y_pos = box_y;     
    }

    public function updatePosition(_x:Number, _y:Number) {
        if (this.attachedToPlayer) {
            this.x_pos = _x;
            this.y_pos = _y;
        }
    }

    //other code here

}

你可以看到,如果所附的ToPlayer boolean被设定,我们就能够通过参与者的立场,并更新箱子的位置。 最后,我们在方框中增加一个移动方法:

public function move() {
    if (this.attachedToPlayer) {
        this._x = x_pos;
        this._y = y_pos;
    }
}

Examples of updating position: http://www.swinburne.edu.au/design/tutorials/P-flash/T-How-to-smoothly-slide-objects-around-in-Flash/ID-17/

Finally, to make it all work we need to call the move method in the game loop:

//assuming you have an array called  boxArray  and player object called  player 
for(var box in boxArray){
    if (player.hittest(box)) {
        player.attachObjectMethod(box);
    }
    box.updatePosition(player.get_Xpos, player.get_Ypos);
    box.move();
}

You have 并且 specified that the blocks should only move with the player if they have nothing on top of them. When you call your attachedToPlayer method, you would 并且 need to run a foreach loop inside the method between the box and the objects that might sit on top of the box. You should now have a fair idea from the above code how to do this.

I appreciate that this is quite a lengthy answer, and I haven t had an opportunity to test all the code (in fact I m fairly positive I made a mistake somewhere) - don t hesitate to ask questions. My other advice is to understand the concepts thoroughly, and then write your own code one bit at a time.

亲爱!

我这样做的方式是,设计针对他将要选取的每个阵营的个别点进行点击测试,然后制定点击标准,在穿透镜子的间隙时间范围内进行点击,并在区块内建立一个框架,以便不再停留(消失?)。

如果你再次混淆我刚才所说的话,我会试图帮助你。





相关问题
As2 Benchmarking

I ve been looking for a took or a method of benchmarking as2 code specifically individual functions. I ve looked at Grant Skinners Performance Test which is for as3 so it does me no good. Does anyone ...

For Loop Only Returning Last Item in Array :(

I m an actionscript novice so I hope I m missing something simple here. In a nutshell, I have a for loop updating a dynamic text element but it seems to iterate so fast that only the last item in the ...

Volume slider - volume doesn t change until mouse over

I ve created a small music player with a sliding volume control. I m having trouble with the volume. Though it does control volume properly, if I set the initial volume to less than 100%, the volume ...

as2 simple for loop not populating textbox

I have got an xml file that brings text into a flash movie in the form of an array, I need to population some textboxes and want to do this using a for loop. My loop look like this: for(var i=...

Run Jquery function on actionscript 2.0

I have a function in jquery I would like run in flash using action script 2.0 The Jquery: <script> $(document).ready(function(){ $("a").click(function(event){ $("div#Header")....

热门标签