I am trying to print on the middle of the screen when the player reaches a new level. I have tried lots of ways but the result is always the same in that the screen freezes as long as the entity is active. This works just fine if I use an animation, but if I try to just use text it messes up.
EntityLevelHud = ig.Entity.extend({
collides: ig.Entity.COLLIDES.NEVER,
font: new ig.Font('media/04b03.font.png'),
size: { x: 40, y: 40 },
//animSheet: new ig.AnimationSheet( 'media/coinscore.png', 40, 40 ),
timer: 100,
scroll: false,
init: function( x, y, settings ) {
//this.addAnim( 'idle', 0.1, [0] );
this.parent( x, y, settings );
},
update: function() {
this.parent();
if ( --this.timer <= 0 ) {
this.kill();
}
var levelString = "Level " + this.level.toString();
this.font.draw( levelString, this.pos.x, this.pos.y );
}
});
Don't draw inside the update method.
Also, EntityLevelHud's level property is undefined. Unless set in WM, toString() will raise an exception.
Sample fix:
level: 'UNKNOWN',
draw: function()
{
this.parent();
this.font.draw('Level' + this.level, this.pos.x, this.pos.y);
}
Cheers.
Also, a good habit to take is to set gravityFactor to 0 for such entities as are not supposed to be affected by gravity.
Thanks very much, I did not realize putting that inside the update function would do that, but definitely my bad on not referencing where i stored the player level correctly. Here is the updated version, the next thing I need to ask is why the scrolling is choppy for text printed to the screen but not if I used an animation? I used the drop game as a reference for scrolling the screen.
EntityLevelHud = ig.Entity.extend({
collides: ig.Entity.COLLIDES.NEVER,
font: new ig.Font('media/font.png'),
size: { x: 40, y: 40 },
animSheet: new ig.AnimationSheet( 'media/coinscore.png', 40, 40 ),
timer: 100,
scroll: false,
gravityFactor: 0,
init: function( x, y, settings ) {
//this.addAnim( 'idle', 0.1, [0] );
this.parent( x, y, settings );
},
update: function() {
this.parent();
if ( --this.timer <= 0 ) {
this.kill();
}
},
draw: function() {
this.parent();
this.font.draw( 'Level' + ig.game.level, this.pos.x, this.pos.y );
}
});
// Move screen and entities one tile up
this.screen.y -= 40;
for( var i =0; i < this.entities.length; i++ ) {
if ( this.entities[i].scroll != false ) {
this.entities[i].pos.y -= 40;
}
}
If I use an animation image, the image scrolls very smoothly, when I switched to the text display, it was jumping by 40 pixels on an update. Any ideas?
My code may be a bit misleading, I put in the scroll = false part and the check in the scrolling section to stop it from scrolling until I can fix it.
How is the scrolling section declared and defined?
I am not sure where the scrolling part is actually defined for the impact system, but the section I posted is the part of the code that shifts the screen by 40 pixels.
update: function() {
if( ig.input.pressed('ok') ) {
ig.system.setGame( DropGame );
}
if( this.gameOver ) {
return;
}
this.speed += ig.system.tick * ((10/this.speed)*this.level);
this.screen.y += ig.system.tick * this.speed;
this.score += ig.system.tick * this.speed;
// Do we need a new row?
if( this.screen.y > 200 ) {
// Move screen and entities one tile up
this.screen.y -= 40;
for( var i =0; i < this.entities.length; i++ ) {
if ( this.entities[i].scroll != false ) {
this.entities[i].pos.y -= 40;
}
}
// Delete first row, insert new
this.map.shift();
this.map.push(this.getRow());
What's your game's clearColor set to? If set, try any other value than null.
I removed my clearColor line so that it would stay at the default value and that did not fix the choppy scrolling but it did remove my background image.
Page 1 of 1
« first
« previous
next ›
last »