Invalidating image too fast - c#

I created simple app where the player moves the image to left and right. I am redrawing only the area of the player.
But if the player holds the key, the movement is too fast and you cannot see the image moving fast rather than flickering "something".
Any way to fix it? I am just beginning and am just 14 y/o so please bear with me.
What I am doing is on the key down event I recognize the arrow and then add or subtract to player class X and Y properties. Based on that I invalidate the area around the player.

If the main problem is flickering you want to be double-buffering (drawing to an area of memory - not the screen and then switching that area of memory to be drawn). Try setting these flags on your form (in its constructor):
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);

Related

AxWindowsMediaPlayer video 180 rotation or vertical flip (C#)

Is it possible to roatate (or flip) screen of AxWindowsMediaPlayer? I have found only one solution - to make screenshots with genereting Bitmap, RotateFlip() it and copy to PictureBox. By it requires one more showing Form (or graphical space anyway) for not rotated AxWindowsMediaPlayer. If you have any idea how to get Bitmap, for example, from hidden AxWindowsMediaPlayer directly or directly rotate AxWindowsMediaPlayer screen or you know different good player please help
many thanks

Detect UNITY UI image only moves inside another image or rect transform

I have two image in my unity scene.
One of this images is an square as background Recttransform and another image is a button.
I use Drag Event for this button to detect movement in run time.
But I want to move this button only inside the background image.
And I don't know how to make this limitation.
Is there any solution for this issue ?
For more explanation please see this image :
Off the top of my head, here are a two ways to do this:
Create a few invisible box colliders and place them at the edge of the red square. Probably easiest but more prone to issues when screen size changes.
Get Screen.width, Screen.height, Rect.width, and Rect.height. Only allow drag up to the edges of the screen minus 1/2 Rect.width and 1/2 Rect.height.

Animating an image not playing in game scene

I am trying to make an animation of a countdown.
I first made a Gameobject, created a canvas for it, and inside that canvas I created a UI Image, attached an image to it, and finally created an animation with that image.
Everything is working fine except the animation is not showing in game scene but only in normal scene, but when I go to that UI Image component and start the game I can see the image changing which means that its not the animation but something else.
Does anyone have an idea of what's going on?
There are several possibilities. Depending on if the image is showing up at all, you can check if your UI image is anchored correctly (four triangle marks) or pivot position is where you want it (circle mark). Depending on how this is done, if you Game window resizes in play-mode with the display set to Free Aspect, your image may move off the visible screen or, in some cases, get crushed which usually shows up as a red X in the editor. I can see this happening if your Game window is set to Maximize on Play.

ScrollRect not scrolling when canvas Render Mode is set to Screen Space - Camera

Did you find out why this was happening? I'm having the same issue here.
I had a canvas with a scroll bar working normally, I needed to set the canvas render mode to "Screen Space - Camera", and now the bar doesn't move anymore.
When you change the Canva's Render Mode from Screen Space - Overlay to Screen Space - Camera, an new slot called Render Camera will appear under the Canvas. Drag your main camera into this slot. That camera will be used to send events to the UI elements.
If you've already done this but the problem is still there, delete the ScrollRect and create a new one. Finally, if the ScrollRect is still not moving, make sure that no other UI object is blocking it.
Maybe a hidden panel or image with 0 alpha... Any UI object that is below the ScrollRect in the Hierarchy tab will block the ScrollRect if on top of it.
EDIT:
Once you drag the main camera to the Render Camera slot, Plane Distance slot will appear. Also make sure that it's not set to 0. Mine is set to 100 as shown in the screenshot above and that should work fine.
There might be multiple reasons why your scrollview doesn't work
I encountered with a similar problem. My canvas had a background image so i had to put a Image element without a sprite and set the alpha to "0" within Content of scrollview.
when your viewport field is not referring to viewport object in scroll rect
Try altering the movement type
I also had this problem due to not having an EventSystem in the scene.

C# XNA 4.0 Fullscreen Mouse Moves Into Second Monitor

The heading just about says it all. I derive from the XNA Game class, and set the IsMouseVisible = true. I have a dual screen setup with the secondary display being extended from the primary. I set my game to fullscreen mode (GraphicsDeviceManager.IsFullScreen = true). All works fine and fullscreen mode is initialized. The only problem I have is that the mouse does not stay bound within the fullscreen game. As soon as it reaches the edge of the fullscreen game, it seamlessly moves over onto the secondary monitor. Is this expected bahaviour?
I do a Mouse.GetState() to retrieve mouse info every frame on the same thread in which my game runs.
I have even tried setting Mouse.WindowHandle = GameWindowHandle before every call to GetState, but it does not change anything.
Any ideas? Or is this expected behaviour and I need to clamp the mouse to the fullscreen area myself?
Regards,
Riaan
Yes, exactly, clamp your mouse to the screen that you want it to stay on. This is similar to an approach that I (and many others) use when I implement sprite cursors for my games. I hide the system mouse, and clamp it to the center of the screen so that it doesn't show up on other monitors.
The only downside is that you have to un-clamp your mouse if you minimize the game, etc. Otherwise it stays stuck, which can be really annoying.

Categories