Javascript – Collision Detection Problem on Canvas Platformer

I'm having big problems with collision detection in my platformer. If you go straight to the right, the block floats. Even the corners let the block through and the walls are sticky. It's a bit chaotic. I know that my gravity is a big problem. If someone could help me, I would be so happy.

Here is the collision code:

  const calculatorTileSize = 1.0 / mapTileSize;
const nextX = guy.x + guy.velX;
const nextY = guy.y + guy.velY;

const currentMinX = (guy.x * calculatorTileSize) | 0;
const currentMaxX = ((guy.x + guy.width) * calculatorTileSize) | 0;
const currentMinY = (guy.y * calculatorTileSize) | 0;
const currentMaxY = ((guy.y + guy.height) * calculatorTileSize) | 0;

const nextMinX = (nextX * calculatorTileSize) | 0;
const nextMaxX = ((nextX + guy.width) * calculatorTileSize) | 0;
const nextMinY = (nextY * calculatorTileSize) | 0;
const nextMaxY = ((nextY + guy.height) * calculatorTileSize) | 0;

// Collision of the X-axis
if (guy.velX! == 0.0) {
for (if i = nextMinX; i <= nextMaxX; i ++) {
for (let j = currentMyY; j <= currentMaxY; j ++) {
if (map[j][i]) {
guy.velX = 0.0;

// collision of the Y-axis
if (guy.velY! == 0.0) {
for (if j = nextMinY; j <= nextMaxY; j ++) {
for (let i = currentMinX; i <= currentMaxX; i ++) {
if (map[j][i]) {
guy.velY = 0.0;
physics.gravity = 0;
} else {
Physics.Gravity = 0.4;

The full game is in this codeepen:

Unit – Relative vertical alignment of 3 texts on canvas

This looks like a simple application of anchor properties in the UI layout system:

Animation showing the configuration of three lines in the Unity editor

For all three lines, Min X and 0, and Max X should be 1 so that the anchors span the entire width of the container.

Then vary the Min & Max Y of each element. The bottom line ranges from 0 to 0.3333, the middle from .3333 to .6666 and the top from .6666 to one.

Set the Left Up Right Down parameters to zero so that the corners of the text area align exactly with the anchor points and you are done.

Since the anchors are specified as a fraction of the size of the parent, the layout of the text automatically adjusts as you resize the parent to maintain those relationships.

Animation that shows how to change the size and aspect ratio of the container

If you do not want to change these percentages each time you add or remove an item from your list, you can easily nest it in a parent with a vertical layout group that does the positioning and resizing for you:

Inspector configuration of the vertical layout group

ios – Would it make sense to use HTML Canvas as a render solution for an app on mobile devices?

This is my first post in this community. Let me know if I need to go into detail. I'm creating a mobile graphics application (think of After Effects for iOS) and wondered if it makes sense to use an HTML canvas for the render / preview part (the user interface still uses Cocoa). I have set up some professionals:

  • I already have experience with HTML5 Canvas
  • I would not have to create a whole rendering engine
  • Creating new effects is easier for me and other developers (less worried about creating libraries for effect developers).
  • I can render the final video with Capture stream

What would be possible disadvantages and, if not practicable, what would be the framework for this situation? Would I just have to build my own engine from scratch?

reactjs – Street View image does not center on canvas

Enter image description hereI'm trying to render a Google Maps Street View container in my project using Google Map React. But I'm having trouble centering the Street View image. It is driven to one side.

This is the code I use:

import React, {Component} off & # 39;
PropTypes from & prop; types & # 39; import
GoogleMapReact from & # 39; google-map-react & # 39; import

Export standard class GoogleMapContainer extends component {
static properties = {
Middle: PropTypes.object,
zoom: PropTypes.number
static defaultProps = {
Center: {
Lat: 59.95,
lng: 30.33
Zoom: 11

render () {
Return (
// Important! Always set the container height explicitly


Javascript – How do I rotate individual shapes on an HTML5 canvas?

So I am making a simple Asteroids clone as an introduction to HTML5 Canvas. I want to be able to rotate the main player while leaving the other objects alone on the screen. Right now I'm using transformation and rotation on the canvas so the player can move, which works well. However, since the entire screen is rotated, this affects other shapes on the screen. Instead, the general way to do this is to cause each shape to track its own positions and perform manual transformations on the shape itself while leaving the canvas alone? Can I possibly give my form a CSS class and control it in this way? Should I use more than one workspace to control the rotations individually? We are not sure how it is accepted to process multiple images / shapes on screen simultaneously with their own motion and rotation patterns. My gut tells me that each shape should follow its own positions and just do the math for the shape object itself … but then I would not use the Canvas APIs at all to make them rotate.

My app currently:

And a code snippet for the rotation:

// player test
Function drawShip () {
ctx.beginPath ();
ctx.moveTo (shipStartX, shipStartY);
ctx.lineTo (shipStartX + 8, shipStartY + 20);
ctx.lineTo (shipStartX, shipStartY + 15);
ctx.lineTo (shipStartX - 8, shipStartY + 20);
ctx.lineTo (shipStartX, shipStartY);
ctx.translate (shipStartX, shipCenterY);
ctx.rotate ((Math.PI / 180) * shipMoveDegree)
ctx.translate (-shipStartX, -shipCenterY);
ctx.stroke ();
ctx.closePath ();

Can the save () and restore () methods for CanvasRenderingContext2D come into play here? I tried to experiment with it, but I did not get anywhere. I've tried using save () and restore (), but the problem is that after restoring, the player will simply be reset to its original position, as I never actually change its position.

Polaroid – Expose a movie on a canvas

In short, I want to "map" a 5.5 "LCD screen to check its light distribution and see where the light is more intense and where weaker.

This is true for an LCD 3D printer with a UV LED light source at the bottom, projected onto an LCD screen whose pixels are turned on to let the light through and produce images for each layer of the model to be printed.

Because the projected light comes from a single point, it gets more to the sides of the screen, which are supposed to be about 30% weaker on the sides.

I would like to somehow use a photographic film set on the 5.5-inch screen, expose a full screen for about 0.1 seconds and be able to see on the film the transitions from stronger to weaker spots.

Would it be possible? Could I somehow use a Polaroid movie? Which would be the easiest way to do this?

Thank you in advance.