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 dwarapalaka

I just started playing with this and had a couple of questions. I've scanned through the forms and the documentation but couldn't find an answer.

1. How do I create a background for my game? Basically, I just want a large image to fill the canvas and stay there all the time, with characters rendered on top. Right now, I'm using a bunch of images and drawing them. But the player doesn't show unless I call "this.parent()" last in the main draw method, in which case, all the background images don't show.

2. Is there an easy way to create a button object in Impact? I noticed none of the demos had any on-screen buttons that could be clicked and couldn't find anything in the docs about this. Ideally I would like to have hover and click effects also, but for now, I'll settle for just having a button that the player can click.

Thanks!

DP

1 decade ago by dominic

1. You have the right idea. The problem is, that when you call this.parent() in your Game's draw() method, it clears the screen. I will change it for the next release, so that when you set .clearColor to null, the screen won't be cleared.

For now, you can just draw all your entities by yourself, e.g.:
draw: function(){
	this.backgroundImage.draw( 0, 0 );
	
	for( var i = 0; i < this.entities.length; i++ ) {
		this.entities[i].draw();
	}
},

Also, have a look at the draw() method in lib/impact/game.js – there's no magic involved ;)


2. For Mobile devices you can use ig.input.bindTouch() to bind an HTML element to a specific action - but that's probably not what you wanted...

Otherwise, there is no "Button" Class in Impact yet; you will have to program your own. E.g. make it a subclass of ig.Entity, use the update() method to check if the mouse coordinates are inside and (update the animation accordingly) and check for clicks.

1 decade ago by dwarapalaka

Thanks for the help! I ended up creating entities for all the background elements (some of which will become interactive later on) and got it to work the way I wanted.

Somewhat related question. If I have an entity that has only a static sprite, should I just load that image as an "animation"? What I did was to create an Image object within that Entity and the draw method simply draws that image. I didn't attach the image as an animation. I'm probably not doing it in the most optimal way though.
Page 1 of 1
« first « previous next › last »