gpt4 book ai didi

javascript - 在 Crafty.js 中加载 Sprite 时的彩色背景

转载 作者:行者123 更新时间:2023-12-02 18:02:36 24 4
gpt4 key购买 nike

当在 crafty.js 中使用具有透明背景的 Sprite 时,它会出现一个我似乎无法摆脱的白色背景,我自己制作了 Sprite ,并且对 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;
}
}
});

最佳答案

您已将“颜色”组件分配给实体。将其设置为“无”。

.color('none')

关于javascript - 在 Crafty.js 中加载 Sprite 时的彩色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20399483/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com