本文整理匯總了C#中Microsoft.Xna.Framework.Graphics.Sprite.evento_ColisionHorizontalTile方法的典型用法代碼示例。如果您正苦於以下問題:C# Sprite.evento_ColisionHorizontalTile方法的具體用法?C# Sprite.evento_ColisionHorizontalTile怎麽用?C# Sprite.evento_ColisionHorizontalTile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Microsoft.Xna.Framework.Graphics.Sprite
的用法示例。
在下文中一共展示了Sprite.evento_ColisionHorizontalTile方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: actualizarColisiones
/*
* Actualiza los sprites con las
* colisiones de los Tiles y
* otros Sprites.
*/
private void actualizarColisiones(Sprite objSprite, long elapsedTime)
{
if (objSprite.solidoTiles) {
// Corregir x
float dx = objSprite.velocidadX;
float oldX = objSprite.x;
float newX = oldX + dx * elapsedTime;
Point? tile = getColisionTile(objSprite, newX, objSprite.y);
if (tile != null) {
// line up with the tile boundary
if (dx > 0) {
objSprite.x =
TileMap.tilesAPixels(tile.Value.X)
- objSprite.animacion.obtenerImagen().Width
- (objSprite.x - objSprite.x);
} else if (dx < 0) {
objSprite.x = TileMap.tilesAPixels(tile.Value.X + 1);
}
objSprite.evento_ColisionHorizontalTile();
}
// Corregir y
float dy = objSprite.velocidadY;
float oldY = objSprite.y;
float newY = oldY + dy * elapsedTime;
tile = getColisionTile(objSprite, objSprite.x, newY);
if (tile != null) {
// line up with the tile boundary
if (dy > 0) {
objSprite.y = TileMap.tilesAPixels(tile.Value.Y)
- objSprite.animacion.obtenerImagen().Height;
} else if (dy < 0) {
objSprite.y = TileMap.tilesAPixels(tile.Value.Y + 1);
}
objSprite.evento_ColisionVerticalTile();
}
}
//if (objSprite.solidoSprites || objSprite is BoxCollisionSprite) {
if (objSprite.solidoSprites)
{
//Colision Horizontal Sprites
float dx = objSprite.velocidadX;
float oldX = objSprite.x;
float newX = oldX + dx * elapsedTime;
Sprite sprite = getColisionSprite(objSprite, newX, objSprite.y);
if (sprite != null && sprite.solidoSprites) {
sprite.evento_ColisionHorizontalSprite(objSprite);
}
//Colision Vertical Sprites
float dy = objSprite.velocidadY;
float oldY = objSprite.y;
float newY = oldY + dy * elapsedTime;
sprite = getColisionSprite(objSprite, objSprite.x, newY);
if (sprite != null && sprite.solidoSprites)
{
sprite.evento_ColisionVerticalSprite(objSprite);
}
}
}