html canvas – Help me Make Sense of Unity 2D Resolution Management

I am trying to set up an environment for a retro style pixel art game in Unity 2D. I aim for a vertical resolution of 240 pixels, and then, I would like the horizontal resolution to be dependent on the target screen’s aspect ratio, so, on a 4:3 screen 320×240, on 16:9 around ˜432×240, and so on.

I have read a bunch of tutorials, added pixel perfect to my main camera, set up a target resolution in player preferences, set the pixel in a unit to 8 pixels everywhere, but still cannot make heads or tails of how it actually works.

Here is an image of my scene with my camera selected:

enter image description here

If I am correct, the dashed line of the camera is my target resolution, although it is weird as the green image I used as a background has a native resolution of 216 pixel vertical, yet it fills up the supposedly 240 pixel high camera. I have no idea what the solid green line is, and don’t even get me started of the canvas, whose render target is set for camera yet it is obviously many times bigger than that.

Can someone please explain it to me how to properly set up a 2D environment described in my opening, point out my mistakes, point me to a good tutorial, or just give me advice on how to understand Unity’s resolution management?

javascript – How to add zombie arms to enemy’s in HTML canvas

I’m making a game with html canvas ( not WEBGL ). I have zombies that go to the center of the screen, but for now they are just circles. I want to give them two arms, like the arms players have in I have looked at this question: Moving an object in a circular path. I don’t, know what trigonometry to use to calculate the angle. Here is my code:

