Java-Gaming.org Hi !
Featured games (87)
games approved by the League of Dukes
Games in Showcase (649)
Games in Android Showcase (181)
games submitted by our members
Games in WIP (699)
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 ... 5
1  Game Development / Newbie & Debugging Questions / Re: Bit operating + Handling Weapons and/or Spells on: 2015-10-01 19:45:33
Also, are you sure you'll only ever need 16 traits? (bits) It'll be painful if you eventually find out you need more.

EDIT: the sort of cleaner way of doing this is with EnumSets, btw

Well, currently I am using 14 types and I can switch to integers to use 32bit...

I would argue that what you're doing here is basically like having an array of booleans. Instead of that, why not use an ArrayList that holds an enum type?

Like I said, which approach you take really depends on you. If you're really sticking with this bit approach, then check out bit shifting and the Integer class for some useful functions.

As you both suggest that I should use Enum types, I will gather some information about this subject. Thanks for helping me out. Honestly I also like to argue a bit with these kinds of things, it provides some usefull information. Well thanks again for the effort
-RoseSlayer
2  Game Development / Newbie & Debugging Questions / Re: Handling a large variety of spells and/or weapons (shorts|bit) on: 2015-10-01 19:30:13
Why in Gosling's name wouldn't you just use interfaces instead?

Or better yet, a "composition over inheritance" approach like we've been talking about?

I am using composition over inheritance, but the type is declared in the very base of all things.
The (short)type is only used for holdingcells that only can hold that type (of a combination like that (i.e. CellB)). I think this is the most clean and best way to approach this situation. I am not using instanceof etcetera, also the possibilities of doing it this way is endless. Why do I need to create new lines of codes if I only need to test if a bit of the short is 0 or 1?

Thanks for responding as fast as you just did.
-RoseSlayer
3  Game Development / Newbie & Debugging Questions / Re: solved Handling a large variety of spells and/or weapons on: 2015-10-01 19:20:31
Thank you all for your support.

The way of creating a large variety of spells and weapons is working now.
All the items do have the following in them:
1  
short type


the types that are currently possible are the following:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
   public static final short allType = -1;
   public static final short equip = 2;
   public static final short consumable = 4;
   public static final short material = 8;
   public static final short spell = 16;
   public static final short weapon = 32;
   public static final short shield = 64;
   public static final short backpack = 128;
   public static final short ammo = 256;
   public static final short face = 512;
   public static final short helmet = 1024;
   public static final short body = 2048;
   public static final short boots = 4096;
   public static final short gloves = 8192;


The reason why I've done this is to make it quite easy to create an item that is made out of multiple types.
for example I have a sword:
1  
Sword sword(short(equip & sword))

If you write it in shorts:
1  
2  
3  
4  
equip = 0000000000000010
weapon = 0000000000100000
/* so sword has those types together */
sword = 0000000000100010

so sword will have the type:

But with only this knowledge I am stuck:

I have a cell, cellA that only accepts equip, and cellB that accepts equip, weapon and shield but how to test if the bit on that place is 1 or 0?
I don't know if it is possible to use these kind of bit operators anyways, so if you know anything about this subject, provide me with some of your delicious information.

As always, thanks for reading
-RoseSlayer
4  Game Development / Newbie & Debugging Questions / Re: Three Dimensional Array 'dupe' glitch on: 2015-09-20 17:32:40
Hint: What do you think Array.fill() does with it's arguments?

You are creating ONE instance of InventoryCell(null), and put that in every slot of the array.

As the array only holds references, you'll see that changing the data in the InventoryCell instance, will be visible from every slot in the array.

I feel dumb...
Thanks anyways  Grin
-RoseSlayer
5  Game Development / Newbie & Debugging Questions / Three Dimensional Array 'dupe' glitch on: 2015-09-20 17:22:36
Greetings again,

I've spent some hours trying to solve it, rechecking all the classes etc, but I can't seem to find where the problem is. So I believe after some Trail-And-Error that it was the Three DImension Array itself. The problem is that an item that is added to the Array i.e.
1  
inventorySpells[0][0][0]

gets duped to
1  
inventorySpells[0][0][n]


