Show Posts
|
|
Pages: [1] 2
|
|
1
|
Java Game APIs & Engines / Java 2D / Re: Slick2D, play sound at location
|
on: 2013-04-07 19:49:31
|
but it isn't what I expected.
That not really descriptive. playAt(x, y, z) does EXACTLY what you want. make sure your sound files are MONO or it simply wont work Care to explain how the method works? What the parameters mean? The method is very poorly documented.
|
|
|
|
|
2
|
Java Game APIs & Engines / Java 2D / Re: Translating XNA method to Slick2D
|
on: 2013-04-04 00:08:01
|
Do I really need to learn linear algebra? That would require a background of math to, which I dont have. I checked the Slick2D api and I found a few interesting things but I am stuck at the first line in the method body: Matrix transformAToB = transformA * Matrix.Invert(transformB); How do I translate this? The real problem is that since Slick uses OpenGL for rendering, you won't have access to the color data without performing a copy from GPU to CPU (which can be slow).
Dont worry about that.
|
|
|
|
|
3
|
Java Game APIs & Engines / Java 2D / Translating XNA method to Slick2D
|
on: 2013-04-03 23:04:59
|
There is a method by Microsoft which perform a pixel perfect collision detection on two sprites. The special thing about this function is that it supports rotations! Here is the method: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| public static bool IntersectPixels( Matrix transformA, int widthA, int heightA, Color[] dataA, Matrix transformB, int widthB, int heightB, Color[] dataB) { Matrix transformAToB = transformA * Matrix.Invert(transformB);
Vector2 stepX = Vector2.TransformNormal(Vector2.UnitX, transformAToB); Vector2 stepY = Vector2.TransformNormal(Vector2.UnitY, transformAToB);
Vector2 yPosInB = Vector2.Transform(Vector2.Zero, transformAToB);
for (int yA = 0; yA < heightA; yA++) { Vector2 posInB = yPosInB;
for (int xA = 0; xA < widthA; xA++) { int xB = (int)Math.Round(posInB.X); int yB = (int)Math.Round(posInB.Y);
if (0 <= xB && xB < widthB && 0 <= yB && yB < heightB) { Color colorA = dataA[xA + yA * widthA]; Color colorB = dataB[xB + yB * widthB];
if (colorA.A != 0 && colorB.A != 0) { return true; } }
posInB += stepX; }
yPosInB += stepY; }
return false; } |
I am familiar with java so I can translate most of the code myself. width, height and color data I have access to so we dont have to worry about them. It is the Matrix and Transform classes that confuse me. What is their equivalence in Slick2D? Also, in my game, the rotation of the images is stored as an float.
|
|
|
|
|
5
|
Java Game APIs & Engines / Java 2D / Slick2D, play sound at location
|
on: 2013-03-14 19:07:48
|
|
So, I need help with an algorithm for my 2D Game. Say entity AA is emitting a sound. The strength of the emitting sound is determined by the distance between AA and BB(this could be the main character). The further away they are, the weaker the sound is. The max distance(pass this distance and the sound volume is 0) is of course customizable. The volume setting can be from 0.0 to 1.0. Where and when to do these checks is not a problem. I know my engine and I can resolve that. How to check it is the problem.
There is a method in Slick2Ds Sound class called playAt(x, y, z) but it isn't what I expected.
Maybe there already is a way to implement this with Slick2D?
|
|
|
|
|
9
|
Games Center / Showcase / Flesh Boy alpha
|
on: 2013-03-09 16:54:24
|
This is a public release of my latest project. I am hoping people will download it and give me some feedback.Open Source Fleh Boy is a 2d game with a simple concept, you finish a stage by reaching goal. You have a bunch enemies, a time limit and loads of hindrance trying to stop you from reaching there. Flesh Boy is heavily inspired by Super Meat Boy, N+ and NReality. Here is an ingame image:  You are that red guy doing a wall slide. In this release, I wont be showing any features. Instead, I am releasing a test map where you can check and feel the controller. I am mostly looking for controller feedback, but any type of feedback is appreciated: - Do you like the controller? Why? - Would you want to play a game with a controller like this? - Bugs? - Other thoughts? Download: http://www.gamedev.net/topic/639987-os-flesh-boy-alpha/Usage: Extract the content from the rar, launch the executable file. You need java 7 to run this.
|
|
|
|
|
10
|
Java Game APIs & Engines / Java 2D / Re: Obtain pixel from Image(Slick2D)
|
on: 2013-01-23 18:22:13
|
|
I am trying to create a fast pixel-perfect function. The only thing making it ineffective is grabbing the pixels from the Image. I have made a piss solution, by associating every image with an int[][] array(that represent all the pixels in the image). This array is initiated at loading screen. The results performance wise is fantastic. But it turns my code into a mess, killing the readability. And its not working with rotation.
|
|
|
|
|
12
|
Java Game APIs & Engines / Java 2D / Re: Adding a trailer behind a missile
|
on: 2013-01-08 02:22:45
|
|
ra4king: That lime-green circle is the target. The other dark-greyed-green-line is the smoke, which is incorrectly placed. But never mind that. I solved it, but a new problem occurred.
I see the problem. This line: stage.append(trailer.getClone(x, y + realHeight)); This just adds the trailer to the game, it does not render it. That happens later, when the rotation is restored to normal.
So I thought, I use g.renderAnimation instead of stage.append, so I can render it on the method where the rotation is taking place. The trailer is just an graphical effect anyway, with no properties. I quickly succeed to get the trailer where I wanted. However, I am getting erroneous results with drawAnimation(org.newdawn.slick.Animation). It seems like multiple animations that use the very same Image object can not be present at the same time. Even if I am calling drawAnimation every frame, only one animation is seeable. That is not the only problem, the graphic context is not rendering all frames in the animation. Yepp, for some reason, it is skipping some frames, making it look like it is blinking. Can anyone explain this?
|
|
|
|
|
15
|
Java Game APIs & Engines / Java 2D / Adding a trailer behind a missile
|
on: 2013-01-06 22:45:02
|
I know how to add a trailer behind a missile, but I am having trouble getting the right coordinates, the trailer is a bit off. So, first, I rotate the image so it is facing the target and render it: 1 2 3 4
| float rotation = (float) getAngle(x, y, targetX, targetY); g.rotate(x, y, rotation + 90); g.drawImage(missile, x, y); |
Then, I try to render the trailer behind the missile like this: 1 2 3 4 5
| if(trailer != null) { g.rotate(x, y + realHeight, rotation + 90); stage.append(trailer.getClone(x, y + realHeight)); } |
And finally, I make the rotation normal: g.rotate(0, 0, 0); Obviously this doesn't work. Any one have any idea?
|
|
|
|
|
16
|
Java Game APIs & Engines / Java 2D / Re: Draw a laser(Slick2D)
|
on: 2013-01-06 19:14:34
|
|
That laser fx thing gave me an idea. I just draw multiple lines(graphics.drawLine) with smaller strokes and different color on the same coordinates. That would make it look like a real laser.
|
|
|
|
|
18
|
Java Game APIs & Engines / Java 2D / Re: Save/load in java game with Slick2D
|
on: 2013-01-02 19:55:18
|
|
I doubt class exists. How is that nonexistent class suppose to know what to save? How is it suppose to know about the variables your games uses when they did not exist when that nonexistent class was developed? What you have to do, is that when the Save button is pressed, you save all the stats of the game, the health, the position of all the units etc.
|
|
|
|
|
19
|
Java Game APIs & Engines / Java 2D / Re: quickest most effecient way to darken/lighten image on the fly?
|
on: 2012-12-30 19:11:53
|
|
I advise you to stay away from Java2D when creating games. Java2D spend more time rendering than for example Slick2D does and, having fps such as 60 or higher is going to cause lag because Java2D can not render so many times per frame. So what is going to happen that it is going to skip rendering some frames, making the game look laggy, but in reality it is just rendering operation that are being aborted. Note that this do not happen on all computers, but you wanna make a game that looks the same on all computer, right?
|
|
|
|
|
21
|
Java Game APIs & Engines / Java 2D / Re: Use drawLine to render a bullet(Slick2D).
|
on: 2012-12-28 22:23:50
|
|
A gun fire at target. The projectile is traveling towards the target. I want to create a bullet effect, which would start at the projectiles x and y coordinate, and end... exactly where? I cant just use the projectiles x and y + 10(which would be the length of the bullet) because then would the bullet always be a vertical line rather than a rotated line.
I cant figure out how to get a correctly rotated line.
|
|
|
|
|
26
|
Java Game APIs & Engines / Java 2D / Apply AffineTransform to Slick2D?
|
on: 2012-12-21 20:20:43
|
With, Java2D, I did like this:1 2 3 4 5 6 7 8 9
| @Override public void draw(Graphics2D g) { AffineTransform transformer = new AffineTransform(); transformer.translate(-(Math.min(stage.width-stage.visibleWidth, Math.max(0, main.posX - stage.visibleWidth / 2))), -(Math.min(stage.height-stage.visibleHeight, Math.max(0, main.posY - stage.visibleHeight / 2)))); g.setTransform(transformer); } |
This works perfect. I tried similar in Slick2D: 1 2 3 4 5 6 7
| @Override public void render(GameContainer gc, Graphics g) throws SlickException { g.translate(-(Math.min(stage.width-stage.visibleWidth, Math.max(0, main.posX - stage.visibleWidth / 2))), -(Math.min(stage.height-stage.visibleHeight, Math.max(0, main.posY - stage.visibleHeight / 2)))); } |
This however, did not work at all. The result was that every thing in the window was black. How do I fix this?EDIT: This was an mistake by me. translate works fine for slick2d
|
|
|
|
|
27
|
Java Game APIs & Engines / Java 2D / Re: Pixel perfect collision detection
|
on: 2012-12-19 21:47:00
|
Is it safe to assume the sprites won't be scaled in anyway? As in their drawn size matches the image size? Or do you want help with sprites possibly being scaled as well...
The spriates wont be scaled in any way after they are loaded for the first time. I must ask, why are you doing it this way? is this a learning experience? cause it would be a lot easier to just get some pre-existing code thats already in java.
I cant find any pixel perfect code written in java, so I have to translate this C++ code.
|
|
|
|
|
28
|
Java Game APIs & Engines / Java 2D / Pixel perfect collision detection
|
on: 2012-12-18 23:28:30
|
I want to translate a C++ function I found on the net. Here is the C++ code: // Full object-to-object pixel-level collision detector: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| short int Sprite_Collide(sprite_ptr object1, sprite_ptr object2) { int left1, left2, over_left; int right1, right2, over_right; int top1, top2, over_top; int bottom1, bottom2, over_bottom; int over_width, over_height; int i, j; unsigned char *pixel1, *pixel2; left1 = object1->x; left2 = object2->x; right1 = object1->x + object1->width; right2 = object2->x + object2->width; top1 = object1->y; top2 = object2->y; bottom1 = object1->y + object1->height; bottom2 = object2->y + object2->height; if (bottom1 < top2) return(0); if (top1 > bottom2) return(0); if (right1 < left2) return(0); if (left1 > right2) return(0); if (bottom1 > bottom2) over_bottom = bottom2; else over_bottom = bottom1; if (top1 < top2) over_top = top2; else over_top = top1; if (right1 > right2) over_right = right2; else over_right = right1; if (left1 < left2) over_left = left2; else over_left = left1; i = ((over_top - object1\1->y) * object1->width) + over_left; pixel1 = object1->frames[object1->curr_frame] + i; j = ((over_top - object2->y) * object2->width) + over_left; pixel2 = object2->frames[object2->curr_frame] + j; for (i=0; i < over_height; I++) { for (j=0; j < over_width; j++) { if (*pixel1 > 0) && (*pixel2 > 0) return(1); pixel1++; pixel2++; } pixel1 += (object1->width - over_width); pixel2 += (object2->width - over_width); } return(0); }; |
I understand most of the code. I get lost at line 45 and downwards. Some help? PS I am using BufferedImage, and the getRGB methods are extremely slow. I am thinking to store all the colors in an int array, that is initialized before the game starts.
|
|
|
|
|
29
|
Java Game APIs & Engines / Java 2D / Re: Slick2d advantages?
|
on: 2012-12-18 20:22:40
|
|
Well, I am not that convinced to use Slick2D. I am not creating a high performance game anyway. However, my game looks laggy on my laptop for some odd reson(it is not really laggy as the fps is locked at 66. Its more like an graphical glitch), which is why I am considering switching to Slick2D.
|
|
|
|
|
30
|
Java Game APIs & Engines / Java 2D / Slick2d advantages?
|
on: 2012-12-18 02:33:31
|
|
Do Slick2D have advantages over Swing? Example, do it interfere with the native system better than Swing do? Why is it better than Swing? Isint Slick2D just a modified Swing window?
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|