Ivan Slavka

Greenhorn
+ Follow
since Feb 06, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ivan Slavka

Hi guys,

I'm trying to learn more about java computer graphics, and in my study I encountered following problem.
Probably there is a simple solution to this, but I'm baffled.

Here's the question, why the integers that represent color are not the same?
Also I noticed that when I change value 255 => 254 the integer of the color object gets recalculated but the one in the bufferedImage doesn't, why is that?

11 years ago
OK, guys. My bad. I found a problem. Thanks anyway.
Hi guys,

I'm having a very weird problem in Eclipse during debugging. I know that it is probably my error, but I can't figure out where, so I decided to ask for your help.
To explain the problem that I'm facing is a little but hard, but I'll try my best so bare with me on this one.

First of all, I have uploaded my project source files, so that anybody willing to help, is able to.
Source

I'm creating a tetris like game, and I'm a beginner so, if anybody has some advice about my code writing feel free to tell me, however my problem is priority.

Problem:
I put the breakpoint on line 251 in file ShapeCoordinator.java. The problem is, if my shape is able to rotate(there are no blocks in vicinity),
it successfully goes to this line, however if for example we have following situation (check attached image), the L shape on the left side shouldn't be able to rotate,
debug doesn't go to the above mentioned line because it's inside the condition which returns false (this behavior is correct), problem is that my shape gets turned anyway.

I can't figure out why my shape get's turned (second attached image). I tried to put breakpoints on other lines as well, however I'm unable to catch the breakpoint.

Probably it's my fault somewhere, however I'm unable to figure it out.
Thanks in advance for your help, and if you need some other info please feel free to ask.
Hi guys,

today I was reading about isometric and hexagonal maps for games( Isometric and Hexagonal maps ). Well personally I'm interested in hexagonal maps, but both of them had something similar. It is said, I quote: "Since both Iso and Hex tiles are contained in overlapping rectangles, you MUST USE BITMASKS!", well I don't understand why use bitmasks when I can create *.png image with transparency?

And another thing if this bit masking is really needed, how do I perform bit blitting in java, what methods or which class should I use?
12 years ago
Wow, Rob, thanks.

I wouldn't guess that, not in a million years. Well they could put that into the JavaDoc.
Thanks once again!
12 years ago
Hi guys!

I have a very strange problem. And I can't figure out what could be the problem.
I am developing my clone of the old game Frogger, I think that everybody knows the game I'm talking about.
Well the main reason to develop Frogger is to learn about java games and 2D graphics, anyway this is my problem.

When I run my Frogger application in Eclipse, all the images are shown with no problem with the appropriate animation
(Logs moving in one direction car in another), then when I export this project as Runnable Jar and start it, I can see all images,
except the car images. I know that the missing car images are moving because when I move my frog on the road it gets killed (returns to the start position.)

This is my class that loads and holds the required images. All the images are in the same folder (source)


This is my complete frogger application, feel free to download and study the code. (I didn't test on another machine, so if it works well on your machne let me know.)
Frogger
12 years ago
Guys, sorry for the trouble, but I figured out, what was the problem, my condition was incorrect. I fixed it by multiplying the radius. Because before it was only taking into the consideration only upper quarter as a boundary.
I was trying to resolve this for two days, I'm not sure if I'm suppose to laugh or cry.

Anyway, Rob thanks for the insight you gave me regarding the Timer and paint() method, I'll make sure to implement my code that way.

12 years ago
Hello Rob,

well as I said, I'm learning Java2D, so that is one half of the answer to your question, and the other half is that I read many resources,
and couple of books about Java Game programming like,

Java 2 Game Programming by Thomas Petchel and
Beginning Java SE 6 Game Programming, Third Edition by Jonathan S. Harbour,

and in both of these books, they are using Thread not javax.swing.Timer as well they are overriding paint() method.

Now, I'm not here to argue or judge who is correct and who is not, I just want to learn correct Java Game Development(not applets but fullscreen).

So I should use javax.swing.Timer even though I have only JPanel from Swing package, the rest of graphics is awt?
Then is this response (StackOverflow) to the question incorrect?

And about the paint() method. This article Oracle
says to use paint with awt and paintComponent with Swing. And I'm using awt to draw the shapes.
12 years ago
Thank you for welcoming me to the ranch Darryl, and once again I apologize for double posting.

Hello Randall,

yes I am overriding the paint() method of the JPanel. If I don't override it, where else would I draw my images?
I didn't want to post my whole Main class, in order not to scare other people , if you need more information I will gladly provide.

Here is my complete code of the above mentioned classes:
Notice it, doesn't have main method, that's because in my Main class I only instantiate the JFrame and then I add SphereBoard as a contentPane.

SphereBoard class


Sphere class



I apologize if the code seems a bit hard to read, but as I mentioned I am learning this Java2D and, I was experimenting.
12 years ago
Hi guys,

a month ago I decided to try to create a simple game. Well actually it's mostly playing with Java2D then creating a game.
Anyway here is my problem. I decided to learn how to move a shape (Sphere) based on the mouse position.
Ex. If I drag the mouse, the sphere follows the mouse, if I just press the button the sphere starts to move toward the mouse position.

My problem is I can't figure out how to stop the sphere when it's bounds contain the mouse position, basically when the sphere gets to the mouse it should stop.
Well to be more precise, I know how to do the logic to calculate if the mouse point is inside the sphere bounds, but the sphere doesn't stop. It just passes through.
And on some occasions when I start to drag the mouse very fast it stops.

At first I thought that it was concurrency problem (Main thread paints the sphere, MouseEvent thread assigns the mouse position), and I tested with locks, but the result was the same.
Is it possible that Java is just too slow for even this kind of simple animation, or am I missing something?

Here is my code:

Main class


Ball class



I apologize for double posting this thread, I posted it by mistake to the game development forum, and I don't know how to move it here.
12 years ago
Hi guys,

a month ago I decided to try to create a simple game. Well actually it's mostly playing with Java2D then creating a game.
Anyway here is my problem. I decided to learn how to move a shape (Sphere) based on the mouse position.
Ex. If I drag the mouse, the sphere follows the mouse, if I just press the button the sphere starts to move toward the mouse position.

My problem is I can't figure out how to stop the sphere when it's bounds contain the mouse position, basically when the sphere gets to the mouse it should stop.
Well to be more precise, I know how to do the logic to calculate if the mouse point is inside the sphere bounds, but the sphere doesn't stop. It just passes through.
And on some occasions when I start to drag the mouse very fast it stops.

At first I thought that it was concurrency problem (Main thread paints the sphere, MouseEvent thread assigns the mouse position), and I tested with locks, but the result was the same.
Is it possible that Java is just too slow for even this kind of simple animation, or am I missing something?

Here is my code:

Main class


Ball class
12 years ago