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

Wirago

Alter Hase

Beiträge: 1 193

Wohnort: Stockerau

Beruf: CRM Application Manager

  • Private Nachricht senden

11

17.02.2013, 14:13

Dann versuchst du wohl einen Parameter zu übergeben der nicht vom Typ rectangle ist ^^

BlueCobold

Community-Fossil

Beiträge: 10 738

Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer

  • Private Nachricht senden

12

17.02.2013, 14:19

Nun, welche Intersects Methode hat denn 2 Ref- und einen Out-Parameter, wovon auch noch alle 3 Rects sind?

http://msdn.microsoft.com/en-us/library/…intersects.aspx
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

13

17.02.2013, 21:36

sobald ich die klammern der methode öffne, zeigt er in schwarz an: ref rec1, ref rec2, + (1 überladung) out;
sobald ich ein 3tes komma mache, steht: ref rectangle value1, ref rectangle value 2, ref rectangle , out rectangle resutl.
ich kann nicht ganz verstehen, wie ich genau mit der methode zu arbeiten habe, sry kenne micht mit xna framework noch nicht so gut aus,

Wirago

Alter Hase

Beiträge: 1 193

Wohnort: Stockerau

Beruf: CRM Application Manager

  • Private Nachricht senden

14

18.02.2013, 12:11

Wie BlueKobold schon geschrieben hat, in XNA prüfst du die Kollision von 2 Rechtecken per "Rectangle.Intersects(Rectangle)"
Wieso du hier mit mehr Überladungen arbeiten willst ist mir rätselhaft.

De_Struktor

unregistriert

15

20.02.2013, 18:47

ich entschuldige mich vielmals für mein rumgenerve, aber die kollisionserkennung ist echt hart :(, sitze seit einer woche dran. es klappt nix!

was ist falsch daran:

public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

Texture2D player1;
Rectangle player1_rect;

Texture2D bombableblock;
Texture2D constblock;

Rectangle[] bombableblock_rect = new Rectangle[100];
Rectangle[] constblock_rect = new Rectangle[217];
Rectangle staticblock;

//List<Rectangle> bombableblock_rect = new List<Rectangle>();
//List<Rectangle> constblock_rect = new List<Rectangle>();

int const_x = 0;
int const_y = 0;

int currWidth = 810;
int currHeight = 630;

bool block = false;
bool block2 = false;
bool block3 = false;
bool block4 = false;
bool block5 = false;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
graphics.PreferredBackBufferWidth = currWidth;
graphics.PreferredBackBufferHeight = currHeight;
graphics.ApplyChanges();
IsMouseVisible = true;
base.Initialize();
}

/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
player1 = Content.Load<Texture2D>("player");
player1_rect = new Rectangle(30, 30, 30, 30);

bombableblock = Content.Load<Texture2D>("bombable_block");
constblock = Content.Load<Texture2D>("staticblock");

spriteBatch = new SpriteBatch(GraphicsDevice);

for (int i = 0; i < 216; i++)
{
constblock_rect.Location = new Point(const_x, const_y);
constblock_rect[i].Height = 30;
constblock_rect[i].Width = 30;

if (i < 27)
{
const_x += 30;
}

else if (i >= 27 && i <= 47)
{
const_x = 0;
const_y += 30;
}

else if (i >= 47 && i <= 75)
{
const_y = 600;
const_x += 30;
}
else if (i >= 75 && i < 95)
{
const_x = currWidth - 30;
const_y -= 30;
}
else if (i == 95)
{
const_x = 60;
const_y = 60;
}
else if (i > 96)
{
const_y += 60;
if (const_y == 600)
{
const_x += 60;
const_y = 0;
}
}
}
const_x = 60;
const_y = 60;
// TODO: use this.Content to load your game content here
}