Initialize:
1  
2  
3  
4  
5  
6  
      inventorySpells = new InventoryCell[INV_WIDTH][INV_HEIGHT][2];
      for (InventoryCell[][] square: inventorySpells) {
         for (InventoryCell[] line : square) {
            Arrays.fill(line, new InventoryCell(null));
         }
      }


Adding a new element:
1  
               inventorySpells[x][y][0].setItem(spell);

(note): This is the only function that adds something to the InventoryCell[][][]

With some good old System.out.print, I've found that
1  
inventorySpells[0][0][0] = inventorySpells[0][0][n∞]//Well it isn't infinity because it can get a max value of 1, but you get the clue


So the problem is that the Third Dimension doesn't matter at all, because changing a z-value, will result in the same x-value and y-value.
I really the three dimension array, it's much cleaner and uses less lines than using multiple Two Dimensional Arrays...

Anyone know what this problem is all about? If there is something not clear, just ask me.
-RoseSlayer
6  Game Development / Newbie & Debugging Questions / Re: Handling a large variety of spells and/or weapons on: 2015-09-17 18:07:15
Similarly, you'd create a new instance of the Spell class whenever a player earned that spell. You wouldn't need to share instances between players, and you wouldn't need one master class responsible for creating spells.

I know this sounds terrible, but the problem is I don't know how to create a new instance of a spell without hardcoding the atributes into the enemy/player class...

1  
Spell fireball = new Spell(1, false);


Because of this I have always used a static class that contains the weapons/spells. If I faced an constructor that doesn't require any attributes I am still confused with making a new instance of a spell because I will hardcode it like:

1  
Spell fireball = new SpellFireBall(); 


/*Edit*/
Nvm, just need to implement cloneable and clone it with the list you've already provided, am I right?
1  
2  
3  
4  
public static Spell getSpell(String name) {
    if (!spells.containsKey(name)) throw new IllegalArgumentException(...);
    return spells.get(name).copy();
}


-RoseSlayer
7  Game Development / Newbie & Debugging Questions / Re: Handling a large variety of spells and/or weapons on: 2015-09-17 17:21:29
I think it really depends on how your characters obtain these weapons and spells in the first place. Are they located in the game world (on the map or in a chest or something)? Are they obtained automatically? Are they there from the beginning?

The weapons are obtained by the following: Crafting, trading/buying, drops
The spells are obtained by the following: Monsters have a very small chance to give the player a spell that fits the monster unique ability (atleast if the player has the requirments) if killed.

With Java 8 the landscape of inheritance vs composition ideological conflicts has subtly changed with the advent of default methods in interfaces.

Well this doesn't help me much, unfortunately...

Yeap. And functional interfaces.  Take a bioware or elder scrolls like game, using an archtype system all items, monsters, effects, etc. could be defined using only inheritance in around a dozen classes.  (give or take given some design decisions).  Player's designing their own doesn't add any problems here either.  Who is creating the data does matter for the base system...it's all just data. 

This excludes all "game mechanic" code.  But in java8 that can be however many static utility (or enum classes) one needs.  Each of these is more or less independent of everyone else.  Java 8 drastically reduces the number of classes required due to functional interfaces.

This is exactly what I am trying to achieve, do you know how this work and give some small information about it?

As always, thanks for the posts and time spended.
-RoseSlayer

8  Game Development / Newbie & Debugging Questions / Re: Handling a large variety of spells and/or weapons on: 2015-09-16 19:06:34
Just chiming in here:
There is no such thing as 'the best', since different games/applications need different functionality.
You can't make a 'fit all' solution, its simply not possible.
There is no the best, I know but I am trying to gain alot of information about this subject, I've had trouble with this in the past. Just need some tactics how other handle it.

I'm not sure why you need that second class. You might also save a bunch of Spells to a text file or something. How you store them is up to you.
I've done this kind of large classes in the past and always had some trouble with it. If I create as example a weapon like fireAxe = new Weapon(1, "fireAxe"); and I give this weapon to multiple entities i.e. the player and a creature. If the durability is 1 and I hit a tree with this axe, both my weapon and his weapon will be broken, as the object that is in their hands is reffering to the same object. I don't know how to handle this type of multipleUsage classes. I know the player can do a Weapon myWeapon = new Weapon(1, "fireAxe") and the same in the creature. So they have not the same objects held in their hands, this is the way to tackle this problem, but it is not the smartest to write the constructor of your weapon in the main class (if you get what I mean with this). I want a global class that has easy access to all of the different weapons. So it only takes one line (withouting adding variables yourself), to take the weapon and use it (without duping it). How are you handling that?
/*Edit*/
Well I know you can do the following to get a weapon without duping it,    
1  
public Weapon createFireAxe(){return new Weapon(1, "fireAxe");}

