Troubles with craftyjs png sprite and custom drawed figure?

371 views Asked by At

i have following code with newest craftyjs:

<!DOCTYPE html>
<html>
<head>
    <style>
        body {
            margin:0;
        }
    </style>

    <script type="text/javascript" src="crafty.js"></script>
    <script>

        Crafty.c("Planet", {
            Planet: function(radius, map) {
                this.radius = radius;
                this.map = map;
                return this;
            },

            draw: function() {
                var ctx = Crafty.canvas.context;

                var x = 100;
                var y = 100;

                var offsetX = 0;

                var map = this.map;

                ctx.save();

                ctx.beginPath();
                ctx.arc(x, y, this.radius, 0, Math.PI * 2, false);
                ctx.closePath();
                ctx.clip();

                var scale = (this.radius * 2) / map.height;
                ctx.drawImage(map, 0, 0, map.width, map.height, x - this.radius - offsetX * scale, y - this.radius, map.width * scale, map.height * scale);

                ctx.beginPath();
                ctx.arc(x, y, this.radius * 1.04, Math.PI * 0.70, Math.PI * 1.30, false);
                ctx.shadowColor = "black";
                ctx.shadowBlur = 5;
                ctx.shadowOffsetX = 5;
                ctx.stroke();
                ctx.beginPath();
                ctx.arc(x, y, this.radius * 1.04, -Math.PI * 0.30, Math.PI * 0.30, false);
                ctx.shadowColor = "black";
                ctx.shadowBlur = 5;
                ctx.shadowOffsetX = -5;
                ctx.stroke();

                ctx.restore();
                console.log('drawing');
            }
        });


        Game = {

          // Initialize and start our game
          start: function() {
            // Start crafty and set a background color so that we can see it's working
            Crafty.init(500,500);

            Crafty.scene('Game', function() {
                Crafty.load(["1.jpg", "ship.png"],
                    function() {
                        Crafty.sprite("ship.png", {player_spr:[0,0, 48,48]});

                        Crafty.background("url('space.jpg')");
                              Crafty.e("2D, Canvas, Planet")
                              .Planet(40, Crafty.asset('1.jpg'));

                              var b2d = Crafty.e("2D, Canvas, player_spr, Actor, Fourway")
                              .multiway({W: -90, S: 90, D: 0, A: 180})
                              .attr({z: 4});

                            Crafty.viewport.clampToEntities = false;

                            Crafty.viewport.follow(b2d,0,0);

                });
            });

            Crafty.scene('Game');

          }
        }

        window.onload = Game.start;
    </script>
</head>

<body>

</body>

</html>

Textures is:

File: 1.jpg

1.jpg

File: ship.png

ship.png

The result canvas rendered image:

result

This is a strange bug! What i can to do with it? Crafty sprite conflict with custom drawings... (it shows sprite transparency)

1

There are 1 answers

2
xercool On

CraftyJS Github version fix this issue!

Just compile that with grunt.

Thank you for your answers!