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 paulh

well i lost all my work for last two months, dont forget to back up online everyone!!

dropbox autosyncs: http://db.tt/pPQI3CJh


Lastly, im naturally trying to get my game working, from scratch again :-(

Actually its ok, i think i can write it pretty quickly and possibly better .. my first problem is why my particles (using the particle plugin) are displayed UNDER the menu image?

ig.module( 
	'game.intro' 
)
.requires(
        'game.entities.particle',
	'impact.game'
	
)
.defines(function(){

Intro = ig.Game.extend({
	
	font: new ig.Font( 'media/04b03.font.png' ),
	MenuImage: new ig.Image( 'media/menu.jpg' ),

    init:function(){	
        ig.input.bind( ig.KEY.MOUSE1, 'left');
    },
        
    draw: function() {
		
	  this.MenuImage.draw( -220, -275 ); 
	   
	},
        
    update:function(){
    
    if (ig.input.state('left')) {
            console.log('left!')
            ig.game.spawnEntity( FireGib, 200, 200 );
        }
        this.parent();
    }


});
});

1 decade ago by Graphikos

I&039;m surprised the particles draw at all. You need to make sure you have #this.parent() in your draw function. Placing this.parent() after your MenuImage draw should draw entities after (on top) of the menu. Everything in Impact (and canvas) is all about draw order.

1 decade ago by paulh

hmm i have tried many different variations of this.parent(); but i cna still only get particles and menu items visible or the image drawn over the top?

 init: function() {
    ig.input.bind( ig.KEY.MOUSE1, 'mouseLeft' );
    //ig.game.spawnEntity(EntityStats,0,0);//spawn the game stats
    var mx = ig.input.mouse.x ; //Figures out the x coord of the mouse in the entire world
    var my = ig.input.mouse.y; //Figures out the y coord of the mouse in the entire world
    
    
        this.MenuImage.draw( 0, 0 );
        
       // this.loadLevel( LevelTest );// LOAD LEVEL DATA
        ig.game.spawnEntity(EntityMenu,22 ,46, { blockType:"Match" } );//spawn a menu item
        ig.game.spawnEntity(EntityMenu,180 ,16, { blockType:"Free" });//spawn a menu item
        ig.game.spawnEntity(EntityMenu,342 ,46, { blockType:"Story" });//spawn a menu item
        
        ig.game.spawnEntity(EntityMenu,12 ,200, { blockType:"Time" });//spawn a menu item
        ig.game.spawnEntity(EntityMenu,180 ,200, { blockType:"Options" });
        ig.game.spawnEntity(EntityMenu,340 ,200, { blockType:"Level" });//spawn a menu item
    
    this.parent();
    
    },
    
run: function(){
    if (ig.input.state('mouseLeft')) {
    ig.game.spawnEntity( FireGib, 200,120 );
}
    this.parent();
    }

1 decade ago by paulh


/dropbox/impact/spellpop/lib/game/intro.js:35

Uncaught TypeError: Object [object Object] has no method 'parent'

1 decade ago by quidmonkey

As the error message says, .init() has no parent method: that is to say, ig.Game.init() does not exist. Comment out that line, and you'll be fine.

1 decade ago by Graphikos

I'm not sure what you got going here now... why did you move the draw to init()?

1 decade ago by paulh

ugh , i changed the draw to init because when i was using draw i ended up drawing the entitites every frame?

this is now worse, as im drawing 6 entities a frame and the menu background still doesn't get draw :-)

i am self taught and i guess im missing some fundamentals :-(

ig.module( 
	'game.intro' 
)
.requires(
        
	'impact.game'
	
)
.defines(function(){

Intro = ig.Game.extend({
	
	font: new ig.Font( 'media/04b03.font.png' ),
	MenuImage: new ig.Image( 'media/menu.jpg' ),
       

 init: function() {
    ig.input.bind( ig.KEY.MOUSE1, 'mouseLeft' );
    //ig.game.spawnEntity(EntityStats,0,0);//spawn the game stats
   
 },
 
 draw:function(){
       this.MenuImage.draw( 0, 0 );
        
       // this.loadLevel( LevelTest );// LOAD LEVEL DATA
        ig.game.spawnEntity(EntityMenu,22 ,46, { blockType:"Match" } );//spawn a menu item
        ig.game.spawnEntity(EntityMenu,180 ,16, { blockType:"Free" });//spawn a menu item
        ig.game.spawnEntity(EntityMenu,342 ,46, { blockType:"Story" });//spawn a menu item
        
        ig.game.spawnEntity(EntityMenu,12 ,200, { blockType:"Time" });//spawn a menu item
        ig.game.spawnEntity(EntityMenu,180 ,200, { blockType:"Options" });
        ig.game.spawnEntity(EntityMenu,340 ,200, { blockType:"Level" });//spawn a menu item
    
    
    this.parent();
    },
    
update: function(){
    var mx = ig.input.mouse.x ; //Figures out the x coord of the mouse in the entire world
    var my = ig.input.mouse.y; //Figures out the y coord of the mouse in the entire world
    
    if (ig.input.state('mouseLeft')) {
    ig.game.spawnEntity( FireGib, mx,my );
    
    }
    this.parent();
    
}

                
});
});


i think ive put this.parent(); in every possible location and combination

1 decade ago by paulh

im calling intro from main:

ig.module( 
	'game.main' 
)
.requires(
	'impact.game',
	'game.intro',

	'game.entities.particle',
	'game.entities.menu',
	 
	'game.plugins.impact-splash-loader',
	
	'impact.debug.debug', // <- Add this
	'impact.font'
)
.defines(function(){

MyGame = ig.Game.extend({
	
	// Load a font
	font: new ig.Font( 'media/04b03.font.png' ),
	introImage: new ig.Image( 'media/intro.jpg' ),
	
	
	init: function() {
		// Initialize your game here; bind keys etc.
		  this.timer = new ig.Timer(1.5);
	},
	
	update: function() {
		// Update all entities and backgroundMaps
		this.parent();
		// Add your own, additional update code here
	},
	
	draw: function() {
		// Draw all entities and backgroundMaps
		if (this.timer.delta() > 0) {
		console.log("one second");
		ig.system.setGame(Intro);
		}
		this.parent();
		this.introImage.draw( 0, 0 );
	}
});


// Start the Game with 60fps, a resolution of 320x240, scaled
// up by a factor of 2
ig.main( '#canvas', MyGame, 60, 480, 320, 1, ig.ImpactSplashLoader );

});


Cant seem to grasp what im doing wrong here, its a simple mistake im sure!!

1 decade ago by paulh

So this gives me the 75% of the functionality i want:

+7 draws and 6 entities
+the menu items are visible
+the particles update and are visible

--the background image is not visible


I remember now that i ran into this last time and just loaded a level with the background in it ...but that feels like im cheating :-)

ig.module( 
	'game.intro'
)
.requires(
        'impact.game'
	
)
.defines(function(){

Intro = ig.Game.extend({
	
	font: new ig.Font( 'media/04b03.font.png' ),
	MenuImage: new ig.Image( 'media/menu.jpg' ),
       
 

 init: function() {
    ig.input.bind( ig.KEY.MOUSE1, 'mouseLeft' );
    //ig.game.spawnEntity(EntityStats,0,0);//spawn the game stats
        ig.game.spawnEntity(EntityMenu,22 ,46, { blockType:"Match" } );//spawn a menu item
        ig.game.spawnEntity(EntityMenu,180 ,16, { blockType:"Free" });//spawn a menu item
        ig.game.spawnEntity(EntityMenu,342 ,46, { blockType:"Story" });//spawn a menu item
        
        ig.game.spawnEntity(EntityMenu,12 ,200, { blockType:"Time" });//spawn a menu item
        ig.game.spawnEntity(EntityMenu,180 ,200, { blockType:"Options" });
        ig.game.spawnEntity(EntityMenu,340 ,200, { blockType:"Level" });//spawn a menu item
        
   
 },

  draw:function(){
    
        this.MenuImage.draw( 0, 0 );
        this.parent();

    },
    
update: function(){
    
    if (ig.input.state('mouseLeft')) {
    ig.game.spawnEntity( FireGib, ig.input.mouse.x,ig.input.mouse.y );
    
    }
    this.parent();
}

});
});


naturally ive tried placing

   this.MenuImage.draw( 0, 0 );
        this.parent();

In various locations and orders.

1 decade ago by paulh

i guess what im not getting is this :

IF i initialise, shouldn't it be:

init:fucntion(){

draw background (so its only drawn once)
draw entities ( ontop of the background)
}

Draw:function(){
this is drawn every frame, why would i put a background image in here,
 if i only want to draw it once?
}

Update:function(){

check mouse
draw particles each frame

}


I guess im also not really understanding what this.parent(); does...

so frustrating, dont want to resort to laoding a level again..

1 decade ago by Graphikos

There are a few things you need to understand about canvas. Think of it in realistic terms. You have canvas that you paint on. Lets go all Bob Ross with this.

You paint a nice backdrop (your static background) on your canvas and then you paint a bird (an entity). Then you think... I want that bird to fly. Well you've already painted the bird covering the part of the backdrop so moving it you have to repaint what use to be there. You achieve this with canvas by redrawing the background every frame and then draw your entities.. thus creating the animation you are looking for. The only way you could "draw once" is if you never draw on top of something moving on top of it.

By default Impact clears the canvas by drawing black every frame. This wipes out everything that use to be there. You can change this by altering .clearColor. Setting it to null would let you draw a background image and actually be able to see if after the clear.

init() will only be called once... when the game is initiated. It&039;s a good place to set settings, load the first level, spawn entities, bind keys, etc. etc. Anything that is drawn here will get covered by the #update() and draw() which run every single frame.

Calling this.parent() calls the method of the super class. In other words if you are specifying a draw() method to do your own draws you are replacing Impact&039;s own #draw() method . Calling this.parent() within your draw() method returns back to impact&039;s method and runs it like normal allowing the engine to do what it needs to do. Generally speaking you will always call #this.parent() unless you really want to suppress the default actions of impact for that method.

When talking about entities and when they do their thing it&039;s once again all about the #update() and draw() methods. Update is when an entity does all its collision checks, movement, etc. etc. Draw is when an entity actually draws it&039;s animation sheet. So when you call #this.parent() in the draw and update methods this is when Impact will do those things for the entities.

Remember that drawing on canvas is all about the order in which you do it. So to put it all together to get it to look correct every frame you need to:

For draw():

1) Draw your background image. If this is a static image make sure you set this.clearColor = null in your game&039;s #init().