but this isn't a great way of getting a specific weapon.

-RoseSlayer
9  Game Development / Newbie & Debugging Questions / Re: Handling a large variety of spells and/or weapons on: 2015-09-16 18:41:47
Use composition instead of inheritance. (More info here).

In other words, you shouldn't have a bunch of classes for different kinds of spells. You should have a single Spell class, and that class should contain (in other words, be composed of) all of the variables necessary to describe the different kinds of spells. Then to create a new spell, you just create a new instance of Spell, not a new subclass.

So basically I need to create like two classes:
  • Spell - A class that contains all the code which has a constructor, so you can edit everything
  • Spells - In here you create a spell like: Spell fireball = new Spell(1, true, 12.1f (...))

Well this will safe alot of time, but spells are in this way not unique. So if you have multiple players with a fireball, playerA has fireball(lv.1) and playerB has fireball(lv.14), they will both be calling the same fireball. I know you can do fireball.cast(levelFireball) etcetera, but with weapons this will not work (atleast I don't believe it will), also using this methode I cannot use different ways of leveling up a spell, for example a spell like enrage(this will buff the player), has other variables then a spell like fireball. If for example upgrading fireball from lv.1 -> lv.2 will give it an unique feature like spawn triple fireballs, how will I handle this in the Spell class. Doesn't this class get way too large if I create like 20 different levelMethodes?

/*Edit*/
Didn't saw you had add some more information in your comment. Thanks again for spending time, but yet I've those questions

/*Edit2*/
I can also create a class that contains vars as:
1  
2  
3  
   public static final byte focusEnemy = 0;
   public static final byte focusPlayer = 1;
   public static final byte focuseAll = 2;

and just call them in the  Spells class as:
1  
2  
   Spell fireBall = new Spell(true, focusEnemy);
   Spell enrage = new Spell(true, focusPlayer);

This type of spellHandling is already alot better than I am currently doing, but still is it the best?

What is your way to tackle this problem?
-RoseSlayer (Also thanks for responding as quick as you did!)
10  Game Development / Newbie & Debugging Questions / Bit operating + Handling Weapons and/or Spells on: 2015-09-16 18:19:17
Good afternoon,

as the title already has stated, I am trying to handle a large variety of spells (and/or weapons). Because weapons are basically the same idea as spells we will not talk about them. Basically I am new in handling large amount of objects which are almost the same. The only problem is that I do not know, where I need to start. I've searched online and found some decent tutorials about oop and Multiple Inheritance. But I've not become much smarter after reading that. The only thing I've learned is that you need to use Interfaces. But I believe that Interfaces are not that usefull, because you still need to write and copy all the code to do the same thing.

Interfaces
Java Multiple Inheritance

My Current setup is as following:
  • EntitySpell extends Sprite
  • SpellCaster (*)
  • Spell (**)
  • SpellFireBall extends Spell (***)

*SpellCaster:
This class is basically just a timer of the spell it is 'holding'. It is also holding the level of the spell (but I've not implemented the leveling system yet).

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  
[quote]public class SpellCaster {
   private float timer;
   
   Spell spell;
   
   public SpellCaster(Spell spell, int level){
      this.spell = spell;
      this.timer = spell.getCooldown();
   }
   
   public void update(float dt){
      if(timer < spell.getCooldown())
         timer+=dt;
   }
   
   public float getMana(){
      return spell.getMana();
   }
   
   public boolean castSpell(float x, float y){
      if(timer >= spell.getCooldown()){
         spell.castSpell(x, y);
         timer = 0;
         return true;
      } else {
         return false;
      }
   }
}

The castSpell is a boolean, if it get casted, then the mana of the player will be reduced by the manaCost which is located in the SpellCaster

**Spell:
Just a simple abstract class that contains some information about the spell i.e. mana/cooldown (and it passes the castSpell event).

***SpellFireBall:
This is the real problem, I am trying to solve the issues it is providing me with, I don't want to write the code twice on multiple Spells like i.e. SpellLightningBolt. It is just a waste of space and time, at this moment it is still a small class without many lines of code in it, but when this class is completed it will be filled with information which is on many spells the same (but remember, not all the spells will be the same, i.e. buffs will be targeted to player instead of target to the cursor. These buffs will only work on the player and not on the enemy unlike the spell FireBall).
Because of this I cannot create a superclass Spell that is extended by SpellFireBall. So what is the best way of creating classes like Spells and or Weapons.

Please, if you have dealt with this issue on your project(s), can you tell me what you've done? I am not seeking for your codes or whatever, just a summary of what you've done or what you think that is the correct way.

If you have any question about the script, what I am doing etcetera, just post a comment to ask :-)

As always, thanks for reading the post
-RoseSlayer
11  Game Development / Game Mechanics / Re: LibGDX Celestial/Planetary bodies TileMap on: 2015-05-10 16:20:03
I get it, was thinking about changing the texture aswell to get a hill etc. Thank you very much for your help.

The game in the last image is probably, as you said, another approach, but your approach is better for the thing I want to accomplish, so thank you very much.
Now I need to tackle another problem, the hitboxes etc.

I don't need a fixed scale regardless of the distance you are from the center of the planet, well not for the tilemap, only for the entities (but that's not any problem).

