动作脚本3.动画永远循环下去gotoAndStop()之后,并有动画过程中的滞后,当角色有冲突 [英] Action Script 3. Animation loop forever after gotoAndStop() and have lag during animation when character have collisions

查看:209
本文介绍了动作脚本3.动画永远循环下去gotoAndStop()之后,并有动画过程中的滞后,当角色有冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建简单的Flash游戏。我有问题,动画循环之后,我的用户gotoAndStop()永远和我有滞后性,当动画过程中,如果角色与地面或任何阶段(如果字符飞在空中没有任何滞后)碰撞

下面是冲突列表:

  VAR myCollisionList:CollisionList =新CollisionList(英雄);
myCollisionList.addItem(地);
myCollisionList.addItem(ground3);
myCollisionList.addItem(ground5);
myCollisionList.addItem(ground4);
 

这里是我的code部分,其中跳的动画。

 如果(Hero.y_speed> 0安培;&安培; myCollisionList.checkCollisions()长度GT; 0)
{
    Hero.y_speed = 0;
    Hero.x_speed = 0;

    如果(空间)
    {
        如果(ground.hitTestPoint(Hero.x + 28,Hero.y + 20,真正的))
        {
            Hero.gotoAndStop(攻击);
            停止();
            Hero.y_speed = -20;
        }
    }
}
 

更新: 地图的截图:

更新2:

下面是code的移动特征到左的部分(以右侧相同)的一面,我知道它的可怕,但我不知道如何使它更好。

pakopos - CollisionList的名称

fonas - 背景

  VAR pakopos:CollisionList =新CollisionList(英雄);
    pakopos.addItem(地);
    pakopos.addItem(ground3);
    pakopos.addItem(ground5);
    pakopos.addItem(ground4);

如果(左){

    Hero.x_speed = -walkspeed;

    setDirection(1);

    如果(pakopos.checkCollisions()长度GT; 0){

    如果(ground5.hitTestPoint(Hero.x  -  26,Hero.y-120,真)){
        跟踪(触摸左侧 -  ground5);
        ground5.x + = 0;
        ground4.x + = 0;
        ground3.x + = 0;
        fonas.x + = 0;
        Enemy.x + = 0;
        }
    否则,如果(Enem​​y.hitTestPoint(Hero.x  -  26,Hero.y-120,真)){
        跟踪(触摸敌人);
        ground5.x + = 0;
        ground4.x + = 0;
        ground3.x + = 0;
        fonas.x + = 0;
        Enemy.x + = 0;
        }
    否则,如果(ground3.hitTestPoint(Hero.x  -  26,Hero.y-120,真)){
        跟踪(触摸左侧 -  ground3);
        ground5.x + = 0;
        ground4.x + = 0;
        ground3.x + = 0;
        fonas.x + = 0;
        Enemy.x + = 0;
        }
    否则,如果(ground4.hitTestPoint(Hero.x  -  26,Hero.y-120,真)){
        跟踪(触摸左侧 -  ground4);
        ground5.x + = 0;
        ground4.x + = 0;
        ground3.x + = 0;
        fonas.x + = 0;
        Enemy.x + = 0;
    }其他
    {
        Hero.x_speed = 0;
        ground5.x + = 4;
        ground4.x + = 4;
        ground3.x + = 4;
        fonas.x + = 4;
        Enemy.x + = 4;

    }}
    其他 {
        ground5.x + = 4;
        ground4.x + = 4;
        ground3.x + = 4;
        fonas.x + = 4;
        Enemy.x + = 4;

    }}
 

解决方案

您code是非常神秘的,所以很难说这是怎么回事,而无需实际调试它,但我的猜测是,你正在检查碰撞多次每次你要对你贴code运行。您应该检查的 checkCollisions()函数使用,因为它似乎返回结果数组的文档。它可能给你所有的碰撞,它在碰撞列表中的对象中发现的,所以你不必叫 hitTestPoint()直接算账。

修改

我不熟悉的,你在你的code使用CDK但它返回的碰撞结果,每个结果都有碰撞的对象,他们的角度数组,如果他们重叠。对于你想要做什么,这似乎是矫枉过正,但正如我所说,我不熟悉它 - 它可能是一个很大的速度,然后 hitTestPoint()

我建议你只用一击测试方法 - 无论是用CDK或使用 hitTestPoint(),但不能同时使用。双方会给你完美的像素检测结果。如果你使用CDK,阅读如何 checkCollisions的文档()的作品。你不得不做这样的事情:

  ...
VAR oResults:阵列= pakopos.checkCollisions();
VAR NCOUNT:INT = oResults.length;

如果(NCOUNT大于0)
{
    对于(VAR我:= 0; I< NCOUNT;我++)
    {
        VAR oHit:对象= oResults [I]

        // TODO检查`oHit.object1`和`oHit.object2`看到哪些对象
        //相撞,并以此为基础进行的东西
        //你可能有多个结果,因为你的英雄可能会发生冲突
        //'地'和'ground4在同一时间。
    }
}
 

