Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var UnitFactor = 64.0 / 64.0; //pixelGrid / PixelbyUnit;
- class behavior_Map extends Sup.Behavior {
- layer: number = 0; // collision layer
- awake() {
- var tilemap: Sup.TileMap = this.actor.tileMapRenderer.getTileMap();
- var position: Sup.Math.Vector3 = this.actor.getPosition();
- var scale: Sup.Math.Vector3 = this.actor.getLocalScale();
- var c;
- var prev_id = -1;
- var width_count = 0;
- var TileID: number;
- for ( var y = 0; y < tilemap.getHeight(); y++ ) {
- for ( var x = -1; x <= tilemap.getWidth(); x++ ) { // x value need to be from -1 to (width + 1) for capture rectangle (TileID return -1 if we are outside of bound)
- TileID = tilemap.getTileAt( this.layer, x, y);
- width_count = width_count + 1;
- if (TileID == prev_id) {
- continue;
- }
- if (prev_id != -1) {
- //build previous rectangle found
- c = {
- actor: new Sup.Actor("physic_body"),
- body: null,
- origin: new Sup.Math.Vector3(((x - (width_count * 0.5 ) ) * UnitFactor * scale.x + position.x), (y * UnitFactor * scale.y + position.y), 0)
- }
- c.actor.setParent(this.actor);
- c.actor.setLocalPosition(c.origin);
- c.body = new Sup.ArcadePhysics2D.Body(c.actor, {width:1 * width_count * UnitFactor * scale.x, height:1 * UnitFactor * scale.y});
- c.body.setMovable(false);
- //if you want store body collision:
- //Collision.Grounds_Body.push(c.body);
- }
- width_count = 0;
- prev_id = TileID;
- }
- }
- //this.actor.tileMapRenderer.setLayerOpacity(0, 0);
- }
- update() {
- }
- }
- Sup.registerBehavior(behavior_Map);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement