It is better for performance to use a lot of rectangles or a lot of vectors?

Started by
18 comments, last by KenWill 8 years, 10 months ago

So i' using LibGDX and i wanna know if it is better for performance to use a lot of rectangles or a lot of vectors or to do my collisions based on x and y?

Advertisement
Depends on too much factors. I'd say pick the one that codes the finest for you and see if you eventually get performance issues.

It's tempting to start giving pro's and cons for both, but then again this depends on tour goal (like, can you do everything you want easily with rects or do you want flexibility).

You could also go hybrid and use vectors + make your own struct for a rect, that makes things easier interchangable if you get into performance issues in the future.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Depends on too much factors. I'd say pick the one that codes the finest for you and see if you eventually get performance issues.

It's tempting to start giving pro's and cons for both, but then again this depends on tour goal (like, can you do everything you want easily with rects or do you want flexibility).

You could also go hybrid and use vectors + make your own struct for a rect, that makes things easier interchangable if you get into performance issues in the future.

Well i asked because if i'm not using rectangles i use vectors, and i have to use at least 3 vectors on each side for what i want and that's a total of 12 vectors. With rectangles i wanna check on which side they are and therefore use like 4 rectangles for 4 sides, and i don't know which one are taking heavilyon performance. I could also make just one rectangle and then make my collision detection based on x and y (or with the sprite alone) but i tried it and had some problems with the collisions so i dumped it. For the project i'm working on right now (a simple concept game thingy) i'll use rectangles and see if i have any problems with it, and if i do i'll just change it to vectors and see if that has the same problem or its better. I think i'll have on the screen at least 15-20 rectangles at a time and way more vectors if i use them, so do you think that will lower the performance or not? I don't think so but then again i'm new to programming and i didn't really care about optimization until now.


With rectangles i wanna check on which side they are and therefore use like 4 rectangles for 4 sides, and i don't know which one are taking heavilyon performance. I could also make just one rectangle and then make my collision detection based on x and y (or with the sprite alone) but i tried it and had some problems with the collisions so i dumped it.

You really should use 1 rectangle for collisions, and, the easiest way to check which side collided with what is to move your objects along 1 axis, then check for collisions, then move along the other axis and check for collisions.

This allows you to, not only know where the collisions occurred (move objects along x-axis, and if collided, you know which side caused the collisions), but also allows axis-independent movement (if you jump into a wall, you don't stop both X and Y movement, only the x movement, and you keep the y-movement going).

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)



You really should use 1 rectangle for collisions, and, the easiest way to check which side collided with what is to move your objects along 1 axis, then check for collisions, then move along the other axis and check for collisions.

This allows you to, not only know where the collisions occurred (move objects along x-axis, and if collided, you know which side caused the collisions), but also allows axis-independent movement (if you jump into a wall, you don't stop both X and Y movement, only the x movement, and you keep the y-movement going).

Sorry i am stupid...how do i do that...an example?

OMG NO NEED! I'm such a dumb ass i can't think fuck...no worries thanks a lot for your help. I discovered myself how to do it...long day of school brain no work.

Thanks a bunch!

Update: nevermind im a dumb fuck..please show me senpai ._.

Please watch your language, Ken. We have some kids reading these forums. Okay?

Personal life and your private thoughts always effect your career. Research is the intellectual backbone of game development and the first order. Version Control is crucial for full management of applications and software. The better the workflow pipeline, then the greater the potential output for a quality game. Completing projects is the last but finest order.

by Clinton, 3Ddreamer

Please watch your language, Ken. We have some kids reading these forums. Okay?

Fine fine geez...like kids are interested in anything else rather than justing biber...ya know you could've actually answer my question :3


.please show me senpai

Here's an old post I made that has some pseudo-code example moving along 1 axis, then checking for collisions, then moving along the other axis.

Link

Tell me where you're confused, and maybe I can help you better understand. And try to act like an adult while doing it.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)


like kids are interested in anything else rather than justing biber...ya know you could've actually answer my question :3

There are hundreds of thousands of youth who are gaming programmers. Many of them surf the web looking for game development information.

The well being of children and other youth is higher priority than all the programming in the world. High priority is also the ability of parents to trust that they don't have to supervise their children 100% of the time as kids view websites which are expected to be safe for them.

When or if you ever have children as a parent yourself, then you will begin to understand.

Personal life and your private thoughts always effect your career. Research is the intellectual backbone of game development and the first order. Version Control is crucial for full management of applications and software. The better the workflow pipeline, then the greater the potential output for a quality game. Completing projects is the last but finest order.

by Clinton, 3Ddreamer

This topic is closed to new replies.

Advertisement