Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

dot

Supermoderator

Beiträge: 9 757

Wohnort: Graz

  • Private Nachricht senden

21

05.03.2013, 14:30

Sry, aber was genau erwartest du dir darauf für eine Antwort? Wobei genau hast du da nun ein Problem? Weißt du nicht wie man Tastendrücke abfängt oder was genau ist dir unklar? Was verwendest du überhaupt für eine Sprache? Wie zeichnest du deine Grafiken? Was hast du schon alles versucht? ...

Du beschreibst doch bereits genau, was für ein Verhalten du haben willst. Wo scheitert es nun konkret, wenn du versuchst, das oben von dir beschriebene Verhalten zu implementieren?

22

05.03.2013, 14:35

Deine Fragestellung lässt sehr zu wünschen übrig!

Das Problem das Du im Moment hast ist nach einigen Beiträgen klar... Du bekommst es nicht hin das bei Tastendruck Bild:A und sonst Bild:B angezeigt wird.

Dabei ergibt sich die Antwort darauf schon in der Fragestellung... Wenn Taste gedrückt zeige Bild:A sonst Bild:B

Um Dir besser helfen zu können würde schon mal helfen welche Sprache und/oder Framework du benutzt und ein Beispielcode kann auch nicht schaden...

PS. Das Forum läuft heute unter aller Sau...

H5::

Treue Seele

Beiträge: 368

Wohnort: Kiel

  • Private Nachricht senden

23

05.03.2013, 14:37

Wie hast du denn das bisher mit dem Standbild gelöst? Und wie das mit dem Bewegen des Standbildes (Sofern du das schon hast). Eventuell gibt es ja da etwas wo man mal ansetzen kann.

Generell würde ich aber erst mal sagen, du gehst genauso vor wie mit dem Standbild auch, das du nur durch das andere während der Bewegungsdauer (Tastendruck) entsprechend ersetzt. Genaueres kann man aber nur sagen wenn man weiß mit was und wie du es bisher gelöst hast.
:love: := Go;

De_Struktor

unregistriert

24

05.03.2013, 14:38

ich würde euch den code ja gerne zeigen, nur der hat knapp 500 zeilen angenommen und ich will nicht noch mehr verwirrung stiften aber gut:

Quellcode

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
 protected override void LoadContent()
 {

 // Create a new SpriteBatch, whichcan be used to draw textures.
 allPic_rect[0] = new Rectangle(30, 30, 30, 30);
 allPic_rect[1] = new Rectangle(30, 30, 30, 30);
 allPic_rect[2] = new Rectangle(30, 30, 30, 30);

 allPic[0] = Content.Load<Texture2D>("Spieler_statisch");
 allPic[1] = Content.Load<Texture2D>("Spieler_rechts");
 allPic[2] = Content.Load<Texture2D>("hinten_hero");

 allPic[3] = Content.Load<Texture2D>("constblock");
 allPic[4] = Content.Load<Texture2D>("bombableblock");

 allPic[5] = Content.Load<Texture2D>("Bomb1");
 allPic[6] = Content.Load<Texture2D>("invisibleWall");
 allPic[7] = Content.Load<Texture2D>("explosion");protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
timerDurrate += gameTime.ElapsedGameTime.TotalMilliseconds;
//Die Zeit die vom vergangenen Drawcall vergangen ist, hinzufügen

if (timerDurrate >= currTime) // Falls die gespeicherte Zeit größer ist als der Timer zum Ticken braucht, führ
// Anweisung aus bzw. führe ein Ereignis aus
{
timerDurrate = 0;
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

if (Keyboard.GetState().IsKeyUp(Keys.W))
{
block = false;
}
if (Keyboard.GetState().IsKeyUp(Keys.A))
{
block2 = false;
}
if (Keyboard.GetState().IsKeyUp(Keys.S))
{
block3 = false;
}
if (Keyboard.GetState().IsKeyUp(Keys.D))
{
block4 = false;
}
// Hier beginnt die Abfrage für den - W - Knopf
if (Keyboard.GetState().IsKeyDown(Keys.W))
{
if (!block)
{
block = true;
// allPic_rect[0] = spieler rechts schauend
// Spieleranimation nach rechts = allPic[1]
if (allPic_rect[0].Y >= 30)
{
allPic_rect[0].Y -= 30;

for (int d = 0; d < 216; d++)
{
if (constblock_rect[d].Intersects(allPic_rect[0]))
{
allPic_rect[0].Y += constblock_rect[d].Width;
}
}
for (int d = 0; d < 225; d++)
{
if (bombableblock_rect[d].Intersects(allPic_rect[0]))
{
allPic_rect[0].Y += bombableblock_rect[d].Width;
}
}
}
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.A))
{
if (!block2)
{
block2 = true;
if (allPic_rect[0].X >= 30)
{
allPic_rect[0].X -= 30;
}

for (int c = 0; c < 216; c++)
{
if (constblock_rect[c].Intersects(allPic_rect[0]))
{
allPic_rect[0].X -= constblock_rect[c].Height;
}
}
for (int c = 0; c < 225; c++)
{

if (bombableblock_rect[c].Intersects(allPic_rect[0]))
{
allPic_rect[0].X += bombableblock_rect[c].Height;
}
}
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.S))
{
if (!block3)
{
block3 = true;
if (allPic_rect[0].Y <= winValue[5] - 70)
{
allPic_rect[1].Y += 30;
}

if (Keyboard.GetState().IsKeyUp(Keys.D))
{ 

}
for (int o = 0; o < 216; o++)
{
if (constblock_rect[o].Intersects(allPic_rect[0]))
{
allPic_rect[0].X -= constblock_rect[o].Height;
}
}
for (int c = 0; c < 225; c++)
{
if (bombableblock_rect[c].Intersects(allPic_rect[0]))
{
allPic_rect[0].Y -= bombableblock_rect[c].Height;
}
}
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.D))
{
if (!block4)
{
block4 = true;
// block 4 = Tasten - D - ist gedrückt
if (allPic_rect[0].X <= winValue[4] - 70)
{
allPic_rect[0].X += 30;
}

for (int i = 0; i < 216; i++)
{
if (constblock_rect[i].Intersects(allPic_rect[0]))
{
allPic_rect[0].X -= constblock_rect[i].Width;

}
} 
for (int c = 0; c < 225; c++)
{
if (bombableblock_rect[c].Intersects(allPic_rect[0]))
{
allPic_rect[0].X -= bombableblock_rect[c].Width;
}
}
base.Update(gameTime);
}
}
}
}[/i][/i]
[i][i]// die allPic[0]) sind arrays, welche ich immer für verschiedene texturen benutze um nicht immer den vollständigen namen umändern zu müssen.[/i][/i]
[i]// ich bin mit den arrays immer gut klar gekommen[/i]
[i]
[/i]
[i]
[/i]

Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »BlueCobold« (05.03.2013, 15:44)


