Guest User

Untitled

a guest
Jun 24th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. function startGame() {
  2. createCanvas.start();
  3.  
  4. }
  5. const ninja = new Image();
  6. let ninjaImage = "images/player/stand01.png"
  7.  
  8.  
  9. const createCanvas = {
  10. canvas : document.createElement('canvas'),
  11. start() {
  12. this.canvas.width = 600;
  13. this.canvas.height= 400;
  14. this.context = this.canvas.getContext('2d');
  15. document.body.insertBefore(this.canvas, document.body.childNodes[0]);
  16. }
  17. }
  18. function sprite(options){
  19. let that = {};
  20. that.context = options.context;
  21. that.width = options.width;
  22. that.height = options.height;
  23. that.image = options.image;
  24. return that;
  25.  
  26. that.render = function () {
  27. that.context.drawImage(
  28. that.image, 0, 0, that.width, that.height, 0, 0, that.width, that.height);
  29. }
  30. player.render();
  31. }
  32. const player = sprite ({
  33. width: 100,
  34. height: 100,
  35. image: ninjaImage
  36. });
  37.  
  38. </script>
Add Comment
Please, Sign In to add comment