Thank you very much, for your fast responding and your help!
-RoseSlayer
12  Game Development / Game Mechanics / Re: LibGDX Celestial/Planetary bodies TileMap on: 2015-05-10 15:52:05
Yes that is exactly what I meant. Is it also possible to have variation in Height, or even better using a dynamic Tilemap like in Terraria?

13  Game Development / Game Mechanics / LibGDX Celestial/Planetary bodies TileMap on: 2015-05-10 14:02:02
Dear JGO-Community,

Currently I am doing some research about Planetary body Tilesystem.
But what is it what I am trying to figure out?
Well take for example these to pictures:

Picture 1: Celestial/Planetary bodies


Picture 2: Terraria Tilemap


The idea is to get the TileMap as Terraria (picture2) into a celestial/planetary body (picture1).
But I've no idea how to accomplish this type of Tile System/Management.
I think it's just as simple as wrapping a TileMap around the body, but I've also no idea on how to accomplish that.

As far as I've researched, I cannot find any information about this subject. Maybe because I cannot find any information is because I don't know how to describe the thing I want to find. So if any of you know anything about this subject, just post the link etc.

I really need the help of you guys, so if you know anything about this subject, or know some information (e.g. wikipedia article/github etc.) just post it.

If you have any question, feel free to ask them.

Thanks for reading and/or helping
-RoseSlayer

14  Game Development / Newbie & Debugging Questions / Re: Check if it's a combo/streak on: 2015-03-08 16:10:42
First of all, thanks for all the help and time investigated.
BurntPizza, and richierich, you both understood the problem.
But there is another problem by doing the following:

1  
2  
if (grid[y][x+1] == cellValue && grid[y][x+2] == cellValue)
            //Horizontal streak!
and
1  
if (grid[x][y - 1].equals(center) && grid[x][y + 1].equals(center)) {}

The problem of these codes is that the script works by comboLength >= 3, but if you want the comboLength >= 4, you can't use these scripts.
So the only solution I could think of is a forLoop. By doing that the script gets kinda choatic, and sometimes require more CPU then other times, which result in laggspikes.
Is there no way of finding the streaks within the grid[x.][y]? like:
1  
grid[x][y = 0]{1, 1, 0, 1, 1, 1, 0 , 0}.contains({1, 1, 1}) -> [x=5][y=0]

The above is the psuedocode, but again there is a problem with the variable comboLength, any other ideas how to solve this problem?

-RoseSlayer
15  Game Development / Newbie & Debugging Questions / Re: Check if it's a combo/streak on: 2015-03-05 19:56:11
It is possible to use this function:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
   public Byte grid[][] = new Byte[8][8];
   public Byte gridComboLength[][] = new Byte[8][8];
   public void checkCombo(){
      for(int y = 0; y < gridHeight; y++){
         for(int x = 0; x < gridWidth; x++){
            int ix = x + 1;
            int comboLength = 0;
            boolean checkHorizontalCombo = true;
            while(checkHorizontalCombo && ix < gridWidth){
               if(grid[x][y] == grid[ix][y]){
                  comboLength++;
                  ix++;
               } else
                  break;
            }
            gridComboLength[x][y] = (byte) comboLength;
            x = ix;
         }
      }
   }


