canvas

How do i Make a sprite change with keyboard input i'm using vanilla JS

时间秒杀一切 提交于 2021-01-04 07:15:26
问题 so ive been testing out HTML canvas. im trying to get a sprite to change on keyboard input. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <canvas id='Game' width='200' height='200' style='border: 2px solid #000000;'></canvas> <script> window.onload = function(){ var Game = document.getElementById('Game'); var context = Game.getContext('2d') var room = new Image(); var

How do i Make a sprite change with keyboard input i'm using vanilla JS

我怕爱的太早我们不能终老 提交于 2021-01-04 07:11:21
问题 so ive been testing out HTML canvas. im trying to get a sprite to change on keyboard input. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <canvas id='Game' width='200' height='200' style='border: 2px solid #000000;'></canvas> <script> window.onload = function(){ var Game = document.getElementById('Game'); var context = Game.getContext('2d') var room = new Image(); var

How do i Make a sprite change with keyboard input i'm using vanilla JS

会有一股神秘感。 提交于 2021-01-04 07:09:33
问题 so ive been testing out HTML canvas. im trying to get a sprite to change on keyboard input. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <canvas id='Game' width='200' height='200' style='border: 2px solid #000000;'></canvas> <script> window.onload = function(){ var Game = document.getElementById('Game'); var context = Game.getContext('2d') var room = new Image(); var

Does using percentages instead of pixels change an html 5 canvas change its properties?

血红的双手。 提交于 2021-01-03 06:28:09
问题 I am practicing javascript and I am trying to make a game. I want the canvas element to be fullscreen, so I used percentages for the height and width attribute, but when I do, it doesn't behave like it normally does. When I run my debug code, it is supposed to make a box that is 50px by 50px, but the graphics look bigger than normal. I've tried getting the canvas height and width in pixels, but that did not work. It does not report any error messages, but it is still too big. <!DOCTYPE html>

Images onload in one function

核能气质少年 提交于 2021-01-01 06:42:47
问题 I'm trying to learn JavaScript, making my first game. How I can make all images onload in one function and later draw it in the canvas making my code shorter? How can I put a lot of images in an array and later us it in a function. This is my third day of learning JavaScript. Thanks in advance. var cvs = document.getElementById('canvas'); var ctx = cvs.getContext('2d'); //load images var bird = new Image(); var bg = new Image(); var fg = new Image(); var pipeNorth = new Image(); var pipeSouth

drag element on canvas

旧巷老猫 提交于 2020-12-30 03:14:23
问题 I draw an element onto a canvas as a string. I then want to be able to click the element (or tap on a mobile device) and drag it around. What I have now is: <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="bootstrap.min.css" /> <link type="text/css" rel="stylesheet" href="stylesheet.css"/> <script src="jquery-1.11.0.js"></script> </head> <body> <canvas id="canvas1" width="662" height="983"> <script src="jquery-1.11.0.js"></script> </canvas> <script> var chosenChord=""; //this gets

drag element on canvas

99封情书 提交于 2020-12-30 03:14:03
问题 I draw an element onto a canvas as a string. I then want to be able to click the element (or tap on a mobile device) and drag it around. What I have now is: <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="bootstrap.min.css" /> <link type="text/css" rel="stylesheet" href="stylesheet.css"/> <script src="jquery-1.11.0.js"></script> </head> <body> <canvas id="canvas1" width="662" height="983"> <script src="jquery-1.11.0.js"></script> </canvas> <script> var chosenChord=""; //this gets

drag element on canvas

空扰寡人 提交于 2020-12-30 03:12:03
问题 I draw an element onto a canvas as a string. I then want to be able to click the element (or tap on a mobile device) and drag it around. What I have now is: <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="bootstrap.min.css" /> <link type="text/css" rel="stylesheet" href="stylesheet.css"/> <script src="jquery-1.11.0.js"></script> </head> <body> <canvas id="canvas1" width="662" height="983"> <script src="jquery-1.11.0.js"></script> </canvas> <script> var chosenChord=""; //this gets

Horrible Canvas GetImageData() / PutImageData() performance on mobile

十年热恋 提交于 2020-12-29 06:11:24
问题 I'm doing a little HTML5 game and, while loading my sprites at the beginning of the map, I do some processing with GetImageData() / looping over all the image / PutImageData(). This works fantastically great on my PC, however, on my cell phones it's horrendously slow. PC: 5-6 ms iPhone 4: 300-600 ms Android HTC Desire S: 2500-3000 ms I've been doing some VERY basic benchmarking, and both GetImageData and PutImageData run very fast, what's taking long is the looping through the contents. Now,

HTML5 Canvas with rounded corner

久未见 提交于 2020-12-29 04:21:42
问题 I'd like to have an HTML5 canvas with rounded corner. I'm using the CSS property border-radius: 15px to round my corners. But, when I draw something in the corner of my canvas, I can draw in the corner. At the beginning: What I have: What I want: Do you have any solution to avoid that? I thought about create a mask but I don't really know how to do.. For information, this works on Firefox but not on Chrome/Safari/Opera. This is a small example: http://jsfiddle.net/XYHpJ/ Thanks! 回答1: Just use