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 hyliandanny

Hello!

I want to place entities onto the canvas without using Weltmeister. In the pong video, Weltmeister is used to place all entities -- such as the paddle for each player and the ball.

Do I need to emulate what Weltmeister is doing in order to achieve this? That is, do I need to...

- create a main.js file in lib/game/levels;
- copy/paste the main.js file's code, like below, and then modify it to fit my entities?


------- code -------

ig.module( 'game.levels.main' )
.requires('impact.image')
.defines(function(){

LevelMyLevel=/JSON[/{"entities":[{"type":"MyEntity","x":123,"y":123}, // etc. etc.
}

------- end code -------

Let me know if there's some other way to get my entities into my game. Thanks!

1 decade ago by Graphikos

It's actually very simple using Game.spawnEntity.


ig.module( 
	'game.main' 
)
.requires(
	'game.entities.ball',
)
.defines(function(){

MyGame = ig.Game.extend({
	
	init: function() {
		this.spawnEntity(EntityBall, 100, 100);		
	},
	
});

ig.main( '#canvas', MyGame, 60, 320, 240, 2 );

});

This will spawn the ball entity at 100,100.

1 decade ago by hyliandanny

Thank you very much. That helped reach a solution!

Here's what I ended up with, in case it helps anyone else in the future.

ig.module( 
	'game.main' 
)
.requires(
	'impact.game',
	'impact.font',
	
	'game.entities.note',
	'game.entities.measure'
)

MyGame = ig.Game.extend({
	// ...

	init: function() {
		// ...
		this.spawnEntity(EntityNote, 10, 10);
	},

        // ...

While on my note.js file, I have...

ig.module(
    'game.entities.note'
)
.requires(
    'impact.entity'
)
.defines(function(){
    
EntityNote = ig.Entity.extend({
    size: {x:64, y:64},
    animSheet: new ig.AnimationSheet('media/note.png', 64, 64),

    init: function( x, y, settings ) {
        this.parent(x, y, settings);
        
        this.addAnim( 'idle', 0.1, [0]);

        // ...
    }
});

});
Page 1 of 1
« first « previous next › last »