Fix exception when putting duplicates in room, corrected scaling
This commit is contained in:
parent
342368a47f
commit
3204c2d029
Binary file not shown.
@ -1210,6 +1210,7 @@ namespace GameCreatorGroupProject
|
|||||||
|
|
||||||
// Dictionary to store texture ID's by name
|
// Dictionary to store texture ID's by name
|
||||||
Dictionary<string, int> textures = new Dictionary<string, int>();
|
Dictionary<string, int> textures = new Dictionary<string, int>();
|
||||||
|
Dictionary<string, Vector2> texSizes = new Dictionary<string, Vector2>();
|
||||||
|
|
||||||
// Function to load a texture for a given gameobject
|
// Function to load a texture for a given gameobject
|
||||||
private Sprite loadSprite(string obj, string sprPath)
|
private Sprite loadSprite(string obj, string sprPath)
|
||||||
@ -1223,6 +1224,7 @@ namespace GameCreatorGroupProject
|
|||||||
// Using the passed object's name as a key
|
// Using the passed object's name as a key
|
||||||
textures.Add(obj, loader.loadImage(sprPath, spr));
|
textures.Add(obj, loader.loadImage(sprPath, spr));
|
||||||
spr.TextureID = textures[obj];
|
spr.TextureID = textures[obj];
|
||||||
|
texSizes.Add(obj, new Vector2(spr.Width, spr.Height));
|
||||||
|
|
||||||
return spr;
|
return spr;
|
||||||
}
|
}
|
||||||
@ -1237,8 +1239,8 @@ namespace GameCreatorGroupProject
|
|||||||
GL.ClearColor(Color.Black);
|
GL.ClearColor(Color.Black);
|
||||||
|
|
||||||
// Set up a viewport
|
// Set up a viewport
|
||||||
int w = glRoomView.Width;
|
int w = glRoomView.Width * 2;
|
||||||
int h = glRoomView.Height;
|
int h = glRoomView.Height * 2;
|
||||||
|
|
||||||
CurrentView = new RectangleF(0, 0, w, h);
|
CurrentView = new RectangleF(0, 0, w, h);
|
||||||
|
|
||||||
@ -1283,6 +1285,14 @@ namespace GameCreatorGroupProject
|
|||||||
spr = loadSprite(objName, objectSprites[objName]);
|
spr = loadSprite(objName, objectSprites[objName]);
|
||||||
currentRoom.Objects[vec].sprite = spr;
|
currentRoom.Objects[vec].sprite = spr;
|
||||||
}
|
}
|
||||||
|
else if (currentRoom.Objects[vec].sprite == null)
|
||||||
|
{
|
||||||
|
// Resuse an old sprite
|
||||||
|
spr.TextureID = textures[objName];
|
||||||
|
spr.Width = (int) texSizes[objName].X;
|
||||||
|
spr.Height = (int)texSizes[objName].Y;
|
||||||
|
currentRoom.Objects[vec].sprite = spr;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if our dictionary has an entry for the current draw depth yet
|
// Check if our dictionary has an entry for the current draw depth yet
|
||||||
if (!objects.ContainsKey((int)vec.Z))
|
if (!objects.ContainsKey((int)vec.Z))
|
||||||
@ -1292,11 +1302,17 @@ namespace GameCreatorGroupProject
|
|||||||
|
|
||||||
// Add this object to the new list
|
// Add this object to the new list
|
||||||
objects[(int)vec.Z].Add(currentRoom.Objects[vec].sprite);
|
objects[(int)vec.Z].Add(currentRoom.Objects[vec].sprite);
|
||||||
|
currentRoom.Objects[vec].sprite.loaded = true; // prevent double-loading
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Add this object to the correct list
|
// Add this object to the correct list if not there already
|
||||||
objects[(int)vec.Z].Add(currentRoom.Objects[vec].sprite);
|
if (currentRoom.Objects[vec].sprite.loaded == false)
|
||||||
|
{
|
||||||
|
// Prevent double-loading
|
||||||
|
currentRoom.Objects[vec].sprite.loaded = true;
|
||||||
|
objects[(int)vec.Z].Add(currentRoom.Objects[vec].sprite);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1307,7 +1323,7 @@ namespace GameCreatorGroupProject
|
|||||||
if (!formLoaded)
|
if (!formLoaded)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GL.Viewport(0, 0, Width, Height);
|
GL.Viewport(0, 0, Width * 2, Height * 2);
|
||||||
|
|
||||||
// Clear previously drawn graphics
|
// Clear previously drawn graphics
|
||||||
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||||
|
@ -14,6 +14,9 @@ namespace GameCreatorGroupProject
|
|||||||
// drawing a 2D image (or sprite) on the screen during the game.
|
// drawing a 2D image (or sprite) on the screen during the game.
|
||||||
class Sprite
|
class Sprite
|
||||||
{
|
{
|
||||||
|
// Variable to track if the given sprite has already been loaded into the room
|
||||||
|
public bool loaded = false;
|
||||||
|
|
||||||
// Member variables
|
// Member variables
|
||||||
// Var for storing position (in pixels) on the screen
|
// Var for storing position (in pixels) on the screen
|
||||||
public Vector3 Position = Vector3.Zero;
|
public Vector3 Position = Vector3.Zero;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user