canvas

How does the optimization of Canvas drawImage work?

我们两清 提交于 2019-12-24 13:25:28
问题 Problem I tried to create a particle system using a Canvas. Interestingly the method drawImage is very fast. I got to 90.000 particles at 60 fps, even using drawImage. However, that was only with the same image. When I used different images for the particles the performance dropped down considerably. Then I changed the order of the images, so that e. g. first all particles of image1 are drawn, then all of image2, etc and the performance was good again. Question Does anyone know why that is?

HTML Canvas Hover Text

蹲街弑〆低调 提交于 2019-12-24 13:16:07
问题 I have an HTML canvas with all different shapes of all different sizes and it is built by parsing information from an external file. I am wondering how I can make it so that hovering the mouse over each shape will display its unique name. I have found resources on how to display text on a mouse hover for the whole canvas, but I need each individual shape to display a unique text. Thanks! 回答1: You can use context.isPointInPath to test if your mouse is hovering over one of your shapes. Create a

TextCentering inside Canvas PlayN

為{幸葍}努か 提交于 2019-12-24 13:13:02
问题 I have one little problem: I am trying go center a given text inside a Canvas with PlayN. I do not have any FontMetrics, because GWT does not offer one, and simple repositioning depending of character number and fontsize just does not works :(.. Can somebody please help 回答1: Use Graphics.layoutText to create a TextLayout . TextLayout provides the width and height of the text, which you can use to position it however you like and render it into a Canvas using Canvas.drawText(TextLayout,x,y) .

canvas animation with .clearRect(x,y,w,h)

无人久伴 提交于 2019-12-24 13:12:50
问题 I'm a relative beginner in using javascript and canvas. I'll try explain what I've done so far. I have an external style sheet, and I've set the background of the canvas element (it's background image of a road that trails off into the horizon). I have then created this first function (drawRoad()) to draw a thin strip of white down the center of the road, and have it trail off into the horizon with the road. I have then created another function (roadLines()) which inserts spaces in this white

Why window.onload works and onload=“” does not work

北慕城南 提交于 2019-12-24 12:47:24
问题 So for some reason my canvas wasn't being applied when called through onload, I've tried other events and they work, I've tried changing where onload is placed (the footer, p and canvas tags) but that didn't work, and i tested the script functionality by placing it at the bottom outside of a function which does work Ive tried another website which I did that had onload and canvas' and they work so after looking up possible solutions I ended up having to add windows.onload in the script area

“The canvas has been tainted by cross-origin data” error on Android (no error on desktop)

*爱你&永不变心* 提交于 2019-12-24 12:45:54
问题 I'm trying to load an image from a video file, draw it on a canvas, and modify canvas pixels. I'm hosting this on a local web server, and it works fine on any desktop computer in my local network. However when I try to open the same page on Android Nexus 7 tablet (also on the local network) I get this error: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data. Here's my final test code: <!DOCTYPE html> <html> <body> <canvas id=

How to center a canvas on top of a background image

你说的曾经没有我的故事 提交于 2019-12-24 12:32:57
问题 I have an image that I want to use as a document background, and place on top of it a canvas element. The reason is that the background is large (2048x1024) and if I place it inside the canvas it will be redrawn on every frame wasting resources. <div id="container"> <image class = "img1" src = "./assets/game.jpg" id= "backk"/> <canvas id="canvas" width="1366" height="1024">No Canvas support!</canvas> </div> container { position: relative; width:100%; margin : auto; } canvas{ display:block;

Can I HitTest element with lower ZIndex in WPF Canvas?

自作多情 提交于 2019-12-24 12:05:30
问题 When I am using System.Windows.Media.VisualTreeHelper.HitTest on mouse clicking canvas, it always returns me the element on top. I mean if there are two elements overlapping each other, the one I get is the one with higher ZIndex in canvas. I also tried to do it this way, but even after I made IsHitTestVisible = False it still returned this same one to me. Is there any possibility to get the element "underneath"? Thanks in advance! 回答1: See the section "Hit Testing and Z-Order" here: Hit

Android - Accessing buttons from SurfaceView

女生的网名这么多〃 提交于 2019-12-24 12:04:10
问题 I am currently working on a simple 2d tower defense game to learn some of the basics of Android game development. To handle my graphics I have a custom object that extends SurfaceView and all of my drawing takes place on the SurfaceView's canvas object. This is all working fine. I'd like my game to have two stages. The "combat" stage and the "building stage". In the building stage, I'm trying to add a button that can be clicked to begin the next combat stage. From my research, it sounds like

How to fill color of more than one canvas image?

和自甴很熟 提交于 2019-12-24 11:41:34
问题 It's my first time to use html5 canvas and I have no idea yet how it works. My problem is, I have to modify the colors of the images in the canvas. It's easy if there's only one image. But, I will have more than one, in other words, overlapping images. To further understand my question, I created an illustration. There will be 2 image files only, Image 1 and Image 2: This is my current code (with fiddle here too): HTML: <canvas id="canvas1" width="600" height="600"></canvas> JS: var can =