| Reply | « Previous Thread | Next Thread » |
|
Hi,
I am struggling to retrieve what kind of Class a specific Layer is as used in the LayerManager API... You can add Sprites to a LayerManager which become instances of Layer... Let's say I've got 3 custom Sprite derivates, classes Apple, Pear and Banana... Lets say I add 3 Apples, 2, Pears and one Banana to the LayerManager... How do I recognize a Pear object afterwards ? Lets say I want to remove only the Pear elements, how can that be achieved ? Thanks in advance |
|
Tut... you know this! Sprites don't become instances of Layer... they already are (Sprite extends Layer). You can tell what specific type a Layer is, by using instanceof.
PHP Code:
PHP Code:
Cheers, Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
hehe,
thx Graham, it seems to work... I was trying something a little too complex, my algorithm had one extra step in which instead of checking the retreived Layer to the needed class I first extracted the Object from the Layer and then did an instance of check, which actually didnt work :( btw great if-else loop, already taking into account that if a Layer is removed the indexes within the layermanager decrease by one and thus no i++ ;) another way (which I used till now) was the opposite, starting out at the end of the Layers stack (highest index) and working downwards... anyways thx graham, as always u have been of great help :D "Tut... you know this!".... ehhrmm... yeah I knew that, was just a momentary lapse of reason :P or the lack of that :D |
|
Quote:
PHP Code:
Cheers, Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
hehe well if we have to start tweaking and optimizing I would declare Layer layer outside the loop,so that it gets reutilized instead of creating a new Object every time :
PHP Code:
U know how Pears are, they are pretty complex fruits ;) they come in different sizes, colors, countries, wights and so forth, and not to forget they come in bunch :P So like this I might be saving some memory by not instanciating a Layer object every time :P hehe btw I dont know what u were thinking about when u typed this Quote:
|
|
Again, tut! :) That's just a declaration, it doesn't allocate memory or run any code.
What it does do, is tell the compiler to allocate a slot in the stack-frame for the variable. Since that slot only needs to be reserved for the scope of the variable (it's enclosing {...}), nesting the declaration as deep as possible keeps the scope small, and allows the compiler to re-use the stack-frame slot for another local variable later. PHP Code:
More significantly, you could also be preventing an object from becoming garbage, by keeping a reference to it in a variable you no longer want. By letting the variable fall out of scope, you increase the chances of the garbage collector will notice that the object is unreferenced, and release the memory. So, as a rule, keep the declaration as close to the use as possible. Someone called you that in another post... you were amused, but I think you secretly like it... :P |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
hhmmm,
ok, thanks for the insight, that about the slots I didn't know actually... well thats another lesson, still enough to learn, and it's good to have people in this forum which can give such extended information regarding not only the devices but Java specifically as a language... |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Layer ads break browsing | nokiameister | General Browsing | 0 | 2007-06-11 12:39 |
| graphic layer over a video layer | ninku6a | Symbian Media (Graphics & Sounds) | 0 | 2006-02-21 14:38 |
| graphic layer over a video layer | ninku6a | Mobile Java Media (Graphics & Sounds) | 0 | 2006-02-21 14:37 |
| ::: How much tiled layers on Nokias60? (speed Q) ::: | alex_raider | Mobile Java Media (Graphics & Sounds) | 0 | 2005-12-09 19:26 |
| MMS (WAP) Layer description | Potappel | General Messaging | 0 | 2003-10-23 10:22 |