Jump to content
  • Advertisement

Juvelbagarn

Member
  • Content Count

    7
  • Joined

  • Last visited

Everything posted by Juvelbagarn

  1. Juvelbagarn

    Rectangle

    Hello everyone! I've just started programming XNA again and did not remember much about it, I didnt really complete any games.. Anyway, I ran in to some problem today, I'm trying to create a pong game and the bounces are kind of wierd. It seems like the rectangle is not a rectangle, more like a 1px dot on the top left corner, The ball is 20x20px size and the rectangle code looks like this: ballrec = new Rectangle((int)ballvec.X, (int)ballvec.Y, ball.Width, ball.Height); And this is the Draw section: spritebatch.Draw(ball,ballvec,ballrec,Color.White,0,new Vector2(0,0),1,SpriteEffects.None,0); when it bounces the ball only reacts to the top left corner, what am I doing wrong here? /Freemountain
  2. Juvelbagarn

    Rectangle

    Thank you, it worked. If I study the code you write it all make sense. i hope i get the collision with ball -> paddle correct aswell now Thanks once more.
  3. Juvelbagarn

    Rectangle

    Alright, I'm using spritebatch.Draw(ball, ballvec, Color.White); right now, and the problem is still there. here's some more code. int maxX = GraphicsDevice.Viewport.Width; int maxY = GraphicsDevice.Viewport.Height; ballrec = new Rectangle((int)ballvec.X, (int)ballvec.Y, ball.Width, ball.Height); //check for bounce if (ballvec.X > maxX || ballvec.X < 0) ballspeed.X *= -1; if (ballvec.Y > maxY || ballvec.Y < 0) ballspeed.Y *= -1; As I said before, the ball is 20x20px and i want the recangle to be 20x20 aswell. EDIT: changed "ballvec" to "ballrec" in "check for bounce" and the ball did not even bounce, just keept going off screen.
  4. Juvelbagarn

    Loop rectangles?

    Hello, I'm new to this forum and pretty new to C# and XNA (Still lerning a lot of C# and i'm NOT giving that shit up cus i KNOW i can lern it if i reallt try). ive made a 2d sprite -map, more or less.. it looks like this when the loop is finishd: ############ #-----------------# #-----------------# #-----------------# ############ Its all 32x32px squares and the sprites are drawn verry nice.. The only problem is.. I dont know how to loop the rectangles so i can find out the bounds. the only rectangle that work is the far bottom right, I think i know the problem but not how to solv it. I think i need several new names for the rectangles or loop them.. If you would be kind to explain it to me it would be verry helpfull. here are some of my code(Its all in the DRAW method): for (int i = 0; i < levels.level_0.GetLength(0); ++i) for (int j = 0; j < levels.level_0.GetLength(1); ++j) { Vector2 tilePos = new Vector2(j * 32, i * 32); if (levels.level_0[i, j] == 1) { mazeBounds = new Rectangle((int)tilePos.X, (int)tilePos.Y, 32, 32); spriteBatch.Draw(mapBrick, tilePos, Color.White); } } UPPDATE, this is the code im working with, the other one was the old one, from some wierd tutorial. Om sorry to confuse you.
  5. Juvelbagarn

    Loop rectangles?

    Jansic was on to something there.. i tried it but not with the result i wanted.. I simply want a rectangle for every sprite i draw, so that i make something happen when my mouse sprite touches (intersects) with the sprites. Simply, a maze, you tuch the walls you die and have to restart from "start position".. I don't know how to explain any better. As i said before, im verry new to OOP and C#/XNA. But i'm still lerning.
  6. Juvelbagarn

    Loop rectangles?

    mazeBounds tells me where the blocks are, i don't WANT em to reset, i want to create new ones, but i dont know how to.
  7. Juvelbagarn

    Loop rectangles?

    Yea, i want the rectangles to loop, just like the sprites..
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!