Jump to content

[Bug?] Pixi drawing lines to points Graphics().drawRect.


AquSe
 Share

Recommended Posts

Hello, I've made a little script that retrieves my mouse's position and draws it on the screen as a rectangle 1x1 pixel. It works fine, until there are thousands of coloured in pixels and Pixi JS at some point [bugs?] out and does something like:

 

215e36edc8.png

 

 

I also tried just drawing random rectangles on screen(screenshot is bugged), and it does the same thing(kind of, see that line in the middle?) Basically the script would run and then the line would appear out of nowhere, and then for the next minute or two the same line would come from that middle point to every single rectangle that is drawn:

 

2XPNvIv.png

 

So yeah, is there a better way to draw lines or something instead of colouring in pixel by pixel? I like the way it looks though, if only that didn't happen.

 

Here's the script:

<!DOCTYPE HTML><html><head>	<title>Mah Mouse</title>	<style>		body {			margin: 0;			padding: 0;			background-color: #000000;		}	</style>	<script src="pixi.js"></script></head><body>	<script>	var mouseX = 0	var mouseY = 0		// create an new instance of a pixi stage	var stage = new PIXI.Stage(0x000000);	// create a renderer instance	var renderer = new PIXI.WebGLRenderer(1600, 900);	// add the renderer view element to the DOM	document.body.appendChild(renderer.view);        var graphics = new PIXI.Graphics();        graphics.lineStyle(1, 0xFFFFFF);        stage.addChild(graphics);		requestAnimFrame(animate);	function animate() {	    requestAnimFrame(animate);	    renderer.render(stage);	}		indx = 0;		var makeRequest = function(){	   var ajaxRequest = new XMLHttpRequest(); //Doing this.ajaxRequest doesn't work because the callback function says that ajaxRequest is then undefined. Which makes sense.	   var ajaxFunction = function(){	      if(ajaxRequest.readyState == 4){			var pointsStr = ajaxRequest.responseText.split("C");			indx = parseInt(pointsStr[pointsStr.length - 1]);			console.log(indx);			for (i = 0; i < pointsStr.length - 1; i++) {				if(pointsStr[i] != ""){					var points = pointsStr[i].split(",");										mouseX = parseInt(points[0]);					mouseY = parseInt(points[1]);										graphics.drawRect(mouseX,mouseY,1,1);				}			}	      } 	   }		   ajaxRequest.onreadystatechange = ajaxFunction;           ajaxRequest.open("GET", "http://109.255.170.73/mouseCoord/" + indx, true);	   ajaxRequest.send();	}		var interval = setInterval(function(){	    makeRequest();	}, 5);	</script>	</body></html>
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...