ModestMaps and Flashpunk [SOLVED!]


(Mike Evmm) #1

Hello,
I’ve recently found out about ModestMaps (which imo is the besterest thing ever, since Google deprecated their Maps API), and I was trying to integrate it with FP. However, and as expected, I have to add the map instance to the stage, which I did by calling FP.stage.addChildAt(map, 1) , so that all FP rendering would occur on top of the map (or so I expected). I have a general idea of how Flashpunk renders things (backbuffer, frontbuffer, etc), but I’m not sure how it integrates into Flash, and the map seems to always overlap any FP entities or graphics I add.
Is there a way around this? Am I going about it wrongly?
Thanks in advance,
Mike


(Abel Toy) #2

Actually, you are adding the map in top of FlashPunk if you’re using that.

In order to add the map below FlashPunk, you would have to use FP.stage.addChildAt(map, 0).

However, this would result in your map being invisible. FlashPunk is not transparent.

Not sure how ModestMaps work, but you can render a sprite to FlashPunk’s list using FP.buffer.draw(sprite)

I actually have a SpriteRenderer Graphic class I use in my project, so your entities can use a Flash sprite as their graphic. Here you have it (I have translated this from Haxe, as I’m working with HaxePunk. There might be some slight issues with the syntax):

public class SpriteRenderer extends Graphic
{
    private var _sprite:Sprite;
    private var _matrix:Matrix;
    
    public function SpriteRenderer(sprite:Sprite) 
    {
        super();
        
        _sprite = sprite;
        _matrix = new Matrix();
    }
    
    override public function render(target:BitmapData, point:Point, camera:Point):Void
    {
        _matrix.b = _matrix.c = 0;
        _matrix.a = _matrix.d = 1;
        _matrix.tx = point.x + x - camera.x * scrollX;
        _matrix.ty = point.y + y - camera.y * scrollY;
        
        target.draw(_sprite, _matrix);
    }
}

(Mike Evmm) #3

Thanks for the help! ModestMaps map does extends sprite, but it won’t show up on stage (with FP.buffer.render) unless added as its child. Any idea why?


(Abel Toy) #4

Probably because they need access to the stage or something and internally are using the added to stage event.

Try adding it using FP.stage.addChildAt(map, 0) and rendering it to the buffer?


(Mike Evmm) #5

Worked like a charm! Thank you!