Draw player positions into canvas

25 views Asked by At

So here i try to do a collision detection from image rendering with canvas, so once we loaded maps and others properties on stage, we also use drawImage the collision source into another canvas running in the back with a little square which is show player positions.

Every properties on stage has anchor set to (0.5, 1) and map area positions is set to (0, 1400). Guess i must use these for a litle calc.

The thing is if i just draw player positions without no calc this isn't showing the good results on the collision canvas.

        this.preview_canvas // equal our canvas element;
        const collision = PIXI.utils.TextureCache[this.collision.id]
        const source = collision.baseTexture.resource.source;
        const canvas = this.preview_collision;
        const context = canvas.getContext("2d");
        context.clearRect(0, 0, canvas.width, canvas.height);
        context.drawImage(source, 0, 0, 250, 250);
        
        context.beginPath();
        context.arc(playerX, playerY, 2, 0, 1 * Math.PI, false);
        context.fillStyle = 'yellow';
        context.fill();
0

There are 0 answers