2) Let your entities draw. Call this.parent() to let Impact draw the entities.

3) Draw your menu image or whatever else you want on top of the entities.

You pretty much had it correct. You are missing the tweak to .clearColor to get your background to show and maybe a bit of a draw order issue but easily to fix that also.

I hope the helps clear up some confusion you had about how things work. It's not an easy thing to explain.

1 decade ago by alexandre

Your image is in jpeg format: it does not support transparency. So, if your game class calls ig.Game's draw first, you will not be able to see the entities you spawned because the jpeg will hide them:
draw: function ()
{
  this.parent();
  this.MenuImage.draw(0,0);
}

If on the other hand you draw the image first before calling ig.Game's draw, your image will not be visible because ig.Game's draw method clears the screen when invoked...
draw: function ()
{
  this.MenuImage.draw(0,0);
  this.parent();
}

unless, that is, you override the value of your clearColor property:
clearColor: null,

draw: function ()
{
  this.MenuImage.draw(0,0);
  this.parent();
}

EDIT: and there you go... I posted after Graphikos had posted his in-depth explanation of how Impact works... Anyway, you can consider this a synopsis.

1 decade ago by paulh

This community continues to amaze me, i was just showing my partner how much a "stranger" wrote to help me out, she was also pretty amazed to.

Thank you everyone!

1 decade ago by Graphikos

We're not strangers around here... this is a tight community. ;)

1 decade ago by alexandre

We're not strangers around here... this is a tight community. ;)


Sorry. Who are you again?
:p
Page 1 of 1
« first « previous next › last »