Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (498)
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 644 times)
0 Members and 1 Guest are viewing this topic.
Offline superhigh

Senior Newbie





« Posted 2013-04-30 05: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.
Thanks.
Offline loom_weaver

JGO Coder


Medals: 17



« Reply #1 - Posted 2013-04-30 05: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 05: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 Kernel


Medals: 128
Projects: 3
Exp: 14 years


Esoteric Software


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

Jesus says NO.

Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 114
Projects: 4
Exp: 3 years



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

1  
2  
for(int i = 0; i < ents.size(); i++)
g.draw(ents.get(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 Member


Medals: 1



« Reply #5 - Posted 2013-04-30 19: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:

1  
2  
3  
4  
public Rectangle getRectangle(){
rectangle.setRect(getX(),getY(),getWidth(),getHeight());
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:

1  
2  
3  
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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (15 views)
2014-04-15 18:08:23

BurntPizza (13 views)
2014-04-15 03:46:01

UprightPath (27 views)
2014-04-14 17:39:50

UprightPath (12 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (51 views)
2014-04-10 04:04:31

BurntPizza (110 views)
2014-04-08 23:06:04

tom_mai78101 (211 views)
2014-04-05 13:34:39

trollwarrior1 (179 views)
2014-04-04 12:06:45

CJLetsGame (185 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org 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‑gaming.org
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!