[r114] Could not getContext from c2canvas element

Bugs will be moved here once resolved.

Post » Sun Jan 13, 2013 6:11 pm

I wrote a plugin to lazy load image from URL to prevent broken image in case of slow network..
Everything are fine in r95. But in r114 my javascript code is broken..??

Following this code:
///
var c=document.getElementById("c2canvas");
var ctx=c.getContext("2d");
/////
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);      
      //alert(this.x);
      var _x = this.x;
      var _y = this.y;
      var _w = this.width;
      var _h = this.height;
        //this.runtime.trigger(pluginProto.cnds.ImageLoaded,instance);
        var image = new Image();
        image.src = myparam;           
       var c=document.getElementById("c2canvas");
       //var c = $("#c2canvas")[0>;
       var ctx=c.getContext("2d");
       if(c.getContext("2d")!=null){       
        image.onload= function(){       
            ctx.drawImage(image, _x - _w/2, _y- _h/2, _w,_h);
        }
           //this.draw(con);
           //this.runtime.redraw=true;
        this.image = image;       
        }else{
            alert("what the heck...??");
        }
     };

     //////////////////////////////////////



So how do I solve this problem in case the runtime was changed...???

Thank in advanced
B
11
S
2
Posts: 73
Reputation: 1,438

Post » Tue Jan 15, 2013 3:58 pm

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'?
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Wed Jan 16, 2013 11:33 am

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.
B
11
S
2
Posts: 73
Reputation: 1,438

Post » Wed Jan 16, 2013 2:30 pm

Your code is definitely wrong, it must have worked by accident in r95.
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Wed Jan 16, 2013 2:42 pm

Dear Ashley
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 www.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..
B
11
S
2
Posts: 73
Reputation: 1,438

Post » Wed Jan 16, 2013 2:50 pm

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...@Ashley
B
11
S
2
Posts: 73
Reputation: 1,438


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 2 guests