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 Warspawn

Here is a star field background class I made. It uses the context to draw the stars dynamically. gist

1 decade ago by Terry

In your code on line 11 you forgot Entity infront of Starfield.

How can I control the density of the stars?

1 decade ago by Warspawn

is the Entity prefix some sort of required naming convention that WM looks for or something? I'm new to ImpactJS and don't know.

Also when you init the starfield, the first param is starCount. So if you want more stars, that's the way. Also, I have 2 of them with different counts scrolling at different speeds on top of each other to give a more dense effect.

1 decade ago by Warspawn

for those interested, I just updated the class now that I've learned a bit more about ImpactJS... now it extends BackgroundMap so that you can add them to the background array to get rendered. Still you will have to manually call update as the backgroundMaps array in game doesn't have an update normally.

for example:

// main.js
ig.module('game.main')
.requires(
    'impact.debug.debug',
    'impact.game',
    'game.starfield'
)
.defines(function() {
    SpaceBlasterGame = ig.Game.extend({
        version: '1.0',
        font: new ig.Font( 'media/04b03.font.png' ),
        init: function() {
            this.backgroundMaps.push(
                new Starfield(250, {vel: {x: 0, y: 100}}),
                new Starfield(150, {vel: {x: 0, y: 200}}),
                new Starfield(550, {vel: {x: 0, y: 20}})
            );
        },
        update: function() {
            this.parent();

            for(var i=0;i<this.backgroundMaps.length;i++) {
                if(this.backgroundMaps[i].update) {
                    this.backgroundMaps[i].update();
                }
            }
        },
        draw: function() {
            this.parent();

            this.font.draw( 'Version: ' + this.version, 8, ig.system.height - 8, ig.Font.ALIGN.LEFT );
        }
    });

    ig.main('#canvas', SpaceBlasterGame, 60, 600, 800, 1);
});

1 decade ago by Joncom

Quote from Warspawn
is the Entity prefix some sort of required naming convention that WM looks for or something? I'm new to ImpactJS and don't know.

If it was an entity you were extending, then yes. The convention would be to name the entity EntityStarfield. But since it&039;s not an entity, but rather a #backgroundMap, don't worry about it.

PS - Might be cool if you had a demo up so people could see what sort of effect this achieves.
Page 1 of 1
« first « previous next › last »