Question

I have been following this tutorial here - http://www.stormation.info/rpg-game-creation-tutorial/

I am trying to make a simple Zelda style rpg game but in the tutorial it uses a dynamic background. I want to use PNG images which have transparent areas where the character can walk.

Like these: http://www.imagebam.com/image/de39a1325517813

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

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

I want everything apart from the transparent areas to block the character. Is this possible?

The tutorial has collision detection but when I follow it by making the png a movie clip then using the instance 'walls' to correspond with the code then my character disappears when testing the scene.

Here is my current As2 code:

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() 
}
Was it helpful?

Solution

hitTest can't recognize alpha in bitmaps straight out of the bottle, but I don't think it's impossible to come up with a solution for this if you tinker with the BitmapData class. An easier (but less elegant) way would be to use an invincible layer where you just fill in where the player can't go, and hitTest against this instead of the clip containing the png.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top