Ich benutze SFML mit Otter2d zum Spiele erstellen:
Ich benutze diesen Code:
|
C#-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
class MyEntity : Entity
{
float nx; // x-position for dragging
float ny; // y-position for dragging
bool isDragging; // handles the dragging
Input input; // the input shortcut
Image img; // the image of the entity
public MyEntity()
{
input = Game.Instance.Input; // initialize input
img = Content.myImg; // initialize img
AddGraphic(img); // add img graphic
}
public override void Update()
{
// call drag process
Drag();
base.Update();
}
/// <summary>
/// controls the dragging of the form
/// </summary>
private void Drag()
{
// if mouse is over image
if (input.MouseX > X && input.MouseX < X + img.ScaledWidth &&
input.MouseY > Y && input.MouseY < Y + img.ScaledHeight)
{
// if left mouse button was pressed while mouse over image
if (input.MouseButtonPressed(MouseButton.Left))
{
// calculate new coordinates for the object
nx = input.MouseX - X;
ny = input.MouseY - Y;
// set dragging to true
isDragging = true;
}
}
// if mouse is outside of image and left mouse button is down
if (input.MouseButtonDown(MouseButton.Left))
{
// if isDragging is true
if (isDragging == true)
{
// set new positions
X = input.MouseX - nx;
Y = input.MouseY - ny;
}
}
// if user releases the left mouse button
if (input.MouseButtonReleased(MouseButton.Left))
{
// set isDragging to false
isDragging = false;
}
}
}
|
Dieses Objekt stellt ein Bild dar was mit der Maus verschoben werden kann. Das funktioniert auch. Mein Problem ist allerdings das wenn man es bewegt das es an den Ecken flackert/flimmert.
Folgendes hab ich schon versucht:
- Den "Origin" des Bildes untersuchen ob er eine nicht unterstütze Zahl (wie 0.5f) enthält
- Die "Smooth"-Property auf true setzen.
- Video/Grafikkarten-Treiber aktualisieren
Ich weiß nicht woran es liegt, ich kann davon auch leider kein Video aufnehmen, weil man zumindest mit "Snagit" keine SFML-Spiele aufnehmen kann (da ist dann nur ein schwarzer Bildschirm auf den Aufnahmen aber sonst nichts)
Ich hoffe ihr könnt mir sagen wo der Fehler ist.