Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

9 years ago by Tharuin

Hey guys!

I'm having trouble with my game having a lot of static entities. All of them have different sizes but all behave the same (collision with player). It is not possible for me to get them into a tileset and have them managed by collisionlayer.

I'm wondering whether there is a best practice for this. Like some "EntityStatic" with some imagePath property you set in the editor, together with scalable size and just load it then?

Any other ideas?

Thanks

9 years ago by stahlmanDesign

I modified my weltmeister collision-layer tileset at position 46 (unused) to be blue so I can paint "water" in my level. When entities encounter it, they behave as if it is water and change to swimming. Then on top of that, in a visible layer I place the appropriate tiles for water, but it could be anything. For example if you modify a collision tile for climbing, you could put vines on another layer above it, or a ladder, rope etc.

/><br />
<br />
For it to work you must check in handleMovementTrace() to detect if the player is touching this special water tile. If an entity does not have this code, it will just fall through and ignore the special tile:<br />
<br />
<pre class= handleMovementTrace: function(res) { var waterTile = 46; //46th tile on collision tiles changed to be water (by default it is empty) //if no collision with ground, wall or slope, then could be water // phase transition ensures it doesn't flip back and forth instantly in an endless loop var tileSize = 8; // toe about to step into water (collision tile 46) on next update? var toe = this.pos.y + this.size.y + 1; if (ig.game.collisionMap.getTile(this.pos.x + (this.flip ? +6 : this.size.x - 6), toe) == waterTile) { // if walking on an entity or near an edge, flip if more than 1 second since last flip var upOrDownPush = (this.vel.y >= 0 ? 50 : -150) //ig.show("udp=",upOrDownPush) this.kill(); ig.game.spawnEntity(EntityPlayerSwimming, this.pos.x, this.pos.y, { flip: this.flip, vel:{y:upOrDownPush}, accel:{y:upOrDownPush} }); } this.parent(res); }
The reason I kill the player is because if it touches water, I spawn a different entity with swimming controls.

9 years ago by Tharuin

This is interesting, I already thought about changing the collision layer for some special behaviour.

Buuuuut this doesn't quiet hit what I need. I have 5 kind of plants and want all of them placed in the map, they all only do visual things, no logic behind them. But I don't have them in a tileset cause they differ too much and it wouldn't work, also they need to be aligned off the tile layer. So how do I manage this without creating a special EntityPlant or EntityPlant1-5 entity?

9 years ago by Joncom

You could give some entity a property called something like "plantType". And in the init function of that entity, set the size and animation to your liking. In Weltmeister, the init function is called, which should pick up these settings, and make the entity look how you'd like. You should be able to set the "plantType" property directly in Weltmeister.

Edit 1: You might need to refresh the level though for the init to get called and pick up the changes?

Edit 2: What makes you say, "It is not possible for me to get them into a tileset and have them managed by collisionlayer"?

9 years ago by Tharuin

@Joncom

Sadly all elements have different sizes and most of them are not multiples of my collision layer. This is why it would be hard to make them based on a tileset. Also the positioning isn't meant to be based on the tile layout.

Ok, but is this also "viable" for a lot more entities, like having a general "EntityStaticAsset" which has a image string and uses wm_resize for size?

9 years ago by drhayes

they need to be aligned off the tile layer.


Sounds like you need an entity for sure, then. Unless you'd be willing to break them up into tile-sized pieces and stick'em in the background manually, like your plant is 38px wide so you make it into three 16px tiles, if you know what I mean.

Your approach sounds like it could work. About the only problem I could see is if you don't make some call to new ig.Image outside of your entity's init function then the preloader won't get a chance to load the image correctly, so you'll have to force it somehow.

You wouldn't have to manage the size manually, either. You can inspect the image size in the entity's constructor and reposition based on that.
Page 1 of 1
« first « previous next › last »