[Sugar-devel] [Karma] question about image loading

Bryan Berry bryan at olenepal.org
Mon Aug 24 03:25:22 EDT 2009


Hey Felipe,

I am trying to add the sprite for the "happy monkey." The monkey starts
off in the normal position, then when the user gets the answer right I
want to briefly show the happy monkey image instead.

I am completely confused how to load the happy monkey
I am trying to 1st draw the normalmonkey w/

context.drawImage(....)

but how do I temporarily erase the normal monkey and draw the happy
monkey?

below is my current, horrible, ineffective code

	//draw monkey
	var monkeyNormalImg = new Image();
	var monkeySadImg = new Image();
	monkeyNormalImg.src = 'chimp/normal_200x209.png';
    	monkeySadImg.src = 'chimp/sad_200x209.png';

	monkeyNormalImg.onload = function () { 
	    monkeyCtx.drawImage(monkeyNormalImg, 0,20);
	};

	var redrawMonkey = function () {
	    	monkeySadImg.onload = function () { 
		    monkeyCtx.drawImage(monkeySadImg, 0,20);
		};
	        
	};



-- 
Bryan W. Berry
Technology Director
OLE Nepal, http://www.olenepal.org



More information about the Sugar-devel mailing list