<canvas id='canvas'>
<script src="">
var canvas = document.querySelector('#canvas');
var context = canvas.getContext('2d');
function Enemy(x,y){
this.x = x;
this.y = y;
this.r = 5;
this.color = `hsl(${Math.floor(Math.random() * 360)},50%,50%)`;
this.vx = 0;
this.vy = 0;
this.draw = () => {
this.x += this.vx;
this.y += this.vy;
context.fillStyle = this.color;
var enemy = new Enemy(0,0);
function loop(){
    context.fillStyle = 'rgba(0,0,0,0.2)';
    var angle = Math.atan2(canvas.height/2 - enemy.y,canvas.width/2 - enemy.x);
    enemy.vx = Math.cos(angle);
    enemy.vy = Math.sin(angle);

I want the arms facing the center, and I want them to move when the enemy changes direction. Thanks in advance

Note Canvas | Forum Promotion

Hello user! Welcome to Note Canvas!

Note Canvas is a notes app (web-based) that I have been working on for years! You can store notes from business notes, school notes, among other things. Available in all browsers, web and mobile.

The main reason that I even wanted to start the application in the first place was because I found a common pattern amongst most of the traditional note-taking apps. One of the main reasons were curiosity, but the other is that I found that the more features a notes app had, the steeper the learning curve is for said app. This is not a slight towards any well-featured app in particular, but rather just an observation on the user experience of the apps and who they are targeting to. My approach is that I want a notes app that both has a lot of functionality AND has practically no learning curve, because it is based on familiar user interfaces that computer users have been using in the past.

All that being said, however, our current target market aren’t users of those apps, or people who use apps like that, but rather a demographic who may not use it at all–students.

Here is the link to to be able to try it for free.

It’s available across all browsers, desktop or mobile.

We also have a blog related to productivity, if that’s something you’re into.


unity – Scene Tab doesn’t show anything beside canvas while Game Tab shows everything

i’ve been building my script normally, but suddently after the last build, i don’t see any GameObject Rendered in Scene Tab beside a canvas i have in another scene. I can see everything rendered in my Game Tab scene through camera.

If i move some object in Scene Tab, it moves in Game Tab too but no display of it at all. and i see the following warnings:

Internal: JobTempAlloc has allocations that are more than 4 frames old - this is not allowed and likely a leak

Internal: deleting an allocation that is older than its permitted lifetime of 4 frames (age = 6)

Internal: JobTempAlloc has allocations that are more than 4 frames old - this is not allowed and likely a leak

Internal: deleting an allocation that is older than its permitted lifetime of 4 frames (age = 12)

enter image description here

  • I tried to reverse back the last build but no success
  • I close and reopen the Scene Tab
  • I Restarted my Computer too.
  • I Observed that after the restart the project did load far slower ( like if it was the first time i open the project in the pc)
    Nothing of this did work

unity3d – How can I can all Canvas object un-pickable within the Scene View?

I have a number of game objects in my scene that all have a Canvas as a child. When I try to click on any object in the Scene View, Unity picks one of my Canvases to select. If I click again, Unity cycles to another Canvas, and so on. I want to make all Canvas objects to be unpickable in the Scene View as described here, so that clicking on a game object selects that object.

I know I can do this by clicking on the hand icon by the canvas’s game object, but these Canvases are all part of prefab instances, and clicking the hand icon within a prefab doesn’t seem to work (Unity doesn’t save the fact that I toggled the pickability within the prefab, and changing the prefab has no effect on the instances within my scene).

Circular draggable UI element in Unity canvas

I am trying to implement my own runtime color picker that’s easy to use for touch interfaces. I want the hue slider to be a ring, along these lines, except the whole ring texture would rotate when dragged.

I have scavenged enough code to get a raw image object rotating when dragged in a UI canvas in the manner I’m looking for:

    private float baseAngle;
    private Vector2 pos;
    public void OnBeginDrag(PointerEventData eventData)
        pos = transform.position;
        pos = eventData.pressPosition - pos;
        baseAngle = Mathf.Atan2(pos.y, pos.x) * Mathf.Rad2Deg;
        baseAngle -= Mathf.Atan2(transform.right.y, transform.right.x) * Mathf.Rad2Deg;

    public void OnDrag(PointerEventData eventData)
        pos = transform.position;
        pos = eventData.position - pos;
        float ang = Mathf.Atan2(pos.y, pos.x) * Mathf.Rad2Deg - baseAngle;
        transform.rotation = Quaternion.AngleAxis(ang, Vector3.forward);

Since it doesn’t use colliders, how can I limit the draggable region to a circle within the square bounds of the texture? Even better, also limit it to a ring rather than a whole circle. Will I have to implement my own check based on some pure math or is there a built in way?


canvas – Javascript speed of an animated object (planet orbiting sun)

So I am pretty new to JavaScript and I thought I might make an animation demonstrating a planet orbiting a sun in an elliptical orbit using Kepler’s laws.

I am struggling to get the speed right. So I want the speed of the planet to be slower further away from the sun, and faster closer to the sun.

Within this method I use Keplers laws to calculate the x and y coordinate. I have also calculated the (real) velocity at each point in its trajectory (this may need to be scaled appropriately as I hope to use real astronomical data).

  this.position = function(theta) {
    var R = Math.pow(((Math.pow(T,2))/((4*Math.pow(Math.PI, 2))/(G*M))),(1/3)) ;
    var a = R/(1-e) ;
    var radius = a*(1-Math.pow(e,2))/(1+e*Math.cos(theta)) ;
    this.x = radius*Math.cos(theta)*10e-10 + canvas.width/2 ;
    this.y = radius*Math.sin(theta)*10e-10 + canvas.height/2;
    this.vel = Math.sqrt(G*M*((2/radius)-(1/a))) ;

I’ve got full code on CodePen here:

Any help or comments will be appreciated. Thanks!

Get an image from canvas on android?

At the moment I have not worked with android and am not familiar with its capabilities.

In the browser, it is possible to get an image from the canvas using the methods


Are there any similar methods on android canvas (, if I understood correctly) to get an image?

Or is it possible only in canvas in the webview component?


javascript – Crear lienzos dinámicos fabric Canvas

Hola buenas queria saber si es posible crear lienzos dinámicos en canvas, ya que en una misma vista puedo tener varios productos que cargo a través de bd, lo que hago es que itero los modelos que tengo en botones y según pulso un botón cargo la información de ese producto con AJAX, pero al ser todos la misma id pues no reconoce ninguno.

Aquí imprimo los resultados

<div style="width: 500px; height: 500px; left: 50%; transform: translate(-50%, -50%);top: 50%; position: relative; bottom: 0%; display: contents;" id="posicionProducto">                   
     /* Resultados  */               

Primero itero las zonas que tiene un producto

@foreach ($zonas as $item)
   <a href="javascript:void(0);" id="{{ $item->id }}" class="btn btnVer cambiar_zona">{{ $item->name_zona }}</a>

Luego según el botón que pulso consulto con AJAX a la base de datos:

      $(document).on('click', '.cambiar_zona', function()
        var id = $(this).attr("id");
        var informacion = 'id=' + id;
        let url = '/admin/catalogo/extraer-producto/' + id;
                headers: { 'X-CSRF-TOKEN': $('meta(name="csrf-token")').attr('content') },
                type: "get",
                url: url,
                data: informacion,
                success: function(data){
                    $('#posicionProducto').append('<div style="position: relative">
                                                        <img src=""+ data.zonas.foto +"" alt="" id="img_producto" style="width: 100%;">
                                                        <div style="position: absolute; top: '+ data.zonas.position_top +'%; left: '+ data.zonas.position_left +'%; width: '+ data.zonas.width +'%; height: '+ data.zonas.height +'%;">
                                                            <canvas id="c_'+ +"" style="border-color: '+ data.zonas.borde +';"></canvas>

Luego se crea el lienzo

var canvas = new fabric.Canvas(document.getElementById('c'));

Pero claro está asociado a la id c y ser repite por tantas iteraciones haya. Esto puede ser de alguna manera dinámico? Saludos