LibGDX group within group - libgdx

Is it possible to add a group to a group. I did that a while ago and it wasn't working at all. I wasn't sure what the reason was, so I did a workaround.
Now I think it would be way easier to do it the first way.
Group group = new Group();
Group otherGroup = new Group();
group.addActor(otherGroup);
This should work, right?

So I figured out what was wrong:
I did override the draw method in "group", and I guess you have to call the draw methods of the children manually because once I removed the draw method in "group" everything worked fine...
The same thing applies to the act(delta) method.
All I had to do is call super.draw() and super.act() in the Group "group", now everything works fine.

Related

WebdriverIO waitfor methods don't work as expected

I am working on a set of webdriverIO tests that use a lot of pauses. To make the framework more robust I want to get rid of the pauses and introduce waitfor statements
I have looked through some walkthroughs, and most of them suggest something in the line of this:
var decrease = browser.$("//*[#id='somebutton");
decrease.waitForExist(5000)
decrease.click()
This doesn't work in 90% of the times however, returning the error message:
An element could not be located on the page using the given search parameters ("//*[#id='somebutton'"). (pretty much the same message I get when I remove the wait altogether)
I have tried both waitForExist and waitForVisible without success
I have played around a but, and found out that the following way does work:
browser.$("//*[#id='somebutton").waitForVisible(5000);
browser.$("//*[#id='somebutton").click()
I am not fond of this solution though, because it requires replication of the locator, which will make support harder in the future.
Can anyone shed some light on why the first option might not be working for me?
This should do the trick:
var selector = "//*[#id='somebutton";
browser.waitForExist(selector, 5000);
browser.click(selector);
Also, an example in the api docs shows it being done like this. Notice they left off the browser. portion.
var notification = $('.notification');
notification.waitForExist(5000);
Perhaps that is your issue? Both ways should work though.
One last thing, you don't have to use the xpath for this element if you don't absolutely have to. It's easier to just use the css selector for id.
var decrease = $('#somebutton');

AS3: Loader all on one line?

I'm used to seeing the Loader class used like this:
var loader:Loader = new Loader();
loader.loadBytes(myByteArray);
addChild(loader);
But then I came across some code where it's all done on one line:
Loader(addChild(new Loader())).loadBytes(myByteArray);
What's the difference between the two? Is one way better than the other? Can someone explain what exactly is going on in the second version?
There is barely any difference, and the first version is "better" because it's actually readable.
To break it down:
Loader(addChild(new Loader())).loadBytes(myByteArray);
We cast something as an Object of the type Loader : Loader(...)
Then we add a DisplayObject to the current displaylist with addChild, which will return the DisplayObject we have added (so that we actually have something that we can cast to something else).
The DisplayObject in question is a Loader Object, and we create a new one for this.
So, Loader(addChild(new Loader())) creates a new Loader object and adds it to the displaylist. But this is still kind of useless, because a Loader needs to, well, load something, right? This is the reason why we cast the whole DisplayObject into a Loader in the first place, so that we can use its methods, such as loadBytes(bytearray). If you wouldn't put the whole thing into a Loader(...) cast, you wouldn't have access to these methods, because addChild will only return an object of the DisplayObject type, and not Loader.
To sum it up, this has no effect on performance whatsoever, it's just a shorter writing style for the same goal. If you're the only one who will see this code in your projects, it's fine. If not, consider that other people should be able to read the code as well, without having to break it down step for step.

Actionscript 3 problems with "Call to a possibly undefined method"

Thanks partly to info from people here, I'm getting more comfortable with Actionscript 3, but I've got a problem that is very puzzling.
The program (done entirely in AS3, no Flash) has several different screens. One does music and it's working very well. Another does video. Obviously when somebody goes from music to video we need to make sure the music is turned off. There is a Main screen that handles going from one to the other.
I started out doing it this way, and the reason I got "Call to a possibly undefined method" is obvious. The following is in the Main class, with the "private var" part inside the class but external to the functions and the "music = new MusicPanel" part in one of the functions:
private var music:MusicPanel;
music = new MusicPanel(trackNames.songNames, trackNames.numSongs);
When switching to the video panel, I added a public function in MusicPanel called StopMusic and called it when the user went to the video panel:
if(music != null)
music.StopMusic();
That got the error:
Call to a possibly undefined method StopMusic
I was checking to make sure music was not null, but that error didn't seem like a bad thing. So I changed the code to:
private var music:MusicPanel = new MusicPanel();
and added a function that would get the song names and number of songs to the music class. That did not help- I got the same error, and in fact the function that tried to put the song names and number of songs got the error also.
At the same time, the Video panel does not give me that error, even though I have laid it out in exactly the same way.
private var video:VideoPanel = new VideoPanel;
video.PlayVideo();
I do a fair amount of setup on the music screen when it gets called as a new class, I do less setup for the video screen. I'm not sure if that makes a difference.
Clearly there is something I don't understand here. Anybody got any idea what's going on? I've looked at a number of questions about this, but have not found an answer. I think I'm doing this right, but the compiler thinks I'm doing it wrong, so I must be doing it wrong.
Later Note: One answer mentioned the difference between Sprite and MovieClip. I gave that a try, changing to MovieClip does not help, and the VideoPanel, which works, extends Sprite.
What is the base class of MusicPanel, Sprite or MovieClip? If Sprite, change to MovieClip and see what that does. In AS3 Sprites are not dynamic, so can't take properties that are not inherent in the class.
It appears that the problem is coming either from Actionscript 3 or from FlashDevelop. I built a new module (SongsPanel) which is very close to the same as the original MusicPanel. It works. If I add a public function in MusicPanel the compiler comes back with the same error. If I add a public function in SongsPanel everything works.
Does FlashDevelop keep track of errors in some hidden file? I'm guessing that's what's going on, and that there is a bug in the way that is done.
PITA!- but at least it now works.