But this is only for the horizontals, so I need 2 times this code.

1  
2  
3  
4  
5  
6  
7  
Grid[][]=
{1, 0, 2, 0, 0, 0, 2, 0}
{1, 1, 0, 1, 1, 2, 2, 0}

GridComboLength[][]=
{1, 1, 1, 3, 0, 0, 1, 1}
{2, 0, 1, 2, 0, 2, 0, 1}


So you see that at [3][0] there is a combo of 3 (according to this Grid)
16  Game Development / Newbie & Debugging Questions / Re: Check if it's a combo/streak on: 2015-03-05 19:01:08
You would use a nested for loop.

What have you tried?

Sorry for the limited information given.
I've tried quite alot, but it was done with objects and not tiles.

First Forloop:
Previously I was checking on every Tile, if it's connected to the left, right, top, bottem.
and if it was connected to the right and not the left it was assigned as the start of a (horizontal)combo.
the same goes for top and bottem, if it was connected to the bottem and not top, it was assigned as a start of a (vertical)combo

Second Forloop:
In the second forloop the code is searching for the Tiles that were assigned to a forloop and then create a forloop within to get the length of the combo (which is extremely inefficient).

Third Forloop:
Execute the combo in the Tile.executeCombo(comboLength);

Forth Forloop:
Remove every Tile that was in a combo and create a new Tile in the grid.

But if you can read this, there were so much forloops and extremely inefficient..
The problem I am also experiencing is that I don't know the exact name of that what I am doing, so I cannot google it for any hints/tips..

But long story short I've removed all the Tile classes and I am doing it now with the identities(byte) to create a faster and cleaner function.
Also an offtopic question, are double-dimensional arrays not faster as you can write it in [x.][y] instead of [x+y*gridWidth]?

-RoseSlayer
17  Game Development / Newbie & Debugging Questions / Check if it's a combo/streak on: 2015-03-05 18:41:48
Greetings JGO,

In this application I've created a grid[][] with Bytes in it.

1  
2  
3  
4  
5  
6  
7  
8  
{1, 0, 2, 0, 0, 0, 2, 0}
{1, 1, 0, 1, 1, 2, 2, 0}
{1, 0, 0, 2, 1, 0, 0, 0}
{0, 1, 0, 2, 2, 0, 1, 0}
{2, 0, 1, 2, 1, 0, 2, 2}
{1, 2, 0, 2, 1, 0, 1, 0}
{0, 1, 1, 0, 0, 0, 1, 2}
{0, 0, 0, 0, 1, 0, 2, 0}


A combo/streak is 3 of the same bytes next to each other, for example {1, 1, 1}. This can occur horizontal and vertical.
But the question is, how do I achieve finding all combos/streaks?

If possible, give an example, explained in words, of how it's done, as I am here to learn and not copy codes.

If you have any questions, just say it.
-RoseSlayer
18  Game Development / Newbie & Debugging Questions / Re: Android Rendering platform Chunk tiles. on: 2015-01-28 19:04:56
tiles[x + y*16] The tiles are already stored consecutively

Tile.render():
1  
2  
3  
   public void render(Canvas c, Level level, float x, float y) {
      level.gameView.gfx.renderBitmap(c, bmp, x, y, level.scale, false, false);
   }


Graphics.renderBitmap():
1  
2  
3  
4  
5  
6  
7  
   public void renderBitmap(Canvas c, Bitmap bmp, float x, float y, float scale, boolean centeredX, boolean centeredY){
      Matrix m = new Matrix();
      m.postTranslate((centeredX ? (-bmp.getWidth() / 2) : 0), (centeredY ? (-bmp.getHeight() / 2) : 0));
      m.postScale(scale, scale);
      m.postTranslate((float)x, (float)y);
      c.drawBitmap(bmp, m, null);
   }


chunk.render_tile() isn't used, it was just a simple  Tile.getTile(tiles[x + y*16]).render(canvas, level, x, y);  

