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

1 decade ago by Alex

Hello,

I'm trying to make a demo game with destructible tiles. Is there some way within the game to destroy a collision and corresponding image tile with it? If not, would building world of tiles as entities be a good idea? Performance wise, especially mobile.

1 decade ago by stahlmanDesign

In another game engine using Objective C (iPhoneGameKit.com) and tiles, it was possible to make tiles that could be destroyed with them being LevelObjects (the equivalent of "entities" in Impact). For example, you could cut down trees to move through the forest.

I don't know if this is possible in Impact.

1 decade ago by Alex

Yes, you can easily make entities disappear in Impact. Think of enemies in demo when you kill them. Just change enemy to a box with health that can be killed and removed on death.

The question however is, if I'm making a fully destroyable world consisted of 100's(1000's) of tile entities, would this affect the performance, especially on mobile platforms, say compared to regular way making the tiles as collisions, but somehow making them destroyable?

Or is the only way of making a destroyable world is to go with entity tiles?

1 decade ago by Hareesun

If you're making a fully destructible world, IMPACT is not the engine you are looking for. In fact, HTML/Javascript are probably the wrong platforms for that.

I could be wrong of course, so don't hold me to that.

I can't remember where I saw it, but Dom has made an entity stress test somewhere. :)

1 decade ago by Alex

If you mean not suitable performance wise, what about using method with loading entities and tiles as the player moves forward trough the level? It was described in some post as an extra feature to reduce lag. I think that would be a workaround for a world full of entity tiles

1 decade ago by BFresh

Alex,

I've had good luck creating entities just outside of the player's view or for entities that you want to persist for a reason or another, I keep them around but overwrite their .draw method to only draw them when within the player's view. They are still updating with the game but drawing them seems to use a chunk of processing I guess. I didn't notice a performance difference on my high-powered desktop, but it was the difference between making the game playable on slower laptops and mobile devices.

1 decade ago by Alex

Care to share? :) Appreciated! Private(e-mail) if you prefer

I still would like to hear what Dom thinks about building a destructible world out of entities, or somehow make collision tiles get destroyed from within the game.

1 decade ago by BFresh

For creating/destroying entities, you'll need to think up some logic on how you would want it to occur based on your game and then have it in your main game loop. For managing things like this, I have a 'manager' entity that exists in the level, is non-visible and just manages the presence or kills other entities.

In terms of only drawing entities close to the player, you could overwrite each entity's draw method or I suppose you could go into impact's entity.js and make it that way for all entities if you wanted. You just have to throw some conditions in before it is drawn:

		if (ig.game.player) {
		
			//Only draw if within sight of player
			if (this.distanceTo(ig.game.player) < ig.game.activedistance) {
				
				if( this.currentAnim ) {
					this.currentAnim.draw(
						this.pos.x.round() - this.offset.x - ig.game.screen.x,
						this.pos.y.round() - this.offset.y - ig.game.screen.y
					);
				}
			}
		
		}

In this case, ig.game.player is the player entity that I've gotten using getEntitybyName in the game's main.js loop (i named the player 'player') and ig.game.activedistance is the distance the entity needs to be within for it to be drawn. I use something like ig.system.width*.75 if you player is centered and can view .5 of the width (and your aspect ratio has your width being larger then the height).

1 decade ago by blast

I know this is an old topic, but I wanted to throw in my experience with destroying tiles. I've actually had good success with this on a recent project. The trick is, the collision map actually inherits from the map class, so although it's not listed in the docs, the collisionMap has getTile() and setTile() available.

In this way, you can use setTile() on both your backgroundMap and the collisionMap at the same time to essentially remove the tile and remove the collision along with it. The only problem is that this does NOT work if you are using a pre-rendered map. I'm not sure how how bad that effects performance over all, but it does work. Here's some code you might use.

Assuming 'this' is an entity or event that has a position this will remove the tile and collision map at that location:

ig.game.backgroundMaps[0].setTile( this.pos.x, this.pos.y, 0 );
ig.game.collisionMap.setTile( this.pos.x, this.pos.y, 0 );

1 decade ago by Kxen

Thanks blast! I'm actually making a game where I need this. I kind of knew this was how you did it but nice to have it confirmed so I don't have to worry about it. :)

1 decade ago by FlynnBoyO

"The only problem is that this does NOT work if you are using a pre-rendered map?"

What qualilfies for a pre-rendered map? A map you built with the level editor? If you could elaborate on that a little it would be helpful to me. When or how does rendering of a map occur if it is not pre-rendered? I am thinking of using this engine and this aspect of game play is important to the game I am developing. Thanks.

1 decade ago by Arantor

A pre-rendered map is one that you've told it to pre-render the image chunks. Normally when a map is used, there's one draw call per tile, for every tile. Which means hundreds of draws per frame, which some systems can't handle.

You can optionally turn on pre-rendering with the 'Pre-Render in Game' option in Weltmeister, which will internally create large bitmaps (usually 512x512) containing tiles, so instead of doing many draws per frame, you do far fewer - but at the cost of not having animated backgrounds.

Similarly, unless you have it re-render the background to this internal canvas, it's going to use the old image (which defeats the purpose of your changing tiles in the map)

1 decade ago by FlynnBoyO

Thanks. That is very helpful.
Page 1 of 1
« first « previous next › last »