Actionscript 3: apply property to all vars or MovieClips

I want to know if it's possible, and if so how, to apply a property of a var to multiple vars at once. I'm making a point-n-click game where i want to apply the buttonMode property to multiple variables (of MovieClips).
I don't know if this is even possible or how simple or advanced this is, but it would be damn handy.
I have searched on Google and this site for a possible answer, with different search terms/keywords, but can't find anything close. I also tried different things with an asterisk such as *.buttonMode = true and movieClip.*.buttonMode = true but no success.
Any help would be very much appreciated.
All you really need to do is bind a specific property of all these movieclips to a bindable variable.
For more information on bindable variables visit :
1. http://www.flexafterdark.com/docs/ActionScript-Bindable
2. http://jacwright.com/blog/54/actionscript-3-bindable-dynamic-objects/
Bindables come in handy whenver you want many objects to refer to a property , and on the change of this property, some property in the object(s) which have binded to this bindable variable will change.

Which coding style is more common?

In no way shape or form am i advertising/promoting my programming style, but as far as 'multiple variable declarations' are concerned, which case is more acceptable professionally and commonly:
case 1:
private $databaseURL = "localhost" ;
private $databaseUName = "root" ;
private $databasePWord = "" ;
private $databaseName = "AirAlliance";
case 2:
private $databaseURL = "localhost";
private $databaseUName = "root";
private $databasePWord = "";
private $databaseName = "AirAlliance";
The reason i like case 1 is because i can skim though it and see that all is correct way faster than case 2. Also i can visually get familiar with variable names witch makes it faster to work with them l latter on the program.
Whichever style the project is already using, so you don't end up spending all day fixing every file you touch.
case 1.5:
private $databaseURL = "localhost";
private $databaseUName = "root";
private $databasePWord = "";
private $databaseName = "AirAlliance";
I don't think aligning the semicolons makes it any more readable, it just makes it annoying to change the value of one of the strings and then have to add or delete spaces to line up the semicolons all over again.
In this case, it looks like the variable names are unlikely to change, so it should be OK to line up the equals signs. If it were possible that the variable names would change, however, I would go with case 2 because (again) it would be annoying to have to line everything up again. (Imagine the work involved in simply adding a new variable called $databaseLongVariableName.)
Case 2. When you add a new variable to your "group", or add/remove a character on one of those lines, you won't have to spend time fiddling around trying to make things line up.
If you change all their alignments when you add a new variable, then any diff tool will show up multiple changes there. Just a thought.
Also, I've done this once. It became a pain in the ass when I had to add a variable that was longer. Padding out all the existing ones with spaces to match turned me off this technique.
Interesting question. As far as I'm concerned, there's no good reason to use case 1. I've never seen that style before, except possibly in config files, and it costs extra time to format your code properly. As soon as you change the contents of the variable, you have to reset your semi-colon as well.
It only works if you use spaces as well... anyone using tabs might have different tab stops set, so it will look completely different opened in another editor.
I think the advantage of readability you mention is somewhat offset by the extra effort required to write it.
It's very tempting to nicely align stuff, I used to align my accessors in PHP as so
function getName() { return $this->name; }
function getAge() { return $this->age; }
function getHeight(){ return $this->height; }
The problem comes when you add in a longer line:
function getName() { return $this->name; }
function getAge() { return $this->age; }
function getNiNumber(){ return $this->ni_number; }
function getHeight(){ return $this->height; }
If I edit the three other lines, then when I commit my change it makes it harder to see who wrote a particular line, and in which revision they did it.
Aligning stuff like = and ; just invites a whole big mess of tab-space screw ups that get checked in, then have to be fixed later.
Most people will use tabs to the left of a line for indentation, then use spaces to align stuff to the right.
Beyond adding bloat to files, it just becomes a big, inconsistent soupy mess. To me, it does not make the code any more readable. To some editors, it makes the code even less readable.
Use case 2. That is far more standard: Google C++ Style
Really you shouldn't even concern yourself with this. Your editor should automatically autoformat your code. Try ctrl+shift+F in Eclipse.
Aligning the semicolons seems like wasted time to me, unless your IDE/text editor can do it for you. Especially if you later add another entry longer than the previous ones; you'll have to realign all of them.
I just fired up my editor and it just hit me. all the reasons i like case 1 for are in syntax highlighting without wasting time.
case 2. with anything else your version control will go crazy everytime you re-adjust the spacing. besides with IDEs that has highlighting and some also show a variable listing, its really a waste of time to align '=' and ';' in my opinion.
Case 2. If I leave out a semicolon, I have a program that tells me so. It's the compiler.
Going with what ever the project you are working on is the best option. (If the project doesn't have a set of coding guidelines, spending five minutes to define them is highly recommended).
A lot of the larger programs have tools which scan the code looking for things to sort and clean. Adding whitespace at the end of the variable could affect some of them.
Also regarding tabs, I've never worked on a project that didn't determine the tab spacing for the editing. You can always use your personal one and have a precommit hook to edit the file before it goes in, but messing with tab spacing will annoy people no end.
You can have a look at the book "Expert PHP 5 Tools" for better understanding the code styling in more detail way.
*There is e-book in net *