/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// 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;
}
if (Keyboard.GetState().IsKeyDown(Keys.W))
{
if (block == false)
{
block = true;
if (player1_rect.X >= 20)
{
for (int i = 0; i < 10; i++)
{
const_y += 60;

if (const_y > 540)
{
const_x += 60;
const_y = 0;
}
if (player1_rect.Y > const_y && player1_rect.X < const_x)
{
player1_rect.Y -= 30;
}
}
}
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.A))
{
if (!block2)
{
block2 = true;
if (player1_rect.X >= 45)
{
player1_rect.X -= 30;
}
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.S))
{
if (!block3)
{
block3 = true;
if (player1_rect.Y <= currHeight - 70)
{
player1_rect.Y += 30;
}
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.D))
{
if (!block4)
{
block4 = true;
if (player1_rect.X <= currWidth - 70)
{
player1_rect.X += 30;
}
}
}
if (constblock_rect[216].Intersects(player1_rect))
{
// player1.X = X - Koordinaten der figur egal wo sie sich bewegt
// player1.X = Y - Koordinaten der figur egal wo sie sich bewegt
player1_rect.Y -= constblock_rect[216].Height;
player1_rect.X -= constblock_rect[216].Width;
[/i][/i]
[i][i](DAs ist der wichtige Part) es klappt alles, nur nicht die kollision für die restlichen blöcke.[/i][/i]
[i][i]
}

// TODO: Add your update logic here
base.Update(gameTime);

}

/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.White);
spriteBatch.Begin();
spriteBatch.Draw(player1, player1_rect, Color.White);
for (int i = 0; i < constblock_rect.Count(); i++)
{
spriteBatch.Draw(constblock, constblock_rect[i], Color.White);

}
// TODO: Add your drawing code here
spriteBatch.End();
base.Draw(gameTime);
}
}
}
[/i][/i][/i]

Wirago

Alter Hase

Beiträge: 1 193

Wohnort: Stockerau

Beruf: CRM Application Manager

  • Private Nachricht senden

16

20.02.2013, 19:07

C#-Quelltext

1
2
3
4
5
6
7
8
if (constblock_rect[216].Intersects(player1_rect))
{
// player1.X = X - Koordinaten der figur egal wo sie sich bewegt
// player1.X = Y - Koordinaten der figur egal wo sie sich bewegt
player1_rect.Y -= constblock_rect[216].Height;
player1_rect.X -= constblock_rect[216].Width;
//(DAs ist der wichtige Part) es klappt alles, nur nicht die kollision für die restlichen blöcke.
}


Du hast ein Rectangle Array mit 217 Rectangles, die If Abfrage hier prüft genau EIN EINZIGES, nämlich das an Position 216 des Arrays. Wo sind die anderen 216? Oder testest du die Kollision mit genau dem Rect?

De_Struktor

unregistriert

17

20.02.2013, 19:17

nein, ich will alle abfragen.
meinst du mit foreach? besser um alle zuprüfen

De_Struktor

unregistriert

18

20.02.2013, 19:18

ich dachte, so bekommt die if abfrage alle elemente des arrays ab, wenn die indiezies bis zum max stehen.
mit der foreach schleife arbeiten?

De_Struktor

unregistriert

19

20.02.2013, 19:24

also für jedes der 217 blöcke soll abgefragtr werden, ob es überlappt, wenn das der fall ist, soll die figur nicht weiter in den block hineinlaufen.
und iwie missfällt mir, grad wie ich 0-216 sagen soll, nicht überlappen.

Schorsch

Supermoderator

Beiträge: 5 145

Wohnort: Wickede

Beruf: Softwareentwickler

  • Private Nachricht senden

20

20.02.2013, 19:30

Ich denke man kann das ganze hier beenden. Dein Problem ist nicht die Kollisionsabfrage, sondern dass du gewisse Dinge beim programmieren nicht verstanden hast. Das ist natürlich an sich nicht schlimm, aber an diesem Punkt solltest du aufhören und dir die C# Grundlagen angucken. Und damit meine ich kein XNA gespiele sondern erst mal nur C#. Wenn dir das zu lange dauert, guck dir mal GameMaker an. Man soll ja das als Hobby machen was einem Spaß macht. Und wenn einem die Lernerei so zu trocken und langweilig ist, ist es ja unsinnig das als Hobby zu machen. Wer eigentlich einfach Spiele machen will ist meiner Meinung nach am Anfang mit GameMaker und Co eh besser dran.
„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.“

Werbeanzeige