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 kaboo

hello,

so i have this grass entity here
ig.module(
        'game.entities.grass'
    )
    .requires(
        'game.entities.trigger'
    )
    .defines(function(){

        EntityGrass = EntityTrigger.extend({
            message: "grass!!!",
            timer: null,
            font: new ig.Font( 'media/04b03.font.png' ),

            check: function(other) {
//                console.error("yo");
//                console.error(this.font);
//                console.error(this.message);
//                console.error(ig.system.width/2);
//                console.error(ig.system.height/2);
                this.font.draw(this.message, ig.system.width/2, ig.system.height/2);
//                this.timer = new ig.Timer(2)
            }
//            draw: function() {
//                if(this.timer && this.timer.delta() < 0) {
//                    this.font.draw(this.message, ig.system.width/2, ig.system.height/2)
//                }
//            }
        });

    });

it extends this trigger entity
ig.module(
        'game.entities.trigger'
    )
    .requires(
        'impact.entity'
    )
    .defines(function(){

        EntityTrigger = ig.Entity.extend({
            _wmDrawBox: true,
            _wmBoxColor: "rgba(0, 255, 0, 0.5)",
            _wmScalable: true,
            size: {x:48, y:48},
            checkAgainst: ig.Entity.TYPE.BOTH,
            type: ig.Entity.TYPE.NONE,
            collides: ig.Entity.COLLIDES.NEVER,
            update: function() {}
        });

    });

and for some reason the message is not being displayed, the console.errors are logged properly so the check function fires. ive been looking at this for quite some time now and i really cant see the problem - its pretty much just copy pasted version of kill entity from weltmeister tutorial. the font file is located at that path.

1 decade ago by Krisjet

You can't call this.font.draw() in your check method, it needs to be drawn in the draw() method of your Grass object. Your idea of setting up a timer during check() that determines whether to draw the font or not looks like it should work.

1 decade ago by kaboo

i moved it to the check function because it wasnt working in draw, the timer is firing correctly though and delta works as expected aswell. heres updated version of grass, the message is still not being displayed.

ig.module(
        'game.entities.grass'
    )
    .requires(
        'game.entities.trigger'
    )
    .defines(function(){

        EntityGrass = EntityTrigger.extend({
            message: "grass!!!",
            timer: null,
            font: new ig.Font( 'media/04b03.font.png' ),

            check: function(other) {
//                console.error("yo");
//                this.font.draw(this.message, ig.system.width/2, ig.system.height/2);
                this.timer = new ig.Timer(5)
            },
            draw: function() {
                if(this.timer && this.timer.delta() < 0) {
                    this.font.draw(this.message, ig.system.width/2, ig.system.height/2)
                }
            }
        });

    });

1 decade ago by Krisjet

You're not drawing anything on top of it? Any objects that have a higher zIndex will be drawn on top of this object, and the text.

1 decade ago by kaboo

nope i dont think so, the map is almost empty, it only has some borders, player entity, grass entity, a line of green tiles to represent the grass and thats it. is there a way to get/set zindex of objects?

1 decade ago by stillen

Don't you need a this.parent() in the draw function if you are extending it?

1 decade ago by kaboo

tried adding this.parent(), it didnt help.

also tried getting rid of grass altogether and put all of the code into trigger and replaced grass with trigger in wm aswell. font.draw still doesnt work...

1 decade ago by Krisjet

This trigger entity of yours, try putting this.parent() in it's update function. If you define an update function and specify it's not supposed to do anything I think it will do exactly that.

1 decade ago by kaboo

aahahhahaha :D, the font is too small and the text was hidden behind the player entity :D. anyway, thanks for the help
Page 1 of 1
« first « previous next › last »