well i tried to write my own class and it looks like this:
call from inside a custom class:
Code: Select all
glow = new CSceneNodeAnimatorTextureII(textures,60, false, timer->getTime());
(glow is predfined in the header file of the custom class):
Code: Select all
#include "../CSceneNodeAnimatorTextureII.h"
//---some code---
scene::ISceneNodeAnimator* glow;
CSceneNodeAnimatorTextureII.h :
Code: Select all
// Copyright (C) 2002-2005 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_SCENE_NODE_ANIMATOR_TEXTUREII_H_INCLUDED__
#define __C_SCENE_NODE_ANIMATOR_TEXTUREII_H_INCLUDED__
#include <irrlicht.h>
#include "irrArray.h"
#include "ISceneNode.h"
#include "ISceneNodeAnimatorFinishingII.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
class CSceneNodeAnimatorTextureII : public ISceneNodeAnimatorFinishingII
{
public:
//! constructor
CSceneNodeAnimatorTextureII(const core::array<video::ITexture*>& textures,
s32 timePerFrame, bool loop, u32 now);
//! destructor
virtual ~CSceneNodeAnimatorTextureII();
//! animates a scene node
virtual void animateNode(ISceneNode* node, u32 timeMs);
//! Writes attributes of the scene node animator.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const;
//! Reads attributes of the scene node animator.
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0);
//! Returns type of the scene node animator
virtual ESCENE_NODE_ANIMATOR_TYPE getType() const { return ESNAT_TEXTURE; }
//! Creates a clone of this animator.
/** Please note that you will have to drop
(IReferenceCounted::drop()) the returned pointer after calling
this. */
virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0);
virtual void resetAnimation();
private:
void clearTextures();
core::array<video::ITexture*> Textures;
u32 TimePerFrame;
u32 StartTime;
bool Loop;
};
#endif
ISceneNodeAnimatorFinishingII.h:
Code: Select all
// Copyright (C) 2002-2008 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __I_SCENE_NODE_ANIMATOR_FINISHING_H_INCLUDED__
#define __I_SCENE_NODE_ANIMATOR_FINISHING_H_INCLUDED__
#include "ISceneNode.h"
namespace irr
{
namespace scene
{
//! This is an abstract base class for animators that have a discrete end time.
class ISceneNodeAnimatorFinishingII : public ISceneNodeAnimator
{
public:
//! constructor
ISceneNodeAnimatorFinishingII(u32 finishTime) : FinishTime(finishTime), HasFinished(false) { }
virtual bool hasFinished(void) const { return HasFinished; }
protected:
u32 FinishTime;
bool HasFinished;
};
} // end namespace scene
} // end namespace irr
#endif
CSceneNodeAnimatorTextureII.cpp :
Code: Select all
// Copyright (C) 2002-2005 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CSceneNodeAnimatorTextureII.h"
#include "ITexture.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
//! constructor
CSceneNodeAnimatorTextureII::CSceneNodeAnimatorTextureII(const core::array<video::ITexture*>& textures,
s32 timePerFrame, bool loop, u32 now) : ISceneNodeAnimatorFinishingII(0),
TimePerFrame(timePerFrame), StartTime(now), Loop(loop)
{
#ifdef _DEBUG
setDebugName("CSceneNodeAnimatorTextureII");
#endif
for (u32 i=0; i<textures.size(); ++i)
{
if (textures[i])
textures[i]->grab();
Textures.push_back(textures[i]);
}
FinishTime = now + (timePerFrame * Textures.size());
}
//! destructor
CSceneNodeAnimatorTextureII::~CSceneNodeAnimatorTextureII()
{
clearTextures();
}
void CSceneNodeAnimatorTextureII::clearTextures()
{
for (u32 i=0; i<Textures.size(); ++i)
if (Textures[i])
Textures[i]->drop();
}
//! animates a scene node
void CSceneNodeAnimatorTextureII::animateNode(ISceneNode* node, u32 timeMs)
{
if(!node)
return;
if (Textures.size())
{
const u32 t = (timeMs-StartTime);
u32 idx = 0;
if (!Loop && timeMs >= FinishTime)
{
idx = Textures.size() - 1;
HasFinished = true;
}
else
{
idx = (t/TimePerFrame) % Textures.size();
}
if (idx < Textures.size())
node->setMaterialTexture(0, Textures[idx]);
}
}
//! Writes attributes of the scene node animator.
void CSceneNodeAnimatorTextureII::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{
out->addInt("TimePerFrame", TimePerFrame);
out->addBool("Loop", Loop);
// add one texture in addition when serializing for editors
// to make it easier to add textures quickly
u32 count = Textures.size();
if ( options && (options->Flags & io::EARWF_FOR_EDITOR))
count += 1;
for (u32 i=0; i<count; ++i)
{
core::stringc tname = "Texture";
tname += (int)(i+1);
out->addTexture(tname.c_str(), i<Textures.size() ? Textures[i] : 0);
}
}
//! Reads attributes of the scene node animator.
void CSceneNodeAnimatorTextureII::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{
TimePerFrame = in->getAttributeAsInt("TimePerFrame");
Loop = in->getAttributeAsBool("Loop");
clearTextures();
for(u32 i=1; true; ++i)
{
core::stringc tname = "Texture";
tname += (int)i;
if (in->existsAttribute(tname.c_str()))
{
video::ITexture* tex = in->getAttributeAsTexture(tname.c_str());
if (tex)
{
tex->grab();
Textures.push_back(tex);
}
}
else
break;
}
}
ISceneNodeAnimator* CSceneNodeAnimatorTextureII::createClone(ISceneNode* node, ISceneManager* newManager)
{
CSceneNodeAnimatorTextureII * newAnimator =
new CSceneNodeAnimatorTextureII(Textures, TimePerFrame, Loop, StartTime);
return newAnimator;
}
void CSceneNodeAnimatorTextureII::resetAnimation()
{
irr::ITimer* timer;
StartTime = timer->getTime();
FinishTime = StartTime + (TimePerFrame * Textures.size());
}
as expected i receive an segmentation fault here when try to debug
do i have any other option to start playing an TexturAnimator(explosion) from the first image when a weapon node(laserBeam) hits a target?
because the TextureAnimator plays when:
loop == false:
starts once and finishes when all images in texture array have played once, starttime and depending on it finishing time is calculated once, also the serialze Attributes function does not fit any option to change this, even if it would IAtributes.h has no addU32 only an addInt
loop == true : also StartTime is calculated once No option to reset it at... it just plays in loop.
so what if i have syme player types just different weapons one wich is a bit faster, i could make the timePerFrame dynamic, would result in an explosion playing faster and look not realistic.
hmm can someone give me an option please or help me on the SIGSEGV (segmentation fault)?