Slick Forums

Discuss the Slick 2D Library
It is currently Mon May 20, 2013 2:13 am

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Wed Jun 06, 2012 7:09 pm 
Offline

Joined: Tue May 22, 2012 8:24 pm
Posts: 49
Hello guys,

I'm trying to learn to code in slick on my own. And I tried to create collision for mouse, based on color ( or alpha ). I already managed to do collision detection based on color, on one image. But, when I try to apply the same thing onto another image, window just blinks and closes. I can't find what I am doing wrong, or is it bug.

Working image :
Attachment:
File comment: This is the working image
collision_img.png
collision_img.png [ 6.62 KiB | Viewed 182 times ]


Not working image :
Attachment:
File comment: This is the not working image...
ball_mask.png
ball_mask.png [ 2.39 KiB | Viewed 182 times ]


Project File : Meat Blaster


Top
 Profile  
 
PostPosted: Sun Jun 10, 2012 10:46 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1467
Can you provide a more succinct test and explain the problem a little further? Ideally a self-contained test that will show the problem. Right now I don't know what you are trying to do or what the problem is (is an exception thrown? If so, which one?).


Top
 Profile  
 
PostPosted: Mon Jun 11, 2012 12:08 pm 
Offline

Joined: Tue May 22, 2012 8:24 pm
Posts: 49
Download the project and you may see some errors.

I created one image, and used rectangle to get color from it, and write Collision on screen if it gets on to orange color.

When I swap the original image, with mask of ball, and try to use the same technique, window just pops up and then closes really fast, and it doesn't say is there an error or something. I'm really confused, and I don't know what to do...


Top
 Profile  
 
PostPosted: Wed Jun 13, 2012 1:02 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1467
Tried your code in Eclipse -- collision works fine. When I uncomment your image mask code I get the following exception:
Code:
Tue Jun 12 20:57:55 EDT 2012 ERROR:129000
java.lang.ArrayIndexOutOfBoundsException: 129000
   at org.newdawn.slick.Image.getColor(Image.java:1248)
   at javagame.Play.update(Play.java:114)
   at org.newdawn.slick.state.StateBasedGame.update(StateBasedGame.java:268)
   at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:657)
   at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:408)
   at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:318)
   at javagame.MyGame.main(MyGame.java:37)
Tue Jun 12 20:57:55 EDT 2012 ERROR:Game.update() failure - check the game code.
org.newdawn.slick.SlickException: Game.update() failure - check the game code.
   at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:663)
   at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:408)
   at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:318)
   at javagame.MyGame.main(MyGame.java:37)


It's pretty clear from the exception that your "index" is "out of bounds" when you call getColor. In other words, the x/y values you are passing to getColor are out of bounds.

Also it seems like you didn't take our advice last time you asked for it -- you're still initting every state unnecessarily in your game class. Maybe you'd benefit by learning a bit more about Java and programming in general.

Next time please (a) post the exception (it will show up in Eclipse), (b) post a more succinct test so we don't need to trudge through hundreds of lines of code, (c) give more details about what the problem is and how I might go about reproducing it. :)


Top
 Profile  
 
PostPosted: Thu Jun 14, 2012 6:27 pm 
Offline

Joined: Tue May 22, 2012 8:24 pm
Posts: 49
Thanks man, I am still learning, and I didn't see that exception thrown, but it's OK, thanks for help.

I'm so glad that there are persons like you, willing to help !

Thanks again !


Top
 Profile  
 
PostPosted: Thu Jun 21, 2012 9:31 pm 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
i would strongly advise you not to use the getColor for performance reasons, cause each time it re-loads the texture


Top
 Profile  
 
PostPosted: Fri Jun 22, 2012 3:59 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1467
mortias wrote:
i would strongly advise you not to use the getColor for performance reasons, cause each time it re-loads the texture

Slick lazily reads the texture data, then tries to keep it in memory. It will only reload if you call flush() on an Image's graphics object (i.e. changing the image, which means the data must be re-read).


Top
 Profile  
 
PostPosted: Fri Jun 22, 2012 7:04 am 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
i had a huge performance problem in my match3 because i wanted to add
a sort of highlight filter based on the color of the icons or something but because
these images change all the time it was always reading textures :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group