Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (808)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (872)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  libgdx intersects color?  (Read 2913 times)
0 Members and 1 Guest are viewing this topic.
Offline SirSoltex

JGO Coder

Medals: 33
Exp: 1 year

Pixel-man, Programmer. Lover of the pancreas

« Posted 2015-06-03 06:51:17 »

Hi i'm learning the libGDX framework and i'm wondering is there some sort of intersects color method?
I have a Rectangle hitbox on a character and i want it to collide with everything but the floor and the floor will always be this constant color (brown) and everything else with be some other color red, green, blue, etc.

Any ideas on how i can achieve this would be great. Thanks! Smiley

Edit: is there anyway at all one can detect the color (of a background Texture) at any given vector on the screen?

Are you humans? I don't know.
Offline Husk

Senior Devvie

Medals: 20
Exp: 3 years

Want to learn everything.

« Reply #1 - Posted 2015-06-03 07:13:29 »

I really advise against using graphics to do your logic. Maintain a logical representation of your objects and perform logic on those, rendering is just how they are shown.

Offline Springrbua
« Reply #2 - Posted 2015-06-03 07:21:58 »


you should ALWAYS separate the logic and the view (visual representation) of your game.
That means, you should somehow store your Entitys type + it's hitbox (the Rectangle).

When drawing, you can use this type to draw the Rectangle with the right color:

if (entity.type == Entities.FLOOR)
    color = Color.MAROON;

Doing this, can make thigs, such as changing the view (maybe you want to have a 2.5D or even 3D view some time, or you only want to change from static Textures to Animations), much easier.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SirSoltex

JGO Coder

Medals: 33
Exp: 1 year

Pixel-man, Programmer. Lover of the pancreas

« Reply #3 - Posted 2015-06-03 08:19:05 »

thanks for the advice i was just looking for a way other than hard coding it all, i guess the only other way for me to do it is with either a tile map or hard coding some polygons to the walls for the collision. But then how would you do it if it's procedurally generated? my game is not but i'm curious Clueless

Are you humans? I don't know.
Offline Springrbua
« Reply #4 - Posted 2015-06-03 09:24:12 »

Does it make a difference, if it is procedural generated or hardcoded?
You always have to store your Map/Level data somewhere. This data can then be used for collision detection and rendering.

In your case, you should have a class "Entity", which stores the type (FLOOR, CHARACTER...) and it's hitbox (the Rectangle).
The you could have a class "World", which stores a list of all "Entities".
For collision detection you can iterate through all the Entities (in a nested for-loop) and check, if they can collide (you said character can't collide with floor) and if they can, check if they do.
It's not the most efficient way, but i guess, in your case it's just efficient enough.

For rendering you can iterate through all Entities and just draw a Rectangle, using the dimensions of their hitbox and the color, associated to their type.
Offline Soulfoam
« Reply #5 - Posted 2015-06-03 12:05:51 »

Never use graphics to dictate game logic.

You should have a list of tiles... regardless if you hardcode the map, procedurally generate it, or load it from an image etc etc.

In your tile class you can simply have an "isBlocked" flag or something, then from there just grab the players current X and current Y, and when the player is moving up, down, left, right or where ever, simply check if the players next move will collide with an isBlocked tile, and if it does don't move them there.

It isn't super difficult, research it a bit more and I'm positive you'll come across something that explains it pretty well.
Offline thedanisaur

JGO Knight

Medals: 59

« Reply #6 - Posted 2015-06-03 15:17:55 »

Use a bitmap image to represent your level and load that in. Then you can use colors from the image to build you map.

Every village needs an idiot Cool
Offline SirSoltex

JGO Coder

Medals: 33
Exp: 1 year

Pixel-man, Programmer. Lover of the pancreas

« Reply #7 - Posted 2015-06-03 23:41:03 »

Thank you all! I think i have found a way to do it by in each room hardcode a polyline around the edges and create collision based on that. Also i guess that the only way to do random generation is with a tile based system, but i'm too lazy to do that Smiley thanks for your advice ill just hardcode the thing.

Are you humans? I don't know.
Pages: [1]
  ignore  |  Print  

Riven (847 views)
2019-09-04 15:33:17

hadezbladez (5795 views)
2018-11-16 13:46:03

hadezbladez (2603 views)
2018-11-16 13:41:33

hadezbladez (6211 views)
2018-11-16 13:35:35

hadezbladez (1499 views)
2018-11-16 13:32:03

EgonOlsen (4734 views)
2018-06-10 19:43:48

EgonOlsen (5793 views)
2018-06-10 19:43:44

EgonOlsen (3276 views)
2018-06-10 19:43:20

DesertCoockie (4175 views)
2018-05-13 18:23:11

nelsongames (5501 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!