0

I am having problems with javasript OOP. Currently, I have two short files.

player.js

function Player(x,y,source){
    this.hp = 100;
    this.speed = 5;
    this.posx = x;
    this.posy = y;
    this.img = new Raster({
        source: source,
        position: new Point(x,y)
    });

    this.displayPlayer();
}    
Player.prototype = {
    constructor: Player,
    displayPlayer:function(){
        this.img.position = new Point(this.posx, this.posy);
    }
};

index.html

<html>
    <head>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script src="http://paperjs.org/assets/js/paper.js" type="text/javascript"></script>
        <style>html{background-color:#DDDDDD;}</style>

        <script src="player.js" type="text/javascript"></script>
        <script src="powerup.js" type="text/javascript"></script>

        <script type="text/paperscript" canvas="myCanvas">
            red = new Player(100,100,'red.png');
        </script>

    </head>

    <body>
        <canvas id="myCanvas" width="600" height="600" style="background-color:#FFFFFF !important;"></canvas>
    </body>
</html>

All I get is a blank screen with nothing.

Link: http://onlyabutton.com/projects/pixelrage/

2
  • Uncaught ReferenceError: Raster is not defined Commented Jan 24, 2014 at 20:16
  • thanks, let me check. Commented Jan 24, 2014 at 20:17

2 Answers 2

1

Maybe you have some paper configuration error. All paper.js structures is hidden in paper object. So you must call it like this

new paper.Raster(....

and code is like this

function Player(x,y,source){
    this.hp = 100;
    this.speed = 5;
    this.posx = x;
    this.posy = y;
    this.img = new paper.Raster({
        source: source,
        position: new paper.Point(x,y)
    });

    this.displayPlayer();
}    
Player.prototype = {
    constructor: Player,
    displayPlayer:function(){
        this.img.position = new paper.Point(this.posx, this.posy);
    }
};

This is not a solution, this is a dirty code.

Sign up to request clarification or add additional context in comments.

1 Comment

I not know the paper.js but maybe the code inside this "<script type="text/paperscript" canvas="myCanvas">" must run with paper private scope. Recheck the examples.
0

Raster is not being defined and is giving you a ReferenceError.

Are you sure you correctly linked to/implemented Paper.js?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.