De_Struktor

unregistriert

25

05.03.2013, 14:56

der code ist SEHR abgekürtzt.
sonst sind es um di e 510 zeilen.

26

05.03.2013, 19:15

Meh, Zeilen nicht eingerückt und nicht die richtigen Code Tags benutzt. Ich bin leider kein Mod, deshalb poste ich es hier mal fix (vielen Dank an http://www.prettyprinter.de/ :D):

C-/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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
protected override void LoadContent()
{
    
    // Create a new SpriteBatch, whichcan be used to draw textures.
    allPic_rect[0] = new Rectangle(30, 30, 30, 30);
    allPic_rect[1] = new Rectangle(30, 30, 30, 30);
    allPic_rect[2] = new Rectangle(30, 30, 30, 30);
    
    allPic[0] = Content.Load&lt;Texture2D&gt;("Spieler_statisch");
    allPic[1] = Content.Load&lt;Texture2D&gt;("Spieler_rechts");
    allPic[2] = Content.Load&lt;Texture2D&gt;("hinten_hero");
    
    allPic[3] = Content.Load&lt;Texture2D&gt;("constblock");
    allPic[4] = Content.Load&lt;Texture2D&gt;("bombableblock");
    
    allPic[5] = Content.Load&lt;Texture2D&gt;("Bomb1");
    allPic[6] = Content.Load&lt;Texture2D&gt;("invisibleWall");
    allPic[7] = Content.Load&lt;Texture2D&gt;("explosion");protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
        this.Exit();
        timerDurrate += gameTime.ElapsedGameTime.TotalMilliseconds;
        //Die Zeit die vom vergangenen Drawcall vergangen ist, hinzufügen
        
        if (timerDurrate &gt;= currTime) // Falls die gespeicherte Zeit größer ist als der Timer zum Ticken braucht, führ
        // Anweisung aus bzw. führe ein Ereignis aus
        {
            timerDurrate = 0;
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();
            
            if (Keyboard.GetState().IsKeyUp(Keys.W))
            {
                block = false;
            }
            if (Keyboard.GetState().IsKeyUp(Keys.A))
            {
                block2 = false;
            }
            if (Keyboard.GetState().IsKeyUp(Keys.S))
            {
                block3 = false;
            }
            if (Keyboard.GetState().IsKeyUp(Keys.D))
            {
                block4 = false;
            }
            // Hier beginnt die Abfrage für den - W - Knopf
            if (Keyboard.GetState().IsKeyDown(Keys.W))
            {
                if (!block)
                {
                    block = true;
                    // allPic_rect[0] = spieler rechts schauend
                    // Spieleranimation nach rechts = allPic[1]
                    if (allPic_rect[0].Y &gt;= 30)
                    {
                        allPic_rect[0].Y -= 30;
                        
                        for (int d = 0; d &lt; 216; d++)
                        {
                            if (constblock_rect[d].Intersects(allPic_rect[0]))
                            {
                                allPic_rect[0].Y += constblock_rect[d].Width;
                            }
                        }
                        for (int d = 0; d &lt; 225; d++)
                        {
                            if (bombableblock_rect[d].Intersects(allPic_rect[0]))
                            {
                                allPic_rect[0].Y += bombableblock_rect[d].Width;
                            }
                        }
                    }
                }
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                if (!block2)
                {
                    block2 = true;
                    if (allPic_rect[0].X &gt;= 30)
                    {
                        allPic_rect[0].X -= 30;
                    }
                    
                    for (int c = 0; c &lt; 216; c++)
                    {
                        if (constblock_rect[c].Intersects(allPic_rect[0]))
                        {
                            allPic_rect[0].X -= constblock_rect[c].Height;
                        }
                    }
                    for (int c = 0; c &lt; 225; c++)
                    {
                        
                        if (bombableblock_rect[c].Intersects(allPic_rect[0]))
                        {
                            allPic_rect[0].X += bombableblock_rect[c].Height;
                        }
                    }
                }
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.S))
            {
                if (!block3)
                {
                    block3 = true;
                    if (allPic_rect[0].Y &lt;= winValue[5] - 70)
                    {
                        allPic_rect[1].Y += 30;
                    }
                    
                    if (Keyboard.GetState().IsKeyUp(Keys.D))
                    {
                        
                    }
                    for (int o = 0; o &lt; 216; o++)
                    {
                        if (constblock_rect[o].Intersects(allPic_rect[0]))
                        {
                            allPic_rect[0].X -= constblock_rect[o].Height;
                        }
                    }
                    for (int c = 0; c &lt; 225; c++)
                    {
                        if (bombableblock_rect[c].Intersects(allPic_rect[0]))
                        {
                            allPic_rect[0].Y -= bombableblock_rect[c].Height;
                        }
                    }
                }
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                if (!block4)
                {
                    block4 = true;
                    // block 4 = Tasten - D - ist gedrückt
                    if (allPic_rect[0].X &lt;= winValue[4] - 70)
                    {
                        allPic_rect[0].X += 30;
                    }
                    
                    for (int i = 0; i &lt; 216; i++)
                    {
                        if (constblock_rect[i].Intersects(allPic_rect[0]))
                        {
                            allPic_rect[0].X -= constblock_rect[i].Width;
                            
                        }
                    }
                    for (int c = 0; c &lt; 225; c++)
                    {
                        if (bombableblock_rect[c].Intersects(allPic_rect[0]))
                        {
                            allPic_rect[0].X -= bombableblock_rect[c].Width;
                        }
                    }
                    base.Update(gameTime);
                }
            }
        }
    }
Lieber dumm fragen, als dumm bleiben!

Schorsch

Supermoderator

Beiträge: 5 145

Wohnort: Wickede

Beruf: Softwareentwickler

  • Private Nachricht senden

27

05.03.2013, 19:38

Was ist das denn auch für eine LoadContent Methode? Da bringst du grad sehr viel durcheinander denke ich. LoadContent wird bei XNA nur am Anfang aufgerufen. Du suchst vermutlich die Update Methode.
„Es ist doch so. Zwei und zwei macht irgendwas, und vier und vier macht irgendwas. Leider nicht dasselbe, dann wär's leicht.
Das ist aber auch schon höhere Mathematik.“

De_Struktor

unregistriert

28

05.03.2013, 19:52

nein, schau mal weiter nach rechts, das ist alles die Update methode^^

De_Struktor

unregistriert

29

05.03.2013, 19:55

und wenn ich jetzt die figur nach vorne bewege, selbst mit dem richtigen bild, verstehe ich nicht, wie ich das alte bild auf der vorherigen position entferne, die alten
bilder werden immer startpositioniert.

De_Struktor

unregistriert

30

05.03.2013, 19:59

die beiden bilder : spieler_statisch und spieler_rechts sollen jeweils wenn sich der andere bewegt, mitgenommen werden, nicht das ein bild sozusagen zurückbleibt.
wenn ihr versteht was ich meine

Werbeanzeige