2013-06-03 74 views
0

好吧所以我设法绘制出一个图像是玩家,但现在我试图画出一个敌人,它不会工作。我添加了警报,它显示该程序正在执行绘制敌方功能,但它仍然不会绘制?帆布没有从spritesheet绘制图像

这里是东西运行:http://www.taffatech.com/DarkOrbit.html 整个代码:http://www.taffatech.com/Source.js

如果有人能帮助我,我将非常感激!

这里是我的数据功能:

function Player() //Object 
{ 

//////Your ships values 
this.PlayerHullMax = 1000; 
this.PlayerHull = 1000; 
this.PlayerShieldMax = 1000; 
this.PlayerShield = 347; 
this.SpaceCrystal = 2684; 
this.Speed = 10; //should be around 2 pixels every-time draw is called by interval, directly linked to the fps global variable 
//////////// 

///////////flags 
this.isUpKey = false; 
this.isDownKey = false; 
this.isLeftKey = false; 
this.isRightKey = false; 
///////////// 

//////////extra 


///////////// 

////Pick Ship 
this.type = "Cruiser"; 
this.srcX = PlayerSrcXPicker(this.type); 
this.srcY = PlayerSrcYPicker(this.type); 
this.drawX = PlayerdrawXPicker(this.type); 
this.drawY = PlayerdrawYPicker(this.type); 
this.playerWidth = PlayerWidthPicker(this.type); 
this.playerHeight = PlayerHeightPicker(this.type); 
//// 


} 

Player.prototype.draw = function() 
{ 
ClearPlayerCanvas(); 
ctxPlayer.globalAlpha=1; 
this.checkDirection(); //must before draw pic to canvas because you have new coords now  from the click 
ctxPlayer.drawImage(spriteImage,this.srcX,this.srcY,this.playerWidth,this.playerHeight,this.drawX,this.drawY,this.playerWidth,this.playerHeight); 

}; 

Player.prototype.checkDirection = function() //these functions are in the PLayer class 
{ 





if(this.isUpKey == true)//if true 
{ 
    if(Player1.drawY >= (0 + this.Speed)) 
    { 
this.drawY -= this.Speed; 

    } 
} 

if(this.isRightKey == true) 
{ 

if(Player1.drawX <= (canvasWidthPlayer - this.playerWidth)) 
    { 
    this.drawX += this.Speed; 
    } 
} 

if(this.isDownKey == true) 
{ 
    if(Player1.drawY <= (canvasHeightPlayer - this.playerHeight)) 
    { 
    this.drawY += this.Speed; 
    } 
} 

if(this.isLeftKey == true) 
{ 
if(Player1.drawX >= (0 + this.Speed)) 
{ 
    this.drawX -= this.Speed; 
    } 
} 
}; 


///////////////////END PLAYER DATA//////////////////////////////////////////////// 
function Enemy() //Object 
{ 

//////Your ships values 
this.EnemyHullMax = 1000; 
this.EnemyHull = 1000; 
this.EnemyShieldMax = 1000; 
this.EnemyShield = 347; 
this.SpaceCrystalReward = 2684; 
this.EnemySpeed = 10; //should be around 2 pixels every-time draw is called by  interval, directly linked to the fps global variable 
//////////// 



////Pick Ship 
this.type = "Hover"; 
this.srcX = EnemySrcXPicker(this.type); 
this.srcY = EnemySrcYPicker(this.type); 
this.drawX = EnemydrawXPicker(this.type); 
this.drawY = EnemydrawYPicker(this.type); 
this.enemyWidth = EnemyWidthPicker(this.type); 
this.enemyHeight = EnemyHeightPicker(this.type); 
//// 


} 

Enemy.prototype.draw = function() 
{ 
ClearEnemyCanvas(); 
ctxEnemy.globalAlpha=1; 
    ctxEnemy.drawImage(spriteImage,this.srcX,this.srcY,this.playerWidth,this.playerHeight,this. drawX,this.drawY,this.playerWidth,this.playerHeight); 

} 
//////////START ENEMY DATA////////////////// 

function PlayerSrcXPicker(type) //these functions can be used by player and enemy 
{ 
if (type == "Cruiser") 

{ 
    return 0; 
} 


} 

function PlayerSrcYPicker(type) 
{ 
if (type == "Cruiser") 

{ 
    return 1385; 
} 
} 

function PlayerdrawXPicker(type) 
{ 
if (type == "Cruiser") 

{ 
    return 100; 
} 
} 

function PlayerdrawYPicker(type) 
{ 
if (type== "Cruiser") 

{ 
    return 400; 
} 
} 


function PlayerWidthPicker(type) 
    { 
    if (type == "Cruiser") 

    { 
    return 148; 
} 
    } 

    function PlayerHeightPicker(type) 
    { 
    if (type == "Cruiser") 

    { 
    return 85; 
} 
    } 

function EnemySrcXPicker(type) 
    { 
if (type == "Hover") 

{ 

    return 906; 
    } 
} 

function EnemySrcYPicker(type) 
{ 
if (type == "Hover") 

    { 
    return 601; 
} 
} 

function EnemydrawXPicker(type) 
{ 
if (type == "Hover") 

{ 
    return 800; 
} 
} 

function EnemydrawYPicker(type) 
{ 
if (type== "Hover") 

{ 
    return 300; 
} 
} 


function EnemyWidthPicker(type) 
{ 
if (type == "Hover") 

{ 
    return 90; 
} 
} 

function EnemyHeightPicker(type) 
{ 
if (type == "Hover") 

{ 

    return 75; 
} 
} 

我的init()是:

function init() 
{ 


drawBackground(); 

Player1 = new Player(); 
Enemy1 = new Enemy(); 

drawBars(); 
setUpListeners(); 
StartDrawingShips(); 


} 

我区间:

function UpdateShips() 
{ 

Player1.draw(); 
Enemy1.draw(); 

} 

function StartDrawingShips() 
{ 


    StopDrawing(); 

    drawInterval = setInterval(UpdateShips,fps); // redraw player every fps 



} 




function StopDrawing() 
{ 

    clearInterval(drawInterval); 
} 

如果您需要任何其他信息,然后就问!

+1

它不是fps,而是毫秒 - 帧间 - 反向值。 – Bergi

+0

但是它对绘制玩家起作用,我只是不明白为什么它不会画出敌人,它对于两者来说基本上是一样的东西? – Barney

回答

0
ctxEnemy.drawImage(spriteImage,this.srcX,this.srcY,this.playerWidth,this.playerHeight,this. drawX,this.drawY,this.playerWidth,this.playerHeight); 

Enemy对象没有playerWidthplayerHeight性能。你真的可能想用相同的构造函数为它们建模以避免这种混淆。

+0

谢谢,我在写这行时忘了改名字!必须停止复制和粘贴!谢谢! – Barney