runAction not excuted when invoked from CCNode (not onEnter ) - cocos2d-x

I have Class that is CCNode extended from one of its methods i want to excute actions
but none of then are running :
from this class :
class GameController : public CCNode
where i have also this:
void GameController::onEnter()
{
CCNode::onEnter();
}
this is the code i have :
bool GameController::removeFinalGems(CCArray* gemsToRemove)
{
onGemScaleInAnim = CCCallFuncND::create(this,
callfuncND_selector(GameController::OnGemScaleInAnim),gemsToRemove);
onRemoveGemScaleInAnim = CCCallFuncND::create(this,
callfuncND_selector(GameController::OnRemoveGemScaleInAnim),gemsToRemove);
CCSequence* selectedGemScaleInAndRemove = CCSequence::create(onGemScaleInAnim,
onRemoveGemScaleInAnim,
NULL);
bool b = this->isRunning();
CCAction *action = this->runAction(selectedGemScaleInAndRemove);
return true;
}
void GameController::OnGemScaleInAnim(CCNode* sender,void* data)
{
CCArray *gemsToRemove = (CCArray*) data;
}
void GameController::OnRemoveGemScaleInAnim(CCNode* sender,void* data)
{
CCArray *gemsToRemove = (CCArray*) data;
}
also i added check to see if there is actions running before and after
and its look like before its equal 0 and after it is equal 1
int na = this->numberOfRunningActions(); //equal 0
CCAction *action = this->runAction(selectedGemScaleInAndRemove);
int na0 = this->numberOfRunningActions();//equal 1 so there is action
it never gets to the OnRemoveGemScaleInAnim and OnGemScaleInAnim methods

I ran into this problem on cocos2d-x when porting an iOS cocos2d app.
After your "runAction" call, add the following line of code to check to see if paused target(s) is the culprit:
CCDirector::sharedDirector()->getActionManager()->resumeTarget( this );
In my case, this was the reason why actions were not being run. It seems that CCTransitionFade's (from screen transitions) resulted in pauses. It might be due to construction of nodes done during init, although I have not tested that theory.

Related

How ro fix "java.lang.AssertionError: expected:<String> but was:<null> "?

I'm trying to test my service and an some point I received an error when I did the assertEquals
This is my test
#Test
public void createNewCommentCreatesNewDTOIfNoDTOExists() {
CommentDTO commentDTO = mock(CommentDTO.class);
MergedScopeKey mergedScopeKey = mock(MergedScopeKey.class);
//set merged scope key
sut.setInput(mergedScopeKey);
String commentText = "commentText";
//define behaviour
when(commentApplicationService.createCommentDTO(mergedScopeKey, commentText)).thenReturn(commentDTO);
sut.createNewComment(commentText);
//test the functionality
assertNotNull(commentDTO);
assertEquals(commentText, commentDTO.getCommentText());
//test the behavior
verify(commentApplicationService).createCommentDTO(mergedScopeKey, commentText);
}
And this is my method that I wanted to test:
protected void createNewComment(String commentText) {
CommentDTO commentDTO = commentApplicationService.getDTOComment(mergedScopeKey);
if (commentDTO == null) {
commentApplicationService.createCommentDTO(mergedScopeKey, commentText);
} else {
updateComment(commentDTO, commentText);
}
}
Do you have any ideas what I do wrong ?
You define behaviour:
when(commentApplicationService.createCommentDTO(mergedScopeKey, commentText)).thenReturn(commentDTO);
But in your test you call:
CommentDTO commentDTO = commentApplicationService.getDTOComment(mergedScopeKey);
This is a different method, you receive null here.
Even if you fix this, you call updateComment. It is highly unlikely that your production code sets expectations on the passed in mock, thus you will always receive null from commentDto.getCommentText()
Consider using a real class instead of a mock for DTO classes.

Init not being called when using ShowViewModel<T> in MVVMCross MvX

i'm seeing some weirdness in my Windows Phone app with MVVMCross.
I use ShowViewModel<MyViewModel>(); to load a new view on a command being executed.
I've changed that to:
ShowViewModel<MyViewModel>(new { First = "Hello", Second = "World", Answer = 42 });
But Init isn't being called in the MyViewModel, MyViewModel inherits from another class that in turn inherits from a MvxViewModel, I've even changed both view models to inherit directly from MvxViewModel.
If i used:
Mvx.Resolve<IMvxViewModelLoader>().LoadViewModel(MvxViewModelRequest<MyViewModel>.GetDefaultRequest(), null);
Init get's called, same for the InitFromBundle, I passed a bundle containing that test object but I didn't get the values passed through.
Init method just looks like this:
public void Init(string First, string Second, int Answer)
I'm totally confused, setup, app.cs all look like the navigation example, any ideas what I might have forgot?
Windows 8.1, VS 2013, Hot Tuna, Windows phone 8.
Init methods:
public void Init()
{
}
public void Init(string First, string Second, int Answer)
{
// use the values
var meh = "";
Mvx.Trace("Init called in {0}", GetType().Name);
}
protected override void InitFromBundle(IMvxBundle bundle)
{
}
You should use ShowViewModel<NameOfViewModelClass>(new { First = "Hello", Second = "World", Answer = 42 }); instead

How to verify Google Play Services

Im trying to figure that out for a few days now, but i can't find some good example about the problem. I think i have founded good code example, but i dont know where/how to use it.
About the problem: whenever app comes from foreground i would like to check if the Google play services are avalable. So for that i want use this code:
static final int REQUEST_CODE_RECOVER_PLAY_SERVICES = 1001;
private boolean checkPlayServices() {
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (status != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
showErrorDialog(status);
} else {
Toast.makeText(this, "This device is not supported.",Toast.LENGTH_LONG).show();
finish();
}
return false;
}
return true;
}
void showErrorDialog(int code) {
GooglePlayServicesUtil.getErrorDialog(code, this,REQUEST_CODE_RECOVER_PLAY_SERVICES).show();
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE_RECOVER_PLAY_SERVICES:
if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Google Play Services must be installed.",Toast.LENGTH_SHORT).show();
finish();
}
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
now i would like to check the services with
if (checkPlayServices()) {
System.out.println("ok");
}
but where? I have tryed to use that code in class that extends the game, but then
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
path cant be found. On the other hand, when i place it in separate activity
public class AuthActivity extends Activity {
//all previous code
}
path is ok. Does someone have any idea how to work that out?
Answer: Because this is Android-specific code, you must use that code in the Android module (containing the Activity class), not in the Core module (containing the class that extends Game).
Reason: If you put that function in the Core module, there is no library dependency of GooglePlayServicesUtil for the Core module, hence you cannot refer to the class GooglePlayServicesUtil. Read more on this link for using Android-specific code.

win8 Frame delegate

I have a frame which has a function that updates the frame when an event in another class is raised.
I have the class 'IRCClient' and 'MainFrame'. The IRCClient class has an event 'OnMessageRecvd', the MainFrame has a function 'HandleNewMessageReceived'. In the MainFrame class I have the variables 'CurrentServer' and 'CurrentChannel' to indicate what channel on what server is currently shown to the user.
Now, when I set the 'CurrentServer' and 'CurrentChannel' in the callback of a button, they have a value and all is fine. However, when the 'HandleNewMessageReceived' function is called by the 'OnMessageRecvd' event of IRCClient, the CurrentServer and CurrentChannel are both equal to any value (null) stated in the constructor of MainFrame.
Does anyone have an idea what the source of this behavior is? Thanks a lot in advance.
EDIT:
Below is the code, I've only posted the code in question (any function that uses the CurrentChannel and CurrentServer properties) and snipped away unrelated code.
// Main page, shows chat history.
public sealed partial class MainPage : LIRC.Common.LayoutAwarePage
{
private uint maxMessages;
IRCClient ircc;
IRCHistory irch;
string CurrentServer, CurrentChannel;
// Does all the setup for this class.
public MainPage()
{
this.InitializeComponent();
ircc = App.ircc; // This is a global variable in the 'App' class.
ircc.OnMessage += NewMessageReceived;
irch = App.irch; // This is also a global variable in the 'App' class.
currentChannel = currentServer = null;
}
// Restores the previous state.
protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
if (pageState != null)
{
if(pageState.ContainsKey("viewedChannel"))
{
// Retrieve required info.
string[] viewedChannelTokens = (pageState["viewedChannel"] as string).Split('.');
CurrentChannel = viewedChannelTokens[0];
CurrentServer = viewedChannelTokens[1];
// If the saved channel or server got corrupt
if (string.IsNullOrEmpty(CurrentChannel) || string.IsNullOrEmpty(CurrentServer))
{
// Check if a channel is open, if so, select it.
*snip* // Non-relevant code.
}
// Clear and load required history.
ClearHistory();
if(CurrentServer != null && CurrentChannel != null)
LoadHistory(CurrentServer, CurrentChannel);
}
}
// Create buttons that switch to a channel
*Snip* // Calls AddChannelButton
}
// Creates a button that, when clicked, causes the ChatHistoryView to display the ChannelHistory.
void AddChannelButton(string Server, string Channel)
{
Button btn = new Button();
btn.Content = Channel + "\n" + Server;
btn.Width = 150;
// A function to switch to another channel.
btn.Click += (e, s) =>
{
ClearHistory(); // Clears the ChatHistoryVi.ew field.
LoadHistory(Server, Channel); // Does the actual loading of the channel history
CurrentChannel = Channel;
CurrentServer = Server;
};
ChannelBar.Children.Add(btn);
}
// The function that is called by the IRCClient.OnMessageRecv event.
public void NewMessageReceived(ref DataWriter dw, IRCServerInfo ircsi, IRCClient.RecvMessage recvmsg)
{
if (ircsi.Name == CurrentServer && CurrentChannel == recvmsg.recipient)
{
AddMessage(DateTimeToTime(DateTime.UtcNow), recvmsg.author, recvmsg.message);
}
}
}
// Responsible for creating, managing and closing connections.
public class IRCClient
{
// A structure that describes a message.
public struct RecvMessage
{
public string author; // Nickname
public string realName;
public string ipAddress;
public string recipient; // Indicates in what channel or private converstion.
public string message; // The actual message
};
// Describes how a function that handles a message should be declared.
public delegate void MessageHandler(ref DataWriter dw, IRCServerInfo ircsi, RecvMessage msg);
// Gets raised/called whenever a message was received.
public event MessageHandler OnMessage;
}
It's not clear what is happening from what you said, but if the variables are set to the values you set in the constructor when you check them - it means that either you have not changed them yet by the time you are expecting them to be changed or you set the value of some other variables instead of the ones you thought you had.
These are only guesses though and you can't expect more than guesses without showing your code.

Is it possible to register an open generic delegate in autofac?

I want to register a generic delegate that resolves itself at runtime, but I cannot find a way to do this on generics.
Given a delegate that looks like this:
public delegate TOutput Pipe<in TInput, out TOutput>(TInput input);
And given a discretely registered delegate that look like this:
public class AnonymousPipe<TInput, TOutput>
{
public Pipe<TInput, TOutput> GetPipe(IContext context)
{...}
I want to register a function along the lines of this:
builder.RegisterGeneric(typeof(Pipe<,>)).As(ctx =>
{
var typeArray = ctx.RequestedType.GetGenericArguments();
// this can be memoized
var pipeDefinition = ctx.Resolve(typeof(AnonymousPipe<,>).MakeGenericType(typeArray));
return pipeDefinition.GetPipe(ctx);
I cannot find a way to provide an implementation of the generic as a parameter in Autofac - I may just be missing something. I know I can do this through a generic object or interface, but I want to stick with the lightness of a delegate. It makes unit testing super simple on the injection of these.
Any thoughts? I am having to do discrete registrations at the moment(one per type combination and no generics).
I can only come up with the registration source solution (the universal hammer in Autofac.)
class PipeSource : IRegistrationSource
{
public bool IsAdapterForIndividualComponents { get { return true; } }
public IEnumerable<IComponentRegistration> RegistrationsFor(
Service service,
Func<Service, IEnumerable<IComponentRegistration>> registrationAccessor)
{
var swt = service as IServiceWithType;
if (swt == null || !swt.ServiceType.IsGenericType)
yield break;
var def = swt.ServiceType.GetGenericTypeDefinition();
if (def != typeof(Pipe<,>))
yield break;
var anonPipeService = swt.ChangeType(
typeof(AnonymousPipe<,>).MakeGenericType(
swt.ServiceType.GetGenericArguments()));
var getPipeMethod = anonPipeService.ServiceType.GetMethod("GetPipe");
foreach (var anonPipeReg in registrationAccessor(anonPipeService))
{
yield return RegistrationBuilder.ForDelegate((c, p) => {
var anon = c.ResolveComponent(anonPipeReg, p);
return getPipeMethod.Invoke(anon, null); })
.As(service)
.Targeting(anonPipeReg)
.CreateRegistration();
}
}
}
Then:
builder.RegisterSource(new PipeSource());
Now, I'm certain that I can't type that code into a web page and have it actually compile and run, but it might come close :)