Javascript eigenes Objekt - Uncaught TypeError: object is not a function

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Javascript eigenes Objekt - Uncaught TypeError: object is not a function

    Guten Abend,
    ich bin momentan dabei den Klassiker Doodle Jump für HTML5 zu scripten, allerdings bin ich grad eben beim Testen des ersten Codes gescheitert. Als Fehlercode bekomm ich Uncaught TypeError: object is not a function.

    Hier mein Code:

    index.html

    Quellcode

    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <title>Canvas</title>
    5. <script type="text/javascript" language="javascript" src="game.js"></script>
    6. <script language="javascript" type="text/javascript">
    7. window.onload = function(){
    8. var Test = new Game();
    9. };
    10. </script>
    11. <script language="javascript" type="text/javascript">
    12. </script>
    13. <style type="text/css">
    14. #game_canvas{
    15. background-image: url(images/paper.gif);
    16. background-repeat: repeat;
    17. border: 1px black solid;
    18. -moz-border-radius: 5px;
    19. border-radius: 5px;
    20. box-shadow: 0px 0px 6px black;
    21. }
    22. </style>
    23. </head>
    24. <body>
    25. <canvas id="game_canvas">
    26. </canvas>
    27. </body>
    28. </html>
    Alles anzeigen


    game.js

    Quellcode

    1. var Game = {
    2. canvas: null,
    3. context: null,
    4. width: null,
    5. height: null,
    6. fps: null,
    7. player: null,
    8. bg_image: null,
    9. init: function(cvs_id, cvs_width, cvs_height, fps){
    10. this.canvas = document.getElementById(cvs_id);
    11. this.context = canvas.getContext('2D');
    12. this.width = cvs_width;
    13. this.height = cvs_height;
    14. this.fps = fps;
    15. this.canvas.width = this.width;
    16. this.canvas.height = this.width;
    17. },
    18. start: function()
    19. {
    20. this.loop();
    21. },
    22. addPlayer: function(image_src, width, height){
    23. this.player = new player();
    24. this.player.width = width;
    25. this.player.height = height;
    26. this.player.image = new Image();
    27. this.player.image.src = image_src;
    28. this.player.setPosition((this.canvas.width/2)-(this.player.width/2), this.canvas.height-this.player.height);
    29. this.player.draw();
    30. },
    31. addBackground: function(image_src){
    32. this.bg_image = new Image();
    33. this.bg_image.src = image_src;
    34. },
    35. clearCanvas: function(){
    36. this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
    37. },
    38. loop: function(){
    39. this.clearCanvas();
    40. this.player.draw();
    41. setTimeout('this.loop()', 1000/this.fps);
    42. }
    43. };
    44. var player = {
    45. width: null,
    46. height: null,
    47. image: null,
    48. pos_x: 0,
    49. pos_y: 0,
    50. falling: false,
    51. jumping: false,
    52. setPosition: function(x, y){
    53. this.pos_x;
    54. this.pos_y;
    55. },
    56. draw: function(){
    57. game.context.drawImage(this.image, 0, 0, this.width, this.height, this.pos_x, this.pos_y, this.width, this.height);
    58. }
    59. };
    60. var platform = {
    61. width: null,
    62. height: null,
    63. image: null
    64. };
    Alles anzeigen


    Vielen Dank schonmal :D