Creating a fluid container with a PhysicsObjectBehaviour - A glass full of water

Jul 15, 2010 at 1:51 AM


I'm very new to this and think its awesome. I'm having a play with it and was trying to create a glass filled with liquid which you

can tip over. I've tried a few combinations in xaml but so far no success. If anyone has done this and could give me a few pointers

that would be great.




Jul 15, 2010 at 11:09 AM

Just wanted to make sure you saw these two demos (the source code for them is in the physics helper download)?


Jul 16, 2010 at 3:57 AM
Hi Andy, I did see them, I think what I'm trying to do is something like this: <Canvas x:Name="cglass" Canvas.Left="661" Canvas.Top="85" CacheMode="BitmapCache" Height="390" Width="153"> <pb:PhysicsObjectBehavior Mass="3.6" RestitutionCoefficient="1"/> <pb:PhysicsFluidContainerBehavior/> <Rectangle.Fill> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF5DC3E8" Offset="0.004"/> <GradientStop Color="#FF192661" Offset="1"/> </LinearGradientBrush> </Rectangle.Fill> <Image Source="150px-Zombie_Glass.svg.png" CacheMode="BitmapCache"> </Image> </Canvas> So, basically a container which is also an object which you can move around. The object would be an image and I guess I have to fit the fluid container are inside the image (being the glass). The above doesn't work as I can't have the 2 types of behaviors together.
Jul 16, 2010 at 11:15 AM

Yeah the fluid container can only define a rectangular area where the fluid exists in the game Canvas.

I think the best you could do is have a large fluid container area, and then define a separate glass physics object which you can move around inside the fluid container. Unfortunately if you need things to fall outside of the glass they would still be affected by the fluid so this may not meet your needs.