Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (767)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (854)
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  
  Jesus, seperate entities PLEASE  (Read 2771 times)
0 Members and 1 Guest are viewing this topic.
Offline superhigh

Senior Newbie

« Posted 2013-04-30 03:04:32 »

Been going at this for a couple of hours on JUST this, and I can't seem to figure it out.
using it for debugging on collision detection.
well, I have an entity class, and all npcs and the player are entities, I keep all the entities in an arraylist except for the player.
my problem is, there is a method in the entity class that has their Rectangle, and since I'm debugging, I go to the render method and do, g.draw(rectangle), and it only draws it for the one entity, then I tried looping it from a different class eg.(for(Entity e : ents) {g.draw(e.getRectangle());}, and STILL only draws one of the entitys. This is really pissing me off.
Let me know if you need some of the code, or you could just explain to me what could be causing it.
And let me know if you need more info.
Offline loom_weaver

JGO Coder

Medals: 17

« Reply #1 - Posted 2013-04-30 03:22:56 »

Posting the code would be most helpful.

Also try doing a println of each rect to the logs or using the debugger.  This will help determine if they are all the same or if they are offscreen etc.
Offline ReBirth
« Reply #2 - Posted 2013-04-30 03:31:42 »

Why people have to ask code from you while you're asking for help?

First aid:
- Make sure your ents has > 1 entities
- Debug everything that static
- Printout ents.size() and entity's position

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Nate

« JGO Bitwise Duke »

Medals: 167
Projects: 4
Exp: 14 years

Esoteric Software

« Reply #3 - Posted 2013-04-30 15:39:29 »

Jesus says NO.

Offline Jimmt
« League of Dukes »

JGO Kernel

Medals: 167
Projects: 5
Exp: 6 years

« Reply #4 - Posted 2013-04-30 16:56:37 »

for(int i = 0; i < ents.size(); i++)

Assuming you're using arraylist. Like the others said, check the list size, make sure you're not breaking the loop anywhere, make sure that it truly isn't drawing it rather than it drawing it offscreen or really small/large.
Offline brollysan

Junior Devvie

Medals: 1

« Reply #5 - Posted 2013-04-30 17:47:31 »

Most likely all your entities are referring to the same rectangle making it show at one place only. Do the following in your entities:

public Rectangle getRectangle(){
return rectangle;

Less likely, quite obvious so you probably thought about it, the rectangles are off-screen. Eg you are drawing using the coordinates of the entities but remember while the worldmap may be large (2000x2000 pixels) the gamescreen might only be 512x512 in which case rendering with x,y values outside 512x512 will not show the rectangles, here is a very easy fix:

public Rectangle getRectangle(){
rectangle.setRect(getX()%512, getY()%512, getWidth(), getHeight());
return rectangle;

This again assumes you have screensize 512x512, just change with your actual widths and heights.

This will at least update the rectangle even if there is only one for all of the entities, assuming you have those getters in your class Smiley
Pages: [1]
  ignore  |  Print  

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

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

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

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

nelsongames (1106 views)
2018-04-24 18:15:36

nelsongames (1337 views)
2018-04-24 18:14:32

ivj94 (2077 views)
2018-03-24 14:47:39

ivj94 (1230 views)
2018-03-24 14:46:31

ivj94 (2188 views)
2018-03-24 14:43:53

Solater (798 views)
2018-03-17 05:04:08
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

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 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!