Giter Club home page Giter Club logo

Comments (6)

BinBashBanana avatar BinBashBanana commented on May 31, 2024

I think I understand, the pointer position is incorrect? This is caused by my code for proper scaling, but you haven't implemented it on your UI.

You need to resize the canvas so that the CSS width/height are the real width/height on the page, but the width/height HTML attributes are the width/height used by the WASM application.

var elementWidth = 960;
var elementHeight = 720;

canvas.style.setProperty("width", elementWidth + "px", "important");
canvas.style.setProperty("height", elementHeight + "px", "important");
canvas.width = elementWidth * window.devicePixelRatio;
canvas.height = elementHeight * window.devicePixelRatio;

This code will also make the image a lot clearer.

from webretro.

nenge123 avatar nenge123 commented on May 31, 2024

nono,i need a bigest "canvas".

The larger the canvas, the clearer the image.

can you open the retroarch.nenge.net
using f12 console,moble mode.

click "open" the "psx"

clixk "test" to start

from webretro.

BinBashBanana avatar BinBashBanana commented on May 31, 2024

Larger canvas doesn't mean clearer image. The code I sent adjusted the internal dimensions of the canvas so that the canvas would stay the same size but the image would become clear.

Here is a more updated method that should work for you:

function adjustCanvasSize(width, height) {
	canvas.style.setProperty("width", width + "px", "important");
	canvas.style.setProperty("height", height + "px", "important");
	
	var dpr = window.devicePixelRatio || 1;
	if (Module && Module.setCanvasSize) {
		Module.setCanvasSize(width * dpr, height * dpr);
	} else {
		canvas.width = width * dpr;
		canvas.height = height * dpr;
	}
}

adjustCanvasSize(960, 720);

// optionally attach this to a window resize event listener

from webretro.

nenge123 avatar nenge123 commented on May 31, 2024

adjustCanvasSize is like my code.nothing change.

if using style transform scale is not need hack js.
but this one will add top:-xxx;left:-xxx;

from webretro.

BinBashBanana avatar BinBashBanana commented on May 31, 2024

You shouldn't use style transform scale, using different CSS dimensions and HTML attribute dimensions is not a hacky thing to do.

from webretro.

BinBashBanana avatar BinBashBanana commented on May 31, 2024

Can I close this issue now?

from webretro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.