您冲突组(<$ C C $> pakopos )设置为CDK似乎是关 - 你不会有,以确定是否有在你的小组中的所有对象之间的碰撞 - 我假设你不关心 ground4 碰撞,但你既添加到您的冲突列表。

我觉得(不知道)的 checkCollisions()尝试检查所有对象的组中对所有其他对象。你需要的是检查一个对象(英雄)对对象的列表(各种地面物体)。这是检查的数量之间的巨大的差异。这和你的额外调用 hitTestPoint()可以很容易地解释你的滞后性。

I'm creating simple flash game. I have problem, animation loop forever after I user gotoAndStop() and I have lag when during animation if character have collision with ground or any stage (if character flying on the air don't have any lags)

Here is collision list:

var myCollisionList:CollisionList = new CollisionList(Hero);
myCollisionList.addItem(ground);
myCollisionList.addItem(ground3);
myCollisionList.addItem(ground5);
myCollisionList.addItem(ground4);

And here is my part of code where jumping with animation.

if(Hero.y_speed>0 && myCollisionList.checkCollisions().length > 0 )
{
    Hero.y_speed=0;
    Hero.x_speed=0;

    if(space)
    {
        if (ground.hitTestPoint(Hero.x + 28, Hero.y+20, true))
        {
            Hero.gotoAndStop("attack");
            stop();
            Hero.y_speed = -20;
        }
    }
}

UPDATE: Screenshot of the map:

UPDATE 2:

Here is part of code for move character to left (to right side the same) side, I know Its terrible, but I don't know how to make It better.

pakopos - name of CollisionList

fonas - background

    var pakopos:CollisionList = new CollisionList(Hero);
    pakopos.addItem(ground);
    pakopos.addItem(ground3);
    pakopos.addItem(ground5);
    pakopos.addItem(ground4);

if(left){

    Hero.x_speed = -walkspeed;

    setDirection(1);

    if(pakopos.checkCollisions().length > 0) {

    if (ground5.hitTestPoint(Hero.x - 26, Hero.y-120, true)) {                  
        trace("Touching left side - ground5");
        ground5.x += 0;
        ground4.x += 0;
        ground3.x += 0;
        fonas.x += 0;
        Enemy.x += 0;
        }
    else if (Enemy.hitTestPoint(Hero.x - 26, Hero.y-120, true)) {
        trace("Touching Enemy");
        ground5.x += 0;
        ground4.x += 0;
        ground3.x += 0;
        fonas.x += 0;
        Enemy.x += 0;
        }
    else if (ground3.hitTestPoint(Hero.x - 26, Hero.y-120, true)) {
        trace("Touching left side - ground3");
        ground5.x += 0;
        ground4.x += 0;
        ground3.x += 0;
        fonas.x += 0;
        Enemy.x += 0;
        }
    else if (ground4.hitTestPoint(Hero.x - 26, Hero.y-120, true)) {
        trace("Touching left side - ground4");
        ground5.x += 0;
        ground4.x += 0;
        ground3.x += 0;
        fonas.x += 0;
        Enemy.x += 0;
    }else
    {
        Hero.x_speed = 0; 
        ground5.x += 4;
        ground4.x += 4;
        ground3.x += 4;
        fonas.x += 4;
        Enemy.x += 4;

    }}
    else {
        ground5.x += 4;
        ground4.x += 4;
        ground3.x += 4;
        fonas.x += 4;
        Enemy.x += 4;

    }}

解决方案

Your code is very cryptic so it's hard to say what's going on without actually debugging it but my guess is that you're checking collisions multiple times every time your posted code runs. You should check the documentation of the checkCollisions() function that you use since it seems to return an array of results. It likely gives you all collisions that it found among the objects in the collision list so you don't have to call hitTestPoint() directly afterwards.

Edit:

I'm not familiar with CDK that you use in your code but it returns an array of collision results where each result has the colliding objects, their angle and if they're overlapping. For what you're trying to do it seems like an overkill but as I said, I'm not familiar with it - it may be a lot faster then hitTestPoint().

I'd recommend using only one hit test method - either use CDK or use hitTestPoint() but not both. Both will give you pixel perfect detection results. If you use CDK, read the documentation on how checkCollisions() works. You'd have to do something like this:

...
var oResults:Array = pakopos.checkCollisions();
var nCount:int = oResults.length;

if (nCount > 0)
{
    for ( var i:int = 0; i <nCount; i++ )
    {
        var oHit:Object = oResults[i];

        // TODO check `oHit.object1` and `oHit.object2` to see which objects
        // collided and do something based on that
        // You may have multiple results since your hero may collide with
        // 'ground' and 'ground4' at the same time.
    }
}

Your collision group (pakopos) setup for CDK seems to be off - you won't have to determine if there's a collision between all the objects in your group - I assume you don't care if ground collides with ground4 but you added both to your collision list.

I think (not sure) that checkCollisions() tries to check all objects in the group against all other objects. What you need is check one object (Hero) against a list of objects (the various ground objects). That's a massive difference between the number of checks. This and your extra calls to hitTestPoint() can easily account for your lag.

这篇关于动作脚本3.动画永远循环下去gotoAndStop()之后,并有动画过程中的滞后,当角色有冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