But it's true I am performing 32(probably more) multiplications per tile, which is insanly inefficient.
I think the problem is also the way I am getting the Bitmap that correspond with the TileId..

[edit]:
1  
2  
3  
   public static Tile getTile(byte id) {
      return tiles[id];
   }

This are already some iterations less..

[edit 2:]
Found some websites, after a long time searching:
Voxel 3D Chunk management
Topic about chunk management

Greetings,
Roseslayer.
19  Game Development / Newbie & Debugging Questions / Re: Android Rendering platform Chunk tiles. on: 2015-01-28 16:22:55
JRenner, thanks for the reply.

The getTile is pretty straight-forward:
1  
2  
3  
4  
5  
6  
7  
8  
public static Tile getTile(byte id) {
      for(Tile t: tiles){
         if(t.getId() == id){
            return t;
         }
      }
      return null;
   }


And using DDMS, how can you find the location where the CPU is being eaten up?

Greetings,
Roseslayer
20  Game Development / Newbie & Debugging Questions / Android Rendering platform Chunk tiles. on: 2015-01-27 20:12:07
Dear JGO-community,

I've came across a big issue in the devolpment in my game, the rendering of the tiles within the chunks are causing some FPS drops. So really my question is how to render the tiles of the chunk cpu-efficient? I've already tried some solutions but they didn't really fit the job..


What've tried so far:
Code in Chunk.java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public void render(Canvas canvas, Level level){
       for(int x = 0; x < 16; x++){
          for(int y = 0; y < 16; y++){
             if((cx*16+x)*16*level.scale >= level.xOffset - 16*level.scale && (cx*16+x)*16*level.scale <= level.xOffset + level.gameView.width){
                 if((cy*16+y)*16*level.scale >= level.yOffset - 16*level.scale && (cy*16+y)*16*level.scale <= level.yOffset + level.gameView.height){
                    Tile.getTile(tiles[x + y*16]).render(canvas, level, (cx*16 + x)*16*level.scale - level.xOffset, (cy*16 + y)*16*level.scale - level.yOffset);  
                 }
             }
           }
       }
    }

This gave a FPS from 30 to around 20 and was pretty instable, so I rewrote the whole code to something that didn't used that much forloops:

Code in Level.java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public void render(Canvas c) {
      for(int tileX = (int)((xOffset)/scale)/1; tileX < (int)((xOffset + gameView.width)/scale)/16; tileX++){
         for(int tileY = (int)((xOffset)/scale)/1; tileY < (int)((yOffset + gameView.height)/scale)/16; tileY++){
            for(Chunk chunk : chunkListOpen){
               if(chunk.cx == (int)(tileX/16) && chunk.cy == (int)(tileY/16)){
                  chunk.renderTile(c, this, Math.abs(tileX%16), Math.abs(tileY%16));
               }
            }
         }
      }
}

While running this script the FPS was around 3..

chunkListOpen are 3x3 chunks (in which the center chunk is the chunck which the player is located at)

So really the question is how do you render the visible tiles (most times around 20x8tiles) in 9 chunks efficient?
If you have any questions, feel free to ask them.

Edit:
These are all the tiles visible on the screen
      
1  
2  
for(int tileX = (int)((xOffset)/scale)/1; tileX < (int)((xOffset + gameView.width)/scale)/16; tileX++){
         for(int tileY = (int)((xOffset)/scale)/1; tileY < (int)((yOffset + gameView.height)/scale)/16; tileY++){


Greetings,
Roseslayer
21  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
22  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..
23  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...
24  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!
25  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 ._.''
26  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
27  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. ♥
28  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 ..
29  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...
30  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!
Pages: [1] 2 3 ... 5
 
KaiHH (113 views)
2016-01-31 23:15:29

sci4me (140 views)
2016-01-23 21:47:05

sci4me (126 views)
2016-01-23 21:46:58

KaiHH (158 views)
2016-01-19 13:26:42

theagentd (245 views)
2016-01-05 17:10:00

ClaasJG (260 views)
2016-01-03 16:58:36

chrisdalke (251 views)
2015-12-28 06:31:21

Guerra2442 (255 views)
2015-12-25 03:42:55

Guerra2442 (259 views)
2015-12-25 03:27:21

theagentd (288 views)
2015-12-21 14:43:24
List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50

Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48
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!