当使用带有crafty.js的透明背景的精灵时,它会出现一个我似乎无法摆脱的白色背景,我自己做了一个精灵,并且是javascript,Crafty和Stackoverflow的新手,继承人我的代码
Crafty.scene('World', function() {
//Draw borders, gotta find a more code efficent way
for (var i = 0; i < 64; i++)
{
Crafty.e('Border').at(i, 0);
}
for (var y = 0; y < 48; y++)
{
Crafty.e('Border').at(0, y);
}
for (var y = 0; y < 48; y++)
{
Crafty.e('Border').at(63, y);
}
for (var y = 0; y < 64; y++)
{
Crafty.e('Border').at(y, 47);
}
//draw ingame entities such as the player and obstacles
for (var y = 20; y <40; y++)
{
Crafty.e('Wall').at(y, 10);
}
Crafty.e('Wall').at(15, 10);
Crafty.e('Player').at(20,20);
});
Crafty.scene('Loading', function() {
//Load in Visual Assests
Crafty.load(['assets/male_white_Student_bitmap.gif'], function(){
//Define individual images from bitmap
Crafty.sprite(25, 37, 'assets/male_white_Student_bitmap.gif' , {
spr_Front: [0,0],
spr_Back: [1,0],
spr_Right: [0,1],
spr_Left: [1,1]
});
Crafty.scene('World')
})
});
Game = {
map_grid:{
width: 64,
height: 48,
tile:{
width: 10,
height: 10
}
},
width: function(){
return this.map_grid.width * this.map_grid.tile.width;
},
height: function(){
return this.map_grid.height * this.map_grid.tile.height;
},
//start everything
start: function(){
//define game space and background colour
Crafty.init(Game.width(), Game.height());
Crafty.background('rgb(0, 100, 200)');
//draw borders (must be more efficient way of doing this)
Crafty.scene('Loading');
}
}
Crafty.c('Grid', {
init: function() {
this.attr({
w: Game.map_grid.tile.width,
h: Game.map_grid.tile.height
})
},
at: function(x, y) {
if (x === undefined && y === undefined) {
return { x: this.x/Game.map_grid.tile.width, y: this.y/Game.map_grid.tile.height }
} else {
this.attr({ x: x * Game.map_grid.tile.width, y: y * Game.map_grid.tile.height });
return this;
}
}
});
Crafty.c('Actor', {
init: function() {
this.requires('2D, Canvas, Grid');
},
});
//solid entities within the gameworld
Crafty.c('Wall', {
init: function() {
this.requires('Actor, Color, Solid')
.color('rgb(112, 138, 144)');
},
});
Crafty.c('Border', {
init: function() {
this.requires('Actor, Color, Solid')
.color('rgb(0, 0, 0)');
},
});
//player character and collision code, using fourway for ease of use movement
Crafty.c('Player', {
init: function(){
this.requires('Actor, Color, Fourway, Collision, spr_Front')
.color('rgb(0, 0, 0)')
.fourway(4)
.stopOnSolids()
.onHit('Enemy', this.attackEnemy);
},
stopOnSolids: function() {
this.onHit('Solid', this.stopMovement);
return this;
},
stopMovement: function() {
if (this._movement) {
this.x -= this._movement.x;
if (this.hit('Solid') != false) {
this.x += this._movement.x;
this.y -= this._movement.y;
if (this.hit('Solid') != false) {
this.x -= this._movement.x;
}
}
} else {
this._speed = 0;
}
}
});
答案 0 :(得分:2)
您已为实体分配“颜色”组件。将其设置为“无”。
.color('none')