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

De_Struktor

unregistriert

1

30.03.2013, 21:22

Null - Exception

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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
hallo,
Projekt Bomberman: (wie bekannt)
    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ANX.Framework;
using ANX.Framework.Content;
using ANX.Framework.GamerServices;
using ANX.Framework.Graphics;
using ANX.Framework.Input;

namespace Bombersharp_Projekt
{
    public class Level_1 : ANX.Framework.Game
    {
       public Color color;

       public Texture2D constblock;
       public Texture2D bombableblock;
        
       public Rectangle[] bombableblock_rect = new Rectangle[225];
       public Rectangle[] constblock_rect = new Rectangle[216];

       private int[] winValue = new int[6] { 0, 0, 90, 30, 810, 630 };

        public Level_1(Texture2D constblock, Rectangle[]rectangle)
        {
            this.constblock = constblock;
            for (int i = 0; i < 216; i++)
            {
                constblock_rect[i] = rectangle[i];
                rectangle[i].Location = new Point(winValue[0], winValue[1]);
                rectangle[i].Height = 30;
                rectangle[i].Width = 30;
            }
        }
        public Level_1(Texture2D bombableblock, Rectangle[] rectangle, Color color)
        {
          this.bombableblock = bombableblock;
          this.color = color;
          for (int i = 0; i < 216; i++)
            {
                bombableblock_rect[i] = rectangle[i];
                rectangle[i].Location = new Point(winValue[0], winValue[1]);
                rectangle[i].Height = 30;
                rectangle[i].Width = 30;
            }
        }
        public void LoadConstblocks()
        {
            for (int i = 0; i < 216; i++)
            {
                constblock_rect[i].Location = new Point(winValue[0], winValue[1]);
                constblock_rect[i].Height = 30;
                constblock_rect[i].Width = 30;

                if (i < 27)
                {
                    winValue[0] += 30;
                }
                else if (i >= 27 && i <= 47)
                {
                    winValue[0] = 0;
                    winValue[1] += 30;
                }
                else if (i >= 47 && i <= 75)
                {
                    winValue[1] = 600;
                    winValue[0] += 30;
                }
                else if (i >= 75 && i < 95)
                {
                    winValue[0] = winValue[4] - 30;
                    winValue[1] -= 30;
                }
                else if (i == 95)
                {
                    winValue[0] = 60;
                    winValue[1] = 60;
                }
                else if (i > 96)
                {
                    // Const_y = winValue[1]
                    // Const_x = winValue[0]
                    winValue[1] += 60;
                    if (winValue[1] == 600)
                    {
                        winValue[0] += 60;
                        winValue[1] = 0;
                    }
                }
            }
            winValue[0] = 60;
            winValue[1] = 60;
        }
        public void LoadBombableblocks()
        {
            for (int j = 0; j <= 224; j++)
            {
                bombableblock_rect[j].Location = new Point(winValue[3], winValue[2]);
                bombableblock_rect[j].Width = 30;
                bombableblock_rect[j].Height = 30;
                if (j < 8)
                {
                    winValue[2] += 60;
                }
                else if (j > 8 && j < 24)
                {
                    winValue[3] = 90;
                    winValue[2] -= 60;
                }
                if (j > 24 && j < 32)
                {
                    winValue[3] = 150;
                    winValue[2] = 90;
                }
                else if (j >= 32 && j < 48)
                {
                    winValue[2] += 60;
                }
                // 4. Reihe von Blöcken
                if (j > 48 && j < 54)
                {
                    winValue[2] = 30;
                    winValue[3] = 210;
                }
                else if (j >= 54 && j < 62)
                {
                    winValue[2] += 60;
                }
                if (j > 62 && j < 70)
                {
                    winValue[2] = winValue[5] - 60;
                    winValue[3] = 270;
                }
                else if (j > 70 && j < 79)
                {
                    // Const_yy = winValue[2]
                    // Const_xx = winValue[3]
                    winValue[2] -= 60;
                }
                if (j > 79 && j < 88)
                {
                    winValue[2] = 30;
                    winValue[3] = 330;
                }
                else if (j > 88 && j < 97)
                {
                    winValue[2] += 60;
                }
                if (j > 97 && j < 105)
                {// 11 reihe
                    winValue[3] = 390;
                    winValue[2] = winValue[5] - 60;
                }
                else if (j > 105 && j < 114)
                {
                    winValue[2] -= 60;
                }
                if (j > 114 && j < 123)
                {
                    winValue[3] = 450;
                    winValue[2] = 30;
                }
                else if (j > 123 && j < 132)
                {
                    winValue[2] += 60;
                }
                if (j > 132 && j < 141)
                {
                    winValue[2] = winValue[5] - 60;
                    winValue[3] = 510;
                }
                else if (j > 141 && j < 150)
                {
                    winValue[2] -= 60;
                }
                if (j > 150 && j < 159)
                {
                    winValue[2] = 30;
                    winValue[3] = 570;
                }
                else if (j > 159 && j < 168)
                {
                    winValue[2] += 60;
                }
                if (j > 168 && j < 177)
                {
                    winValue[2] = winValue[5] - 60;
                    winValue[3] = 630;
                }
                else if (j > 177 && j < 186)
                {
                    winValue[2] -= 60;
                }
                if (j > 186 && j < 195)
                {
                    winValue[3] = 690;
                    winValue[2] = 30;
                }
                else if (j > 195 && j < 204)
                {
                    winValue[2] += 60;
                }
                if (j > 204 && j < 213)
                {
                    winValue[3] = 750;
                    winValue[2] = winValue[5] - 120;
                }
                else if (j > 213 && j < 221)
                {
                    winValue[2] -= 60;
                }
            }
        }
        public void DrawTexture(SpriteBatch spritebatch,Texture2D texture, Rectangle rect, Color c)
        {
            for (int i = 0; i < 216; i++)
            {
                spritebatch.Draw(constblock, constblock_rect[i], c);
            }
          
            for (int i = 0; i < 225; i++)
            {
                spritebatch.Draw(bombableblock, bombableblock_rect[i], c);
            }
        }
    }
}


// Ich habe eine Objektinstanz festgelegt, also deklariert und auch initialsiert:
    
Quellcode
1
Level_1 first_map;

sowie
first_map = new Level_1(Blocks[0], new Rectangle[216]);
first_map = new Level_1(Blocks[1], new Rectangle[225],Color.White);
            Blocks[0] = Content.Load<Texture2D>("constblock");
            Blocks[1] = Content.Load<Texture2D>("Block");
            
            first_map.LoadConstblocks();
            first_map.LoadBombableblocks();


alles in texturen geladen, objekt initialisert und konstruktorwerte übergeben und dann auch die methoden zum bauen der blöcke, alles gemacht.
dann sagt er mir bei kompillieren, ArgumentNullExeption: der wert darf nicht NULL sein.

und das zeigt er mir bei : spritebatch.Draw(CONSTBLOCK <----(an), bombableblock_rect, c);
und ich finde nicht heraus, was ich falsch geamcht habe, ich weiss normalerweise wie ich mit dieser fehlermeldung zu arbeiten habe, aber ich habe auch instanziert.
und beim konstruktor ist doch alles initialisiert oder nicht?

bitte um Hilfe

BlueCobold

Community-Fossil

Beiträge: 10 738

Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer

  • Private Nachricht senden

2

30.03.2013, 21:26

Du initialisierst zwar einen Array mit 216 Feldern, aber nicht die Felder an sich. Damit ist jedes Rect darin natürlich null und damit kracht es dann.
Teamleiter von Rickety Racquet (ehemals das "Foren-Projekt") und von Marble Theory

Willkommen auf SPPRO, auch dir wird man zu Unity oder zur Unreal-Engine raten, ganz bestimmt.[/Sarkasmus]

De_Struktor

unregistriert

3

30.03.2013, 21:29

kann ich die Instanzierung auch in einer for schleife initialisieren?
aus rein semantischer sicht
so dass ich alle 216 blöcke durchlaufe?

quasi:

Quellcode

1
2
3
4
for (int i = 0; i < constblock_rect.Length; i++)
            {
                first_map = new Level_1(Blocks[0], new Rectangle[constblock_rect.Length]);
            }

Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »De_Struktor« (30.03.2013, 21:40)


BlueCobold

Community-Fossil

Beiträge: 10 738

Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer

  • Private Nachricht senden

4

30.03.2013, 21:39

Ja.
Teamleiter von Rickety Racquet (ehemals das "Foren-Projekt") und von Marble Theory

Willkommen auf SPPRO, auch dir wird man zu Unity oder zur Unreal-Engine raten, ganz bestimmt.[/Sarkasmus]

De_Struktor

unregistriert

5

30.03.2013, 21:46

zwar gibt er keine laufzeitfehler mehr an, dennoch gibt er mir ein leeres fenster aus, ich suche den ganzen tag schon nach diesen fehlern.
nix.
und hier sind die variablen:

Quellcode

1
2
3
4
5
6
7
8
9
10
11
GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        int[] winValue = new int[6] { 0, 0, 90, 30, 810, 630 };

        Texture2D[] Blocks = new Texture2D[2];

        Rectangle[] constblock_rect = new Rectangle[216];
        Rectangle[] bombableblock_rect = new Rectangle[225];

        Level_1 first_map;

Quellcode

1
2
3
4
5
6
7
8
protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Yellow);
            spriteBatch.Begin();
            first_map.DrawTexture(spriteBatch, new Rectangle(winValue[0], winValue[1], 30, 30), Color.White);
            spriteBatch.End();
            base.Draw(gameTime);
        }
»De_Struktor« hat folgendes Bild angehängt:
  • Unbenannt.PNG

De_Struktor

unregistriert

6

30.03.2013, 23:43

komme einfach nicht drauf -,-

Schorsch

Supermoderator

Beiträge: 5 145

Wohnort: Wickede

Beruf: Softwareentwickler

  • Private Nachricht senden

7

31.03.2013, 13:07

Naja das Fenster sieht ja schon nicht Gelb aus. Was erhoffst du denn? Dass die Map sich zeichnet? An welchen Koordinaten denn ? und was ist mit den Werten in der Map los? Hast du mal versucht den Debugger zu nutzen? Mit Sicherheit ist der Fehler damit schnell gefunden.
„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

8

31.03.2013, 15:16

meinst du das die ich die winValue[6] {......}(siehe sourcecode), ihn nicht übergeben habe, sodass er keine werte zum zeichen hat,
jedoch sage ich ihn doch, beim zeichnen, er soll die werte von

Quellcode

1
2
3
4
5
6
7
for (int i = 0; i < 216; i++)
            {
                constblock_rect[i] = rectangle[i];
                rectangle[i].Location = new Point(winValue[0], winValue[1]);
                rectangle[i].Height = 30;
                rectangle[i].Width = 30;
            }

nehemn und dann zeichnen?!

Schorsch

Supermoderator

Beiträge: 5 145

Wohnort: Wickede

Beruf: Softwareentwickler

  • Private Nachricht senden

9

31.03.2013, 16:42

Ich hatte ja schon auf den Debugger angesprochen. Wir können jetzt so auch nur raten.
„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

10

01.04.2013, 15:14

bluecobold kannst du den thread dort danke löschen, denn ich vermute schon stark weshalb der fehler ist.
deswegen thread löschen!, wäre nett.

Werbeanzeige