I am getting warning on this line stating that method actionWithTarget is deprecated.
Can any one tell which alternative method can be used in cocos2dx
CCCallFunc *callBackfunc = CCCallFunc::actionWithTarget(this,
callfunc_selector(GamePlay::startTrumphetAnimation));
Thanks
Try this:
CCCallFunc *func = CCCallFunc::create(this, callfunc_selector(GameOverScene::MyFunction));
//Declare this function also
void GameOverScene::MyFunction(CCObject* sender)
{
}
if you are using new version of Cocos2dx ,
auto funcCallAction = CallFunc::create([=](){
// TODO: do you stuff here
startTrumphetAnimation();
});
runAction(funcCallAction);
Try this
CCCallFunc *calFunc = CCCalFunc::create(this,callfunc_selector(ClassName::methodName));
If you are using cocos2dx v3:
CallFunc *calFunc = CalFunc::create(CC_CALLBACK_1(ClassName::methodName,this));
void ClassName::methodName(Ref* sender)
{
}
write function definition in this way
void GamePlay::startTrumphetAnimation(CCObject* sender)
{
}
If you are using COCOS2DX-3.0 or 3.14v
runAction( CallFunc::create([=]() { startTrumphetAnimation() }));
But you should write this line inside any method of GamePlay Class.
Related
jni.h provide this
struct JNINativeInterface_ {
...
jint (JNICALL *GetVersion)(JNIEnv *env);
...
}
to call it in C can be written as
void test(JNIEnv *env){
// C
jint version = (*env)->GetVersion(env);
// C++
// jint version = env->GetVersion();
}
and then how can I do it in kotlin?
fun test(env: CPointer<JNIEnvVar>){
val version = // how?
}
After searching answer in google there are few example for Kotlin/Native with JNI but they're just basic example please help.
Thanks in advance.
Thanks to Michael.
Long answer is
fun test(env: CPointer<JNIEnvVar>){
// getting "JNINativeInterface_" reference from CPointer<JNIEnvVar> by
val jni:JNINativeInterface_ = env.pointed.pointed!!
// get function reference from JNINativeInterface_
// IntelliJ can help to find existing methods
val func = jni.GetVersion!!
// call a function
var version = func.invoke(env)
// above expression can be simplify as
version = env.pointed.pointed!!.GetVersion!!(env)!!
}
hope this can help somebody to understand
Kotlin/Native 🙂.
I've created myself a helper class called Perm that is meant to return user of current session (I know, I could use default auth/user, but that wouldn't be as much of a fun as creating one from scratch!)
..sadly, the created helper class only works inside a view, but doesn't work at all in controllers.. which kinda misses the point.
Whenever I'm trying to use it inside a controller, it pops:
"Class 'App\Http\Controllers\Perm' not found"
I would most appreciate any help.
HelperServiceProvider.php:
namespace App\Providers;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class HelperServiceProvider extends ServiceProvider
{
public function boot()
{
//
}
public function register()
{
foreach( glob (app_path().'/Helpers/*.php' ) as $filename ) // register all helpers
{
require_once($filename);
}
}
}
Helpers/PermHelper.php:
use App\User;
class Perm
{
public static function user()
{
if(!session('user_id')) return null;
return User::find(session('user_id'));
}
}
Portion of config/app.php, the 'providers' array:
// Custom
App\Providers\HelperServiceProvider::class,
If you are having this issue aswell.
Use proper namespacing.
I am trying to learn TypeScript, and need some advice on implementing generic collection types. I put the dictionary and HashSet in another question, here I'd like any advice on my list type.
Especially the ForEach-Operation looks a bit strange. I think I found it in another question here, and "improved" by returning true or false to give feedback if the iteration was stopped early or completed.
import { IForEachFunction } from "./IForEachFunction"
export class List<T> {
private _items: Array<T>;
public constructor() {
this._items = [];
}
public get Count(): number {
return this._items.length;
}
public Item(index: number): T {
return this._items[index];
}
public Add(value: T): void {
this._items.push(value);
}
public RemoveAt(index: number): void {
this._items.splice(index, 1);
}
public Remove(value: T): void {
let index = this._items.indexOf(value);
this.RemoveAt(index);
}
public ForEach(callback: IForEachFunction<T>): boolean {
for (const element of this._items) {
if (callback(element) === false) {
return false;
}
}
return true;
}
}
The ForEach-Iteration relies on an interface from another file:
export interface IForEachFunction<T> {
(callback: T): boolean | void;
}
You would use my list and the ForEach-Method like this:
let myList: List<a_type> = new List<a_type>();
let completed: boolean = myList.ForEach(xyz => {
// do something with xyz
return false; // aborts the iteration
return true; // continues with the next element
});
if (completed) // we can see what happened "during" the iteration
I think this is not bad, but I'd appreciate any input. I am not sure if I use the === correctly.
Another question which I really like to know: How could I define a function with the interface IForEachFunction? I do not really "re-use" that interface visibly, I always declare an anonymous method as shown above. If I wanted to call a method having the interface definition, is that possible?
Thanks!
Ralf
One problem I see is that you have an interface instance:
callback: IForEachFunction<T>
This contains a method called
callback()
But you only call callback once. You would have call callback() method inside your interface:
callback.callback()
Also your code looks like it is inspired by C# or Java. In TypeScript you would often just use an array. This simplifies certain code constructs.
Here is my main class which I want to test. It contains one private method.
Public class MyClass
{
private bool IsWorkDone(MyItem item, string name)
{
using (MyThing thingObj = new MyThing(item.ID))
{
using (MyWork workObj = thingObj.Open())
{
try
{
return false;
}
}
}
return true;
}
}
In my test class I have written below method
public void CheckIsWorkDoneTest()
{
using (ShimsContext.Create())
{
MyItem myitem = new ShimMyItem () {
itemGet = () => new ShimMyItem () {
IDGet = () => new Guid();
}
};
ShimMyClass.AllInstances.isWorkDoneItemString = (MyClass, MyItem, MyName) => "Here I'm stuck. I need help from stackoverflow users"
PrivateObject objMyClass = new PrivateObject(typeof(MyClass));
object[] parameters = new object[2] { myItem, workName };
bool result = Convert.ToBoolean(objMyClass.Invoke("IsWorkDone", parameters));
Assert.AreEqual(result,true);
}
}
I want to set the value for oSite object from statement => "using (MyThing thingObj = new MyThing(item.ID)) " from my main MyClass Class.
while debugging this line throws Object reference not set to an instance error.
So using ShimMyClass.Allinstance how can I get or set the value for it?
You have quite a few inconsistencies, so your problem is probably just straitening them out. If you're actual code is more consistent, then update your post. The main things
You show private method IsComplete but call isWorkflowCompleted from your Invoke method
You probably end up calling your shimmed method that will pass "Here I'm stuck" and try to convert that string to a Boolean.
I fudged your skeleton and got mine to work after adjusting some of the names.
I want to call a method thrice with different parameters and need to have some delay between calling them,inorder to this i want to use CCCallFuncND,but i unable to implement it in my code, please help me do that by giving a simple example of how to call CCCallFuncND.
My Code is :
this.runAction(CCCallFuncND.action(this, "shift_sec", "1"));
public void shift_sec(String v) {
System.out.println("Coming into this method. : "+v);
}
I will illustrate with example:
CCCallFuncND.action(this, "hitCallback", data)
here
this--> is target i.e sender
"hitCallback"-------> is the string which being called.
data -----------> is an object to be send
public void hitCallback(Object sender,Object data){
CCSprite hitSpotSprite = (CCSprite)data;
hitSpotSprite.removeFromParentAndCleanup(true);
hitSpotSprite = null;
}
in your case
shift_sec(String v){} being modified to
shift_sec(Object sender,Object data){}