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 Ransome

I'm making a series of minigames using Impact and there are a lot of custom images thrown in, so I made a generic EntityImpactImage which would load an image but I could treat like an entity. It has its own draw code and a rudimentary scaling. I can select the entity from the entity pulldown in Weltmeister but as it loads dynamic content nothing shows up, so I'm trying to get Welty to draw a box I can use for reference. I set the usual _wm properties, and when I create the entity it seems to appear in the map file but the guide boxes don't appear. Here's the code:

ig.module(
    'game.entities.ui.impactimage'
).requires(
    'impact.entity'
).defines(function() {

    EntityImpactimage = ig.Entity.extend({
        _wmDrawBox:true,
        _wmScalable:true,
        _wmBoxColor:'#FF00000',
        size:{x:20,y:20},
        collides: ig.Entity.COLLIDES.NEVER,
        
        /* settings:
         * {img:ig.Image('imagefilename')}
         * width height
         */
        init: function(x,y,settings) {
          this.parent(x,y,settings);
          this.image = ig.copy(this.img);
          if(typeof(this.scale) != 'undefined') {
            this.image.resize(this.scale);
            this.image.width = this.image.width * this.scale;
            this.image.height = this.image.height * this.scale;
          }
        },

        draw: function() {
          this.parent();
          this.image.draw(this.pos.x,this.pos.y);
        }
        
    });
});

Any thoughts on why the draw box isn't showing up? Maybe I missed a step?

1 decade ago by dominic

#FF00000 is not a valid color. Count the zeros - should be 4 :)

Edit: Btw., why do you do the this.image = ig.copy(this.img); step, instead of directly using this.img? Also:
Note that this function can't copy instances of ig.Class or subclasses thereof and just returns them uncopied.

~ http://impactjs.com/documentation/class-reference/ig-core#ig-copy

1 decade ago by Ransome

Ah, yes, good catch on the #FF0000, I corrected that. I think I chose to do the copy so that, if the ig.Image object the entity was referencing should get overwritten, the entity would have its own version. I think this was added while addressing a bug on one of the games, but I'm not sure it ever actually fixed the issue. Since you note that it shouldn't work, I've removed the code for the time being and did a plain ol' this.image = this.img

I was able to resolve my issue to an extent. It seems that draw call I did messed with Welty's draw system. After removing the

this.image.draw(this.pos.x,this.pos.y);

in the draw() function I now see the boxes in Weltmeister fine. Now I just need to find that flag that tells me whether I'm in the editor or in run mode and I'll be set. Thanks as always for taking a look dominic, and good to know about the ig.copy.

1 decade ago by dominic

if( !ig.global.wm ) {
    // not in wm
}

1 decade ago by Ransome

Beautiful, thank you :)
Page 1 of 1
« first « previous next › last »