I am new to famo.us and cloned the start example.
What I was trying to do, is to create a CanvasSurface
, create an Image
, load ImageData into it, then draw()
the Image
onto the canvas' context.
The strange thing is, that it works once, when not defining a custom size. When refreshing Firefox the image is loaded, but not seen.
However, I want to have the canvas behave as if it had the css style:
width:100%;
Therefore effectively scaling the drawn image, so that it's width corresponds with the window size.
If somebody could point me to my obvious mistake, why the image is not rendered onto the canvas, I'd be very happy.
http://codefamo.us/g/#gist=caeb0ba013ed3f955f33
/*global famous*/
// import dependencies
var Engine = famous.core.Engine;
var Modifier = famous.core.Modifier;
var Transform = famous.core.Transform;
//var ImageSurface = famous.surfaces.ImageSurface;
var CanvasSurface = famous.surfaces.CanvasSurface;
var Surface = famous.core.Surface;
// create the main context
var mainContext = Engine.createContext();
var backgroundCanvas = new CanvasSurface({
size: [undefined, false]
});
var backgroundContext = backgroundCanvas.getContext('2d');
var imageObj = new Image();
imageObj.src = 'http://upload.wikimedia.org/wikipedia/commons/f/fe/WelteHandnuancierung.jpg';
imageObj.onload = function() {
console.log("images loaded. has width: " + imageObj.width);
backgroundContext.drawImage(imageObj, 0, 0);
};
mainContext.add(backgroundCanvas);