1 decade ago by Fooshi
i have a problem again (i'm very beginer on impact .. :( )
I have created two entities : FondEntity get image data of a canvas et copy some pixel in my main canvas to ducplicate when mouse is pressed (like a scratch ticket), my second entity TestEntity is just a png to display but it don't displayed !
here is my code :
thank you, the begin is hard for me !
I have created two entities : FondEntity get image data of a canvas et copy some pixel in my main canvas to ducplicate when mouse is pressed (like a scratch ticket), my second entity TestEntity is just a png to display but it don't displayed !
here is my code :
ig.module( 'game.test' ) .requires( 'impact.impact', 'impact.game', 'impact.animation', 'impact.entity', 'impact.image', 'impact.input', 'impact.system' ) .defines(function(){ // Entity FondEntity = ig.Entity.extend({ first : new ig.Image('media/first.png'), animSheet : new ig.AnimationSheet('media/first.png',320,480), FondCtx : null, init : function(x,y,settings){ this.parent(x,y,settings ); var FondCanvas = document.getElementById("fond"); // Recupere le canvas de fond this.FondCtx = FondCanvas.getContext("2d"); this.addAnim('idle',1,[0]); this.first.draw(0,0); }, update : function(){ if(ig.input.state('scratch')) { var FondImg; for(var y=0; y<20; ++y) { var x = (Math.sqrt(400-(y*y))).round(); for(var i=0; i<x; ++i) { FondImg = this.FondCtx.getImageData(ig.input.mouse.x+i,ig.input.mouse.y+y,1,1); ig.system.context.putImageData(FondImg,ig.input.mouse.x+i,ig.input.mouse.y+y); FondImg = this.FondCtx.getImageData(ig.input.mouse.x-i,ig.input.mouse.y+y,1,1); ig.system.context.putImageData(FondImg,ig.input.mouse.x-i,ig.input.mouse.y+y); FondImg = this.FondCtx.getImageData(ig.input.mouse.x+i,ig.input.mouse.y-y,1,1); ig.system.context.putImageData(FondImg,ig.input.mouse.x+i,ig.input.mouse.y-y); FondImg = this.FondCtx.getImageData(ig.input.mouse.x-i,ig.input.mouse.y-y,1,1); ig.system.context.putImageData(FondImg,ig.input.mouse.x-i,ig.input.mouse.y-y); } } } } }); // Entity TestEntity = ig.Entity.extend({ size : {x:10, y:10}, animSheet : new ig.AnimationSheet('media/particles.png',10,10), init : function(x,y,settings){ this.parent(x,y,settings ); this.addAnim('idle',1,[0]); }, update : function(){ this.currentAnim = this.anims.idle; this.parent(); } }); // Game TotemGame = ig.Game.extend({ FondCtx : null, init : function(){ var FondCanvas = document.getElementById("fond"); // Recupere le canvas de fond this.FondCtx = FondCanvas.getContext("2d"); ig.input.bind(ig.KEY.MOUSE1, 'scratch'); // Ecouteur de la souris ig.game.spawnEntity(FondEntity,0,0); ig.game.spawnEntity(TestEntity,0,0); }, update : function(){ this.parent(); }, draw : function(){ } }); ig.main('#canvas', TotemGame, 60, 320, 480, 1); }); // Init the background Canvas function init() { var fond = document.getElementById("fond"); var imageFond = new Image(); var imageFond1 = new Image(); if (fond.getContext) { ctx = fond.getContext("2d"); imageFond.onload = function() { ctx.drawImage(imageFond,0,0); } imageFond1.onload = function() { ctx.drawImage(imageFond1,0,0); } imageFond.src = "media/fond.jpg"; imageFond1.src = "media/euro1.png"; } }
thank you, the begin is hard for me !