PNG图像与Flash(AS2)中的字符冲突....如何?

时间:2014-05-08 21:36:07

标签: flash actionscript-2

我一直关注这个教程 - http://www.stormation.info/rpg-game-creation-tutorial/

我正在尝试制作一个简单的塞尔达风格的RPG游戏,但在教程中它使用动态背景。我想使用PNG图像,这些图像具有角色可以行走的透明区域。

喜欢这些: http://www.imagebam.com/image/de39a1325517813

http://www.imagebam.com/image/5e22e6325517815

http://www.imagebam.com/image/753d56325517819

我希望透明区域之外的所有东西都能阻挡角色。这可能吗?

本教程有碰撞检测,但是当我通过将png设为影片剪辑然后使用实例'walls'来对应代码时,我的角色在测试场景时就会消失。

这是我目前的As2代码:

onClipEvent(load){ 
        radius = 6 
        for (stop in this) { 
                    this[stop].stop() 
        } 
} 

onClipEvent(enterFrame){ 
        if(Key.isDown(Key.UP)){ 
                    this._y -= speed 
                    facing = "up" 
        } 
        if(Key.isDown(Key.DOWN)){ 
                    this._y += speed 
                    facing = "down" 
        } 
        if(Key.isDown(Key.RIGHT)){ 
                    this._x += speed 
                    facing = "right" 
        } 
        if(Key.isDown(Key.LEFT)){ 
                    this._x -= speed 
                    facing = "left" 
        } 
        if(Key.isDown(Key.SHIFT)){ 
                    speed = 5 
                    state = "run" 
        }else{ 
                    speed = 3 
                    state = "walk" 
        } 
        if(!Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.UP) && !Key.isDown(Key.DOWN)){ 
                    this[facing].gotoAndStop(1) 
        }else{ 
                    this[facing].play() 
        } 
        while(_root.walls.hitTest(_x, _y+radius/2, true)){ 
                    _y--; 
        } 
        while(_root.walls.hitTest(_x, _y-radius, true)){ 
                    _y++; 
        } 
        while(_root.walls.hitTest(_x-radius, _y, true)){ 
                    _x++; 
        } 
        while(_root.walls.hitTest(_x+radius, _y, true)){ 
                    _x--; 
        } 
        gotoAndStop(state+facing) 
        depthControl() 
}

1 个答案:

答案 0 :(得分:0)

hitTest不能直接从瓶子中识别出位图中的alpha,但我不认为如果你修补BitmapData类,就不可能找到解决方法。一种更容易(但不那么优雅)的方法是使用一个无敌层,你只需填写玩家无法进入的地方,然后针对此而不是包含png的剪辑点击测试。

相关问题