New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createGraphics does not work with p5.play in instance mode. #104

Closed
arorag2396 opened this Issue Jul 26, 2016 · 7 comments

Comments

Projects
None yet
3 participants
@arorag2396

arorag2396 commented Jul 26, 2016

p.setup = function () {
            canvas = p.createCanvas(1000, 1000);
            pg = p.createGraphics(1000, 1000);
}
Uncaught TypeError: pInst.createVector is not a function
Camera @ p5.play.js:2387
(anonymous function) @ p5.play.js:2359
get @ p5.play.js:58
p5.Graphics @ p5.js:11555
p5.createGraphics @ p5.js:13288
p.setup @ RTChess.js:58
(anonymous function) @ p5.js:8900
_runIfPreloadsAreDone @ p5.js:8853
_decrementPreload @ p5.js:8862i
mg.onload @ p5.js:17669

It works in non instance mode, but seems not be working for instance mode. Am I doing something wrong?

@ycatch

This comment has been minimized.

Show comment
Hide comment
@ycatch

ycatch Oct 12, 2016

Hi, there.

I tried p5.js and p5.play in instance mode, like this.

<html>
<head>
  <meta charset="UTF-8">
  <style> body {padding: 50; margin: 0;} </style>
</head>

<body>
    <script src="p5.js"></script>
    <script src="p5.play.js"></script>
    <script>
    var s = function(p) {

        var sq;
        var layer;
        p.setup = function() {
            p.createCanvas(800,400);
            p.background(200);
            layer = p.createGraphics(400, 200, 0, 0);
            sq = p.createSprite(400, 200, 50, 50);
        }

        p.draw = function() {
            p.drawSprites();
            p.image(layer);
        }
    }

    var myp5 = new p5(s);
    </script>
</body>
</html>

However, I had an error message.

TypeError: pInst.createVector is not a function

When I commented createGraphics out, it worked.

ycatch commented Oct 12, 2016

Hi, there.

I tried p5.js and p5.play in instance mode, like this.

<html>
<head>
  <meta charset="UTF-8">
  <style> body {padding: 50; margin: 0;} </style>
</head>

<body>
    <script src="p5.js"></script>
    <script src="p5.play.js"></script>
    <script>
    var s = function(p) {

        var sq;
        var layer;
        p.setup = function() {
            p.createCanvas(800,400);
            p.background(200);
            layer = p.createGraphics(400, 200, 0, 0);
            sq = p.createSprite(400, 200, 50, 50);
        }

        p.draw = function() {
            p.drawSprites();
            p.image(layer);
        }
    }

    var myp5 = new p5(s);
    </script>
</body>
</html>

However, I had an error message.

TypeError: pInst.createVector is not a function

When I commented createGraphics out, it worked.

@islemaster

This comment has been minimized.

Show comment
Hide comment
@islemaster

islemaster Oct 12, 2016

Collaborator

Hi there! createGraphics is a method defined by the p5.js library, not specifically by p5.play. Does this problem only occur when you are using p5.play? If not, you may want to re-open this issue over at https://github.com/processing/p5.js.

I'll be happy to investigate later today if the problem is specific to p5.play.

Collaborator

islemaster commented Oct 12, 2016

Hi there! createGraphics is a method defined by the p5.js library, not specifically by p5.play. Does this problem only occur when you are using p5.play? If not, you may want to re-open this issue over at https://github.com/processing/p5.js.

I'll be happy to investigate later today if the problem is specific to p5.play.

@islemaster islemaster self-assigned this Oct 12, 2016

@arorag2396

This comment has been minimized.

Show comment
Hide comment
@arorag2396

arorag2396 Oct 13, 2016

@islemaster Yes, this problem is specific to p5.play. I have used createGraphics couple of times in p5.js, where I didn't use p5.play.
Thanks!

arorag2396 commented Oct 13, 2016

@islemaster Yes, this problem is specific to p5.play. I have used createGraphics couple of times in p5.js, where I didn't use p5.play.
Thanks!

@ycatch

This comment has been minimized.

Show comment
Hide comment
@ycatch

ycatch Oct 13, 2016

islemaster thank you for your comment.
I posted this issue to p5.js/

processing/p5.js#1635

ycatch commented Oct 13, 2016

islemaster thank you for your comment.
I posted this issue to p5.js/

processing/p5.js#1635

@islemaster

This comment has been minimized.

Show comment
Hide comment
@islemaster

islemaster Oct 19, 2016

Collaborator

I've done some investigation here. The problem is that createGraphics attempts to clone all methods and properties from p5's prototype into the graphics context, and the p5.prototype.camera added by p5.play is failing to lazy-create in instance mode (with or without createGraphics).

This is a symptom of a larger issue we've known about for some time; if we can fix #46 it should take care of this too. I'll spend a little more time seeing if I can get the camera to create using the current workaround, but it may be best to eat our vegetables and use the new approach to add properties to the prototype.

Collaborator

islemaster commented Oct 19, 2016

I've done some investigation here. The problem is that createGraphics attempts to clone all methods and properties from p5's prototype into the graphics context, and the p5.prototype.camera added by p5.play is failing to lazy-create in instance mode (with or without createGraphics).

This is a symptom of a larger issue we've known about for some time; if we can fix #46 it should take care of this too. I'll spend a little more time seeing if I can get the camera to create using the current workaround, but it may be best to eat our vegetables and use the new approach to add properties to the prototype.

@islemaster

This comment has been minimized.

Show comment
Hide comment
@islemaster

islemaster Oct 20, 2016

Collaborator

This should be resolved by #119. It's a fairly sizable change, so I'm going to wait on review from one of the other maintainers to merge; you could certainly pull that branch and use it though.

Collaborator

islemaster commented Oct 20, 2016

This should be resolved by #119. It's a fairly sizable change, so I'm going to wait on review from one of the other maintainers to merge; you could certainly pull that branch and use it though.

@ycatch

This comment has been minimized.

Show comment
Hide comment
@ycatch

ycatch Oct 26, 2016

Thank you, @islemaster .
#119 works in instance mode with createGraphics.
Yeah!!

ycatch commented Oct 26, 2016

Thank you, @islemaster .
#119 works in instance mode with createGraphics.
Yeah!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment