FlashPunk grid and Nape?


(Oli) #3

oh kk thx, but would u by chance know how to go about distributing each of these nape squares to my FP grid?


(Mike Evmm) #4

You could iterate through your grid and add a square body the size of a tile if that position is solid.


(Oli) #5

with a for each loop? How woudl u do it?


(Oli) #6
        for(var i:int = 0; i < grid.height; i+32)
        {
            
        for (var j:int = 0; j < grid.width; j+32) 
        {
        
        if (grid.getTile(i, j) == true)
        {
        //Nape body                        
            var border:Body = new Body(BodyType.STATIC);
            border.shapes.add(new Polygon(Polygon.rect(i, j, 32, 32)));
            border.space = theGameWorld.space;
        }
        
        }
        
        }

This dosent work:(


(Mike Evmm) #7

You have i and j mixed up. (@ border.shapes.add(new Polygon(Polygon.rect(i, j, 32, 32)));)


(Oli) #9

Would you know how to update the body location with the camera?


(Mike Evmm) #10

How so? (CCCharlimitcharlimitcha)


(Oli) #11

nevermind, I kind of have it working using this

    override public function update():void

    {
                    border.position.x = x - FP.camera.x
        border.position.y = y - FP.camera.y
       

    }

altough other bodies wont collide with it for some reason:(


(Mike Evmm) #12

I was about to reply with that solution. What do you mean not collide?


(Oli) #13

it just go through them, then when it reaches the end of the screen the programm crashes.


(Mike Evmm) #14

That’s strange. Are you sure the bodies are in the correct position? It doesn’t look like it from the screenshot


(Oli) #15

yea but u know man im kind of giving up lol. this is not my level i guess. ill post my source code if your interested.


(Mike Evmm) #16

I had so much trouble using Nape with FP that I temporarily changed to Flixel, so I feel you


(Oli) #17

(Hussein Tammam) #18

Does the game need to be tile based? If it doesnt you could just use resizable entities in ogmo and create a body depending on the width and height of the arbitrarily sized entity. it beats having hundreds of bodies for the ground and walls.


(Oli) #19

yea I guess so:) Altough it would have been much simple for level editin


(Hussein Tammam) #20

Hmmmm I dont see any reason why the bodies should be tile based? Nape handles all collisions by default, there is really no reason to be using a flashpunk grid.


(Mike Evmm) #21

Ogmo editor makes it a pain to work with resizable entities.


(Kyle) #22

What’s the purpose of repositioning the nape bodies relative to FP.camera?


(Oli) #23

Yea I understood that. To get a scrolling world, I should be only moving the camera/how I
render the world, not moving the entire world around my camera. Its kinda funny looking back lol