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 wands

How do I overcome this problem?

I got a bullet as en entity, so I spawn it like this
var bullet = ig.game.spawnEntity( EntityLaser, x,y, { vel:  {x:500, y:500} } );

Initial, the bullet was moving like I expected. But after the browser is refreshed, the bullet entity's velocity and position properties becomes 0
I can still see the animation drawn onto the screen. It just stays at the pos x: 0, y:0

No matter how I re-code, every single time I refresh my browser, the properties becomes 0. Really need someone to enlighten me on this.

1 decade ago by drhayes

When you say "every single time I refresh my browser", what do you mean?

Your JS code has the above statement in it. You refresh the browser and it works. You refresh the browser again and it doesn't?

Please walk me through the steps like I'm a complete idiot.

1 decade ago by wands

This is my player1.js file
ig.module(
    'game.entities.player1'
)
.requires(
    'impact.entity'


)
    .defines(function(){

        EntityPlayer1 = ig.Entity.extend({

            animSheet: new ig.AnimationSheet('media/ship1.png',100,100),

            //angle: 0.76,
            speed: 350,
            maxVel: {x:500,y:500},




            init: function( x, y, settings ) {
                // Add animations for the animation sheet
                //ig.setNocache(true);
                this.addAnim( 'idle',1,[0]  );
                //this.currentAnim.angle = 2.96;
                //this.gravityFactor = 3;
               // this.friction.y = 3;
                //this.friction.x = 3;


                this.parent( x, y, settings );

            },

            update: function() {
                // This method is called for every frame on each entity.
                // React to input, or compute the entity's AI here.

                //var test = this.angleTo(EntityPlayer2);


                var angle = null;
                var players = ig.game.getEntitiesByType(EntityPlayer2);
                //
                if (players && players.length > 0) {
                    angle = this.angleTo(players[0]);
                }

                if (angle != null) {
                 this.currentAnim.angle = angle;
                }



                if(ig.input.state('right'))
                    this.vel.x = this.speed;
                if(ig.input.released('right'))
                    this.vel.x = 0;

                if(ig.input.state('left'))
                    this.vel.x = -this.speed;
                if(ig.input.released('left'))
                    this.vel.x = 0;

                if(ig.input.state('up'))
                    this.vel.y = -this.speed;
                if(ig.input.released('up'))
                    this.vel.y = 0;

                if(ig.input.state('down'))
                    this.vel.y = this.speed;
                if(ig.input.released('down'))
                    this.vel.y = 0;

                //console.log("V="+this.vel.x+" "+"F="+this.friction.x);

                if(ig.input.state('right') && ig.input.state('left'))
                    this.vel.x = 0;

                if(ig.input.pressed('player1_fire')){
                    //var bullet = ig.game.spawnEntity(EntityLaser, this.pos.x,this.pos.y);
                    var bullet = ig.game.spawnEntity( EntityLaser, this.pos.x, this.pos.y, {} );

                    //console.log("Bullet pos "+bullet.pos.x+" "+bullet.pos.y);
                    console.log(bullet.pos.x);

                }

                //this.currentAnim.angle = this.angle += 0.01;
                this.parent();
            }


        });

        EntityLaser = ig.Entity.extend({
            maxVel: {x: 600, y:600},
            vel: {x:500, y:500},
            name: 'laser',

            animSheet: new ig.AnimationSheet('media/laser.png',10,30),

            init: function( x, y, settings ) {
                // Call the parent constructor
                this.parent( x, y, settings );

                this.addAnim( 'idle',1,[0]  );
            },
            update: function() {
                this.parent();

                if(this.pos.x>300 && this.pos.y>300){
                    this.kill();
                    //console.log("killed");
                }

            }
        });

    });

As you can see, under the
var bullet = ig.game.spawnEntity( EntityLaser, this.pos.x, this.pos.y, {} );

This line of code works. But once browser is refreshed, the bullet entity.pos.x or y shows as 0. If anyone could help me check it, greatly appreciate it.

1 decade ago by wands

I found the problem. Could be a bug. Apparently, EntityLaser seems to be the issue. If I rename it to Entitylaser instead, everything works perfectly.

if i change to EntityBullet, it works as well.

Only the word EntityLaser, it doesn't like it. just WTH?!! This is not a cool story.

1 decade ago by wands

Where can I report this bug to?

1 decade ago by dungeonmaster

I'm not sure but you made

name:'laser'

Maybe when the entity name and the entity class name are the same, you have this issue.

Or maybe anywhere in your program, if you are doing smt. with entity named laser then it might be the issue.

I don't know your brewer but if it's chrome, it's pretty stubborn to erease the cache. Make sure you make 'empty cache and hard reload' when you change the code. or use firefox/safari.
Page 1 of 1
« first « previous next › last »