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 hellagot

Hi,

i am new to impact and trying to make a game without using a level from weltmeister.

So i have defined two entities, the first one only has base functionality, and the second one extends the first one and actually handles the visual stuff:


ig.module(
        'game.entities.board-tile'
)
.requires(
        'impact.entity'
)
.defines(function(){

EntityBoardTile = ig.Entity.extend({
        size: {x: 32, y: 32},
        init: function( x, y, settings ) {
                this.parent( x, y, settings );
        },

        update: function() {
                this.parent();
        }
});

});


and


ig.module(
        'game.entities.board-tile-defense'
)
.requires(
        'impact.entity',
        'game.entities.board-tile'
)
.defines(function(){

EntityBoardTileDefense = EntityBoardTile.extend({
        size: {x: 32, y: 32},
        animSheet: new ig.AnimationSheet( 'media/tiles/defense.png', 32, 32 ),

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

        update: function() {
                this.parent();
        }
});

});


After this i can create a new EntityBoardTileDefense in the map editor and position it on the map, but i do not want to use levels, so i use it in the main.js the following way:


        defense: null,


        init: function() {
                this.defense = this.spawnEntity( EntityBoardTile, 50, 50 );
        },

        draw: function() {
                // Draw all entities and backgroundMaps
                this.parent();

                for( var i = 0; i < this.entities.length; i++ ) {
                        ig.log( "drawing "+i+" at "+this.entities[i].pos.x+"/"+this.entities[i].pos.y );
                        this.entities[i].draw();
                }
        }

The log says it draws 0 at 50/50, but i do not see anything on the screen.

( well, now lets cross fingers that the post comes out as excpected, i love forums without preview )

Any ideas?

Thank you,
Heiko

1 decade ago by stahlmanDesign

You can edit your post by clicking edit to the right of your name at the top of your post. It appears when you roll over your name.

As for your problem, the code looks good at rough glance, but I've never tried to build an Impact game without a level. Sometimes when things don't appear it's because the screen redraw is erasing what you just drew. In that case it's usually a this.parent(); after your drawing code, but it looks like you did that, so I'm not sure without testing the code myself. Do you need the update method in your extended class that does the drawing?

1 decade ago by hellagot

thanx for the quick reply... the problem was simply, that i spawned EntityBoardTile, which has no image, what i needed to spawn is EntityBoardTileDefense of course.

problem solved
Page 1 of 1
« first « previous next › last »