Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2 3 4
1  Game Development / Newbie & Debugging Questions / Re: ANDROID Perlin Noise clouds & CPU-Usage & Bitmaps on: 2014-11-14 16:46:04
Did you profile it? What's in isTransparent(...)?

1  
2  
3  
4  
5  
6  
   public boolean isTransparant(int image, int x, int y){
      if(getColor(image, x, y) == Colors.transparent){
         return true;
      }
      return false;
   }


I don't know if it is better to retrieve the pixels[] of the mask and only change the integers in that, that doesn't have the value 0 (which is transparent)... Changing that right now, and checking if it is a better way.

Then don't create a new Bitmap every time and recycle Bitmaps. Make two Bitmaps (mask and target) parameters to "generate clouds".  Handle the error case when mask and target are not the same size. Certainly the "clouds" bitmap can be recycled.  I don't know how many mask images you load or how often this method is called.

Recycling it is indeed a better way, but I don't know if that is really efficient, because if you want to overwrite a bitmap you need to make a copy (or I am wrong, kinda new to Android) But I am giving it a try

[Edit]:
O wow, it takes like some milliseconds to generate the entire map instead of 20 seconds... Reusing the Bitmaps with
1  
options.inMutable = true;
is like the heaven of speed ^w^!

And for the isTransparent fuction, i changed it to just retrieve the pixels[] from the mask and don't do anything if the value is 0 which is transparent. Because the getPixel function is probably not the most efficient function out there..
Thanks for all the help but I am still stuck with the Perlin Noise question, how can you really have cloudy effects (I am just shifting the x and y value). Like the effects that make the perlin noise clouds look like they are 'blooming'..

-RoseSlayer
2  Game Development / Newbie & Debugging Questions / Re: ANDROID Perlin Noise clouds & CPU-Usage & Bitmaps on: 2014-11-12 16:39:28
Ah, well if this is on Android, then all bets are off.

Well, it's a big twist, but whilst this topic was mainly about the generation of clouds using Perlin Noise, the rendering of the clouds are causing a problem..
3  Game Development / Newbie & Debugging Questions / Re: Perlin Noise clouds & CPU-Usage on: 2014-11-12 16:04:42
After some testing, i've proved that the Perlin Noise doesn't use alot of CPU, it's the creating of the bitmaps...
I think I've a really inefficient way of generating the Bitmap

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
public Bitmap generateClouds(int image, int depth, int height, int ex, int ey){
      Bitmap mask = BitmapFactory.decodeResource(getResources(), image, options);
      Bitmap clouds = createBitmap(mask.getWidth(), mask.getHeight());
     
      SimplexNoise sn = new SimplexNoise();
      int pixels[] = new int[mask.getWidth()*mask.getHeight()];
      for(int y = 0; y < mask.getHeight(); y++){
         for(int x = 0; x < mask.getWidth(); x++){
            if(!isTransparant(image, x, y)){
               int z = (int)(depth+(sn.octavedNoise(x + ex, y + ey, 3, 0.4f, 0.05f)+0.5)*(height-depth));
               if(z > 120){ //<Generates big clouds..
                  pixels[x+y*mask.getWidth()] = Colors.white;
               } else {
                  pixels[x+y*mask.getWidth()] = Colors.transparent;
               }
            }
         }
      }
     
      System.out.println(pixels);
      clouds.setPixels(pixels, 0, mask.getWidth(), 0, 0, mask.getWidth(), mask.getHeight());
     
      return clouds;
   }


Mask:


Result:
Whilst it provides a good result, it has a FPS of 3-6..




At the start of the game, it starts to generates like 16-22 Bitmaps and the time it takes is 20s...
4  Game Development / Newbie & Debugging Questions / ANDROID Perlin Noise clouds & CPU-Usage & Bitmaps on: 2014-11-11 16:26:21
Hi there,

I know there are probably millions of topics out there about this, but I can't seem to find a good tutorial on how to do it. The problem is that the FPS drops.. Are there any CPU-friendly ways to do it? Or shall I just have a noise tileset. I've already implemented a Perlin Noise gen. If there is any article about it, let me know.

As you probably know it needs an alpha level, yet I don't know how to accomplish it, because the bitmap is like only changing the alpha-level of all the pixels... The clouds only have 1 color and 3 alpha levels(AL). the first AL is like 0% transperant, the second AL is like 33% Transperant etc..

So basically, how to make clouds and changing alpha levels of them. Only use words if you can, I need to write my own program and learn from it ^w^!

-RoseSlayer

Post scriptum: if you have any questions just ask them!
5  Game Development / Newbie & Debugging Questions / Re: Android Bitmap on: 2014-10-21 19:10:49
Never worked with Bitmap, but my guess would be that the width of bmp is less than 11 + 22 = 33 as would be needed in the last line.

Edit: because it makes a subselection starting at x=11, of width=22, so you would end up at x=33 for the right edge of the selection.

Tyvm! I always did if it were positions on the bitmap itself, but they already do -start ._.''
6  Game Development / Newbie & Debugging Questions / Solved Android Bitmap on: 2014-10-21 18:54:54
I've a weird problem, which I don't know how to solve, as this website, doesn't give any information about it. So that is why I came here to ask you guys ^w^

Now my problem is that Bitmap is throwing an error in my face..

(Note: all the bmps are the same)
1  
bmpImage = Bitmap.createBitmap(bmp, 0, 0, 11, 11);

^This line works

1  
bmpImage = Bitmap.createBitmap(bmp, 0, 0, 22, 11);

^This line works

1  
bmpImage = Bitmap.createBitmap(bmp, 11, 0, 22, 11);

^This line throws an error:

1  
10-21 20:53:29.486: E/AndroidRuntime(27566): java.lang.IllegalArgumentException: x + width must be <= bitmap.width()


But the bitmap.getWidth() = 22 and the bitmap.getHeight() = 11 (as you can see from line 2, that is working..)
So basically I don't know what's really wrong about this line of code..

[Edit:] This topic should be in the android fora  Lips Sealed
7  Game Development / Newbie & Debugging Questions / Re: Orbital Mechanics / Velocity on: 2014-10-19 21:53:43
@ags1,
Well wow. How did I be so stupid, this will be alot easier! No algorithms mechanics needed just put them in a plain static path like the other entities. Thank you very much!

[EDIT]
Well it's solved now.  there is almost no CPU required this is all the code

1  
this.angleMagnification = -(Math.toRadians(360/(circumference/speed)));


1  
2  
3  
4  
5  
public void tick() {
   tick++;      
   this.x = (float) (orbiting.x + radius*Math.cos(angleMagnification*tick));
   this.y = (float) (orbiting.y + radius*Math.sin(angleMagnification*tick));
}


Thank you all very much and for your time spend. ♥
8  Game Development / Newbie & Debugging Questions / Re: Orbital Mechanics / Velocity on: 2014-10-19 18:31:21
I need to thank you all for your time, but I need to have a global picture of what I am dealing with.
The thing I want to accomplish is like a solar system with all the planets having a circular orbit (periapsis=apoapsis) and some moons having circular orbits around those planets. The only things I want to have a non 'static' path are comets. Could someone inventory the way how to accomplish this? like step by step a small procedure? I don't need any codes about it, just the procedure, or rather improve my procedure

Procedure
  • Every entity has a mass, starting position and the planet it is orbiting
  • Iterating all the entities and adds it change in position. This change in position is measured by the speed and the radius if the periapsis=apoapsis the radius is also the periapsis/apoapsis. Knowing this a circle around the sun(or planet it's orbiting) is Length = pi^2*radius. Having measured the length of the path you can get the angle by velocity/(length/360) = degrees. Having these degrees you can calculate the x and y that needs to be added.
  • Iterating comets?

Well as you still see I've some problems concerning comets and their calculations.. If there is anyone that knows the procedure to do that? The things I know now is that you need to calculate the vector of all the gravities together and then add velocity perpendicular to it. But I need a somewhat more specified procedure to do that..

[Edit]
It is also in 2 Dimensions, forgot to say that ..
9  Game Development / Newbie & Debugging Questions / Re: Orbital Mechanics / Velocity on: 2014-10-18 19:17:33
The only problem for that is that I need to work with vectors, and I believe Java hasn't a build in function for that so I need to design my own class. Having a bit of trouble with all the degrees, because if I am using tangets on a circle I will get some devided by 0 errors.. Also it's quite hard to figure out the degrees for the vectors, because of that...
10  Games Center / Android Showcase / Re: [Free] First Densetsu on: 2014-10-18 17:57:00
Graphics are reall good!
But what about the story? Does it even have a story I am interested!
11  Game Development / Newbie & Debugging Questions / Re: Orbital Mechanics / Velocity on: 2014-10-18 17:42:09
The moon have a speed in a direction, that is the vector Velocity.
Then you have the gravity, thats a vector from the moon to the center of the planet.

Each frame/update you calculate the gravity vector (moon center to planet center, normalized, plus gravity strength) and then add it to the velocity vector.

To start the simulation: set the position of the planet and then the position of the moon. Calculate the gravity vector and make the velocity be perpendicular to it.

Now for the moon to orbit you must find the equilibrium between moon speed and planet gravity.

If the speed is too high or the gravity too low, the moon will fly away. If the moon is too slow or the gravity too strong, the objects will collide.



+1
Is there also a calculation for the velocity in a circulair orbit?
And if I have like a moon that is orbiting a planet which is orbiting the sun, should I take both of their gravity vectors and then add the velocity vector perpendicular to it? So basically after smashing all the gravity vectors I add the velocity vector, but if I want to do that I should know a way to calculate the velocity. Any idea how I should accomplish that?
12  Game Development / Newbie & Debugging Questions / Re: Orbital Mechanics / Velocity on: 2014-10-18 17:13:48
V = sqrt(GM/r)  , off google where V = velocity required to sustain orbit G is gravitational constant, M is the mass of the central object , and R is the radius from the center of the orbit. you can recalculate R each time . meaning say velocity is too low them recalculate when R is , then reinput R into the equation to obtain the new value.

But how do I know in which direction this vector goes? Or just 90 degrees compared with the AccMagnitude?
13  Game Development / Newbie & Debugging Questions / [SOLVED] Orbital Mechanics / Velocity on: 2014-10-18 16:28:00
Greetings,
Currently working on Oribital Mechanics. The only problem I don't know how to solve after investigating alot of time is the fact that the object in space is pulled straight down to the planet/sun.. B

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
for (int i = 0; i < entities.size(); i++){ //go through all the planets
         if(entities.get(i) != sun){
            double distance = 0;
            for (int j = 0; j < entities.size(); j++){ //add up the gravitational effects of all the other planets
                 if (i != j){
                    distance = Math.sqrt(Math.pow((entities.get(i).getX() - entities.get(j).getX()), 2) + Math.pow((entities.get(i).getY() - entities.get(j).getY()), 2));
                    double G = 60000;
                    double accMag = (G*entities.get(j).getMass())/(Math.pow(distance, 2));
                    double accX = (accMag*(entities.get(j).getX() - entities.get(i).getX()))/distance;
                    double accY = (accMag*(entities.get(j).getY() - entities.get(i).getY()))/distance;
                    entities.get(i).addVX(accX);
                    entities.get(i).addVY(accY);
                 }
            }
              entities.get(i).updatePosition();
         }
      }


Click to Play

This said, means that I only got the accMagnitude and I don't know how I get the velocity. Also I know I probably should be using vectors to calculate it's path. So my question is how I can calculate the velocity. I am probably overlooking some things right now..

As always, thank you very much
-Roseslayer
14  Game Development / Newbie & Debugging Questions / Re: Double becomes infinity on: 2014-09-30 12:23:44
Step backward: Math.exp(x) = e^x.  you want x*x.

exp of zero is one.

yes, I want x^2. stupid of me ...
15  Game Development / Newbie & Debugging Questions / [SOLVED] Double becomes infinity on: 2014-09-30 12:13:16
Greetings,

I don't know what to do to solve this. If anyone know what's the problem, tell it to me in words. I am not learning if someone is pasting codes ^w^!
Tick
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
for (int i = 0; i < entities.size(); i++){
         if(entities.get(i) != sun){
            for (int j = 0; j < entities.size(); j++){
                 if (i != j){
                    double dist = Math.sqrt(Math.exp(entities.get(i).getX() - entities.get(j).getX()) + Math.exp(entities.get(i).getY() - entities.get(j).getY()));
                    double accMag = entities.get(j).getMass()/(Math.exp(dist));
                    double accX = accMag*(entities.get(j).getX() - entities.get(j).getY())/dist;
                    double accY = accMag*(entities.get(j).getY() - entities.get(j).getY())/dist;
                    entities.get(i).addVX(accX);
                    entities.get(i).addVY(accY);
                    System.out.println("dist: " + dist + ", accMag: " + accMag + ", accX: " + accX + ", accY: " + accY);
                 }
            }
              entities.get(i).updatePosition();  
              System.out.println("New postition of Planet [x=" + entities.get(i).getX() + ", y=" + entities.get(i).getY() + "]");
         }
      }


System.out.println()
1  
2  
dist: Infinity, accMag: 0.0, accX: 0.0, accY: 0.0
New postition of Kerbin [x=80000.0, y=0.0]


Well the problem is basically as you can see, that  dist is becomming Infinity, and because of this, the other variables are 0

-RoseSlayer
16  Game Development / Newbie & Debugging Questions / Re: Different stats on the same Array? on: 2014-01-08 15:18:06
So just make for every item a new class? But for the normal items like for example a leaf, without any customizable id's should I also make a new class?
17  Game Development / Newbie & Debugging Questions / Re: Different stats on the same Array? on: 2014-01-05 13:28:45
So basically I need to make a new instance of them and increase the ID everytime I add another sword?
18  Game Development / Newbie & Debugging Questions / Re: Different stats on the same Array? on: 2014-01-04 19:30:08
How did minecraft solved this problem? If changing the name of a sword the don't add another pointer to the Items[]?
19  Game Development / Newbie & Debugging Questions / Re: Different stats on the same Array? on: 2014-01-03 16:25:46
Are your fields for the attack damage etc. static? You'll want to make them instance variables, otherwise the stats will be shared between every instance of the item.

They aren't static, they are protected. All the variables are protected.
20  Game Development / Newbie & Debugging Questions / Different stats on the same Array? on: 2014-01-03 15:55:41
Hi there JGO,

first of all: happy new year! I've an array[] with all the items saved in them. If I change 1 stat of the array all the items with the same id will be changed aswell. So is there a way on having different stats in an Array[]? Please only tell me how to, I want to programm it myself!

Code:
1  
2  
3  
   public static final Items[] tiles = new Items[400];
   
   public static final Items SWORD = new ToolsSword(10, 12); //for example these stats are AttackDamage and AttackSpeed


With this code all the items (with the same id) will have the same AttackDamage and ASpeed. So what is the best way to be able to change the attackDamage without changing them all?

if you use something like this:
1  
2  
3  
Void changeAttackDamage(int attackDamage){
this.attackDamage = attackDamage;
}

then it will change the damage of all the items (with the same id).

If you don't understood the question, just say it.
Thanks for helping already!
-RoseSlayer
21  Game Development / Newbie & Debugging Questions / Re: Inventory, how to make cells 'bigger'. on: 2013-12-10 14:44:40
I personally think it would look very weird with the line still there because it just doesn't fit in the spot. The other thing you could do is create a miniature version of the texture and just use that instead. I think that would work better mechanics wise.

What do you mean with the miniature version, the items that you can see in the inventory are already size *2
& thank you for the +1  Cool

-RoseSlayer
22  Game Development / Newbie & Debugging Questions / Re: Inventory, how to make cells 'bigger'. on: 2013-12-09 20:59:33
Thanks for the help, as always!

This is the finished product:



-RoseSlayer
23  Game Development / Newbie & Debugging Questions / Re: Inventory, how to make cells 'bigger'. on: 2013-12-09 15:24:23
Thanks, going to work on it!
-RoseSlayer
24  Game Development / Newbie & Debugging Questions / Re: Inventory, how to make cells 'bigger'. on: 2013-12-09 14:41:18
So basically you want to make some "cells" bigger than the rest? I kinda don't really understand what you want to achieve. You want to keep some cells at size x, and make some others of size 2x ?

I don't want to make the cells bigger, but the items in the cell are bigger then the cell, so it needs to look like the cells has become bigger example:



As you can see here, some items are bigger then 1 cell.

-RoseSlayer
25  Game Development / Newbie & Debugging Questions / Inventory, how to make cells 'bigger'. on: 2013-12-09 14:26:29
Hi there JGO,

currently I am working on the Inventory. I had an idea to make some items bigger then 1 cell:



But if you can see it is only rendering a bit of the item. I had some ideas to make a few variables, and then just try things out. But it doesn't seem to work that good. The only part that was good is the selection of multiple Cells:

1  
2  
3  
4  
5  
6  
7  
8  
9  
   public List<Integer> biggerCell() {
      List<Integer> cells = new ArrayList<>();
      for(int x = 0 ; x < item[0].getWidth(); x++){
         for(int y = 0 ; y < item[0].getHeight(); y++){
            cells.add(this.x + x + (this.y + y) * maxWidth);
         }
      }
      return cells;
   }


So my question is: Are there any tutorials on how to make cells that are 'bigger' than 1 cell?
Or if you have any ideas, just post them and I will do something with it! (Please do not post any codes, I am still learning and it is not learning if I am copying stuff).

Thanks already!
-RoseSlayer
26  Game Development / Newbie & Debugging Questions / Re: Circle hitboxes. on: 2013-12-06 22:57:44
Screenshot I mean Tongue

But code would be nice too, if you so desire.

I don't have a for-loop so you cannot see the circle, I dont think I got time for making like random points around the character and draw the circle, currently working on items and armor:



Thanks for showing interest ^,^
-RoseSlayer
27  Game Development / Newbie & Debugging Questions / Re: Circle hitboxes. on: 2013-12-06 22:32:52
Can I see a pic of the new product? Tongue

Which product do you mean, the code or a screenshot of the game?

28  Game Development / Newbie & Debugging Questions / Re: Circle hitboxes. on: 2013-12-06 20:09:48
I've just found a possible answer,

Use Pythagoras' theorem!  A2 plus B2 = C2!

Have the point you are checking for check for the distance of x for 'A' and distance of y for 'B'. if the square root of 'C2'(also known as C) is less than or equal to the radius you are checking for, then the boundary has been reached! Cheesy

Haven't actually tried this out, but I hope I've helped.

! THANKS, Now it is a real circle, not a rotate Square! Cheesy
Thanks for all the help guys, love the JGO!
-RoseSlayer
29  Game Development / Newbie & Debugging Questions / Re: Circle hitboxes. on: 2013-12-06 20:05:34
It was stupid of me to make a hitbox for combat, it will take alot of cpu to do a forloop or algorithm the whole time, a simple code to calculate the pixels between the entities is much better:




These 2 pictures will show it is now a circle! (or is it a 45° turned square? Tongue)

-RoseSlayer
30  Game Development / Newbie & Debugging Questions / Re: Circle hitboxes. on: 2013-12-06 19:51:53
Why is your hitbox so big?

Its silly to have to change your collision algorithms just because you for some reason don't have a smaller hitbox. Just use an AABB and check against the tiles, which will also have hitboxes.

The other way you could do it is just to check if the tiles around the player are "solid", and if they aren't you can move. I don't recommend this way, however, because you can only check tiles, and the tiles will have to a uniform size with every other one. So you won't be able to have half tiles or special items with hitboxes. Just use AABBs, which by the way do not require for loops for anything.

As a side question, is your game based off of vanZebans game?

I even don't think I need a hitbox anymore, I could make a check like:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
   public boolean inRange(){
      int xDifference = entityTarget.x - x;
      int yDifference = entityTarget.y - y;
      if(xDifference < 0)
         xDifference = -xDifference;
      if(yDifference <0)
         yDifference = -yDifference;
      if(xDifference + (yDifference - 3) <= range)
         return true;
      return false;
   }
}


It was a hitbox for combat, not for walking.
and your side question is true. (wich is kinda obvious didn't changed character image Tongue).
-RoseSlayer
Pages: [1] 2 3 4
 

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

The first screenshot will be displayed as a thumbnail.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (48 views)
2014-11-29 21:32:03

toopeicgaming1999 (114 views)
2014-11-26 15:22:04

toopeicgaming1999 (102 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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!