Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function startGame() {
- createCanvas.start();
- }
- const ninja = new Image();
- let ninjaImage = "images/player/stand01.png"
- const createCanvas = {
- canvas : document.createElement('canvas'),
- start() {
- this.canvas.width = 600;
- this.canvas.height= 400;
- this.context = this.canvas.getContext('2d');
- document.body.insertBefore(this.canvas, document.body.childNodes[0]);
- }
- }
- function sprite(options){
- let that = {};
- that.context = options.context;
- that.width = options.width;
- that.height = options.height;
- that.image = options.image;
- return that;
- that.render = function () {
- that.context.drawImage(
- that.image, 0, 0, that.width, that.height, 0, 0, that.width, that.height);
- }
- player.render();
- }
- const player = sprite ({
- width: 100,
- height: 100,
- image: ninjaImage
- });
- </script>
Add Comment
Please, Sign In to add comment