Sup Guys,
hope this message reaches you in good health.
Some background: Junior dev, but complete novice game dev currently working on (kinda just started) a basic playing card game (for Android and iOS) as a personal project
The Problem: I’ve written some very basic image scaling logic that just enlarges a button while that button is being held and pressed (touched), there are 2 buttons in question but the scaling effect only seems to be applying to the first button pressed with nothing happening to the second. Any thoughts as to why would be greatly appreciated:
Game1 : Game Class
protected override void LoadContent()
{
GameContent.LoadAll(Content);
// Add main menu screen
GameStateManager.AddScreen(new MainMenuState(GraphicsDevice));
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void Draw(GameTime gameTime)
{
spriteBatch.Begin();
GameStateManager.Draw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
protected override void Update(GameTime gameTime)
{
GameStateManager.Update(gameTime);
base.Update(gameTime);
}
GameStateManager Class
public static void Update(GameTime gameTime)
{
if (_screens.Count > 0)
{
_screens.Peek().Update(gameTime);
foreach (var button in _screens.Peek().GetComponents())
{
button.Update();
}
}
}
Note: The Draw method is also called the same way
Relevant bits in the Main Menu class
private List<Component> Buttons { get; set; }
public MainMenuState(GraphicsDevice graphicsDevice)
: base(graphicsDevice)
{
Name = GameScreen.MainMenu;
Buttons = new List<Component>()
{
new Button("Join", GameContent.JoinGameButtonImage, DeviceScreenSize, -100),
new Button("Create", GameContent.CreateGameButtonImage, DeviceScreenSize, 250)
};
}
public override List<Component> GetComponents()
{
return Buttons;
}
Button Class
public override void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(_texture, new Vector2(_deviceScreenSize.Width / 2, _deviceScreenSize.Height / 2 + _yAxisPosition), null, Color.White, 0, new Vector2(ButtonOrigin, 0), Scale, SpriteEffects.None, 0);
}
public override void Update()
{
while (TouchPanel.IsGestureAvailable)
{
var touch = TouchPanel.ReadGesture();
if (Surface.Contains(touch.Position) && touch.GestureType == GestureType.Hold)
{
IsPressed = true;
Console.WriteLine(Name + " button is held");
}
}
if (TouchCollection.Count == 0)
{
IsPressed = false;
}
}