❔ WPF game in C# having trouble attaching the "fireball" (image) to the player(ImagePlayer)
5 Replies
basically what right now happens, is when the user presses the 'f' key, a fireball is launched (as intended) but from the wrong location!
my intention is "attaching" the fireball to the player, so when the user presses the 'f' key, the fireball will shoot from the player location , any suggestions are welcome!
I dont know the answer, but just play around with the Canvas.SetLeft and SetTop methods.
Put in 0, see where that makes the ball show up.
Put in 100, see where that makes the ball show up... etc
Debug, or print out the value thats in player.ImagePlayer.RenderTransformOrigin.X and you'll figure it out
I don't think the transform works as an exact coordinate set: https://learn.microsoft.com/en-us/dotnet/api/system.windows.uielement.rendertransformorigin?view=windowsdesktop-7.0#remarks
UIElement.RenderTransformOrigin Property (System.Windows)
Gets or sets the center point of any possible render transform declared by RenderTransform, relative to the bounds of the element. This is a dependency property.
Canvas is a UIElement, so if you want to get the current position of the image I think you want to do
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.