I wrote a plugin to lazy load image from URL to prevent broken image in case of slow network..
Following this code:
And the answer is ctx == null or undefined
This is bug...???
My code segment here
// draw myImage
instanceProto.paint = function (myparam)
//alert("here: "+ this.runtime.id);
var _x = this.x;
var _y = this.y;
var _w = this.width;
var _h = this.height;
var image = new Image();
image.src = myparam;
//var c = $("#c2canvas")[0>;
ctx.drawImage(image, _x - _w/2, _y- _h/2, _w,_h);
this.image = image;
alert("what the heck...??");
So how do I solve this problem in case the runtime was changed...???
Thank in advanced
This code should never have worked. You can't call getContext on c2canvas, because it's already called that and you can only call it once. Further the c2canvas can also be a WebGL context if WebGL is supported.
Why not just use Sprite's 'Load image from URL'?
Develop games in your browser. Powerful, performant & highly capable.
Dear Asley..thank for your reply...
Actually in R95 my code work very fine....
I cannot using the LoadImage from URL in sprite because this feature is working very bad in case of large image or low bandwidth work.
It is meaning why I have to write my own plugin to get image.
In my game...player have it own Avatar and sprite doesn't redraw image after it is loaded already...
I just looking for solution for this problem...
Hope you have some suggestion for me in these cases...
Thank you very much.
Your code is definitely wrong, it must have worked by accident in r95.
So I believe that there are something wrong with LoadImage from URL of Sprite...So sorry because I don't know how to post capx file...:) but steps of reproduced this bug like that
System->OnStartLayout: Load image from URL ...."www.something.com"
Button->OnClick: Create Sprite then Load image from URL ...."www.somethingelse.com"
Result: Both image same from something.com
Expected: Images must be different
Thank you very much...
PS: this is reason I can't using LoadImage from URL of Sprite component..
For more information
The sprite at initial state have no image..
I am going to use LoadImageFromURL in case above problem solved...
Thank you very much...axx@Ashley