C
C#2y ago
noam.rees

❔ WPF game in C# having trouble attaching the "fireball" (image) to the player(ImagePlayer)

5 Replies
noam.rees
noam.reesOP2y ago
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!
Maskoe
Maskoe2y ago
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
lycian
lycian2y ago
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.
lycian
lycian2y ago
Canvas is a UIElement, so if you want to get the current position of the image I think you want to do
var playerPosition = player.ImagePlayer.TranslatePoint(new Point(0, 0), Canvas);
Canvas.SetLeft(ImageFireball, playerPosition.X);
Canvas.SetLeft(ImageFireball, playerPosition.Y);
var playerPosition = player.ImagePlayer.TranslatePoint(new Point(0, 0), Canvas);
Canvas.SetLeft(ImageFireball, playerPosition.X);
Canvas.SetLeft(ImageFireball, playerPosition.Y);
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server