timed string
instead of editing the source code....u could create a class wich holds a static text and a float number... wich has an update function... decreases the time.. and ehen it gets to 0 it deletes the text... should be fairly easy to implement i think something like this:
class timedString
{
public:
timedString(IrrlichtDevice *Device, c8* string, f32 time)
{
//constructor
//here u store a pointer to the device... or just the gui enviroment
//then you store the time and the string...
//create the static text
}
update( /*u could recibe the time that passed since last update call*/)
{
//here u decrease the time
//if the time is up u destroy the static text
}
private:
IGUIEstaticText * st;
f32 time;
c8 *text;
IrrlichtDevice* device;//this could be the gui env instead of the device
};
thats just a raw idea of how to go about it...
Hope it helps
class timedString
{
public:
timedString(IrrlichtDevice *Device, c8* string, f32 time)
{
//constructor
//here u store a pointer to the device... or just the gui enviroment
//then you store the time and the string...
//create the static text
}
update( /*u could recibe the time that passed since last update call*/)
{
//here u decrease the time
//if the time is up u destroy the static text
}
private:
IGUIEstaticText * st;
f32 time;
c8 *text;
IrrlichtDevice* device;//this could be the gui env instead of the device
};
thats just a raw idea of how to go about it...
Hope it helps
I think I understand...
you could also make the function boolean...
then return false as long as the text is still alive and true when the text was deleted (or the other way around)...
so you can check the return value and if the function returns true you can pass the next string...
but maybe it would be better if you check the lifetime outside the function...
and only if the time has passed you call the function for the next string...
you could also make the function boolean...
then return false as long as the text is still alive and true when the text was deleted (or the other way around)...
so you can check the return value and if the function returns true you can pass the next string...
but maybe it would be better if you check the lifetime outside the function...
and only if the time has passed you call the function for the next string...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
-
- Posts: 89
- Joined: Tue Nov 06, 2007 4:49 pm
my idea to work on the id was right!! now the problem is another... if I create the pointer to the textbox in the main function and i pass it to the write function it seem to don't recognize the other text... it simply overwrite without caring if there was a text behind... i post the source and a rar with the project so you have only to press f9 in dev cpp ;P
if you think that the problem is my modify simply comment the current call (with the pointer to the textbox in the parameters) and uncomment the call to the function with the static textbox... the overloading provide to the rest XD
i think i need a pointer to the textbox pointer but the compiler say:
'remove is not a type' (line 0142)
here is the *.rar:
http://www.demosrv.altervista.org/bfh.rar
here is the code:
thank youuuuu!!!
if you think that the problem is my modify simply comment the current call (with the pointer to the textbox in the parameters) and uncomment the call to the function with the static textbox... the overloading provide to the rest XD
i think i need a pointer to the textbox pointer but the compiler say:
'remove is not a type' (line 0142)
here is the *.rar:
http://www.demosrv.altervista.org/bfh.rar
here is the code:
Code: Select all
#include <irrlicht.h>
#include <iostream>
#include <wchar.h>
#include <windows.h>
#include <stdio.h>
#include <locale.h>
#include <ctype.h>
#include "utils.h"
//\u00E9 => è
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")
int menus(IrrlichtDevice*, IImage*);
void write(IGUIEnvironment*, int, int*, IGUIStaticText*, const wchar_t*, s32*, s32*);
//void stopwrite(IGUIEnvironment*, int, int*, IGUIStaticText*);
void write(IGUIEnvironment*, int, int*, const wchar_t*, s32*, s32*);
int main()
{
scene::ICameraSceneNode* camera=0;
core::vector3df camcord;
scene::IAnimatedMeshSceneNode* nemesis=0;
//scene::IAnimatedMeshSceneNode* throatcutter=0;
scene::ISceneNode* throatcutter = 0;
u32 time = 0;
core::vector3df pos;
IGUIStaticText* txt=0;
s32 lifeTime=0;
s32 oldTime=GetTickCount();
int curid;
wchar_t stringa[][120] = {
L"na stringa",
L"questa è una stringa per verificare il corretto funzionamento dell'algoritmo di centratura del testo...",
L"questa è una stringa per verificare il funzionamento del testo temporizzato"
};
int size=wcslen(stringa[1]),distance=50,winwidth=1024,winheight=768;
printf("lunghezza test: %d\n",size);
IrrlichtDevice* device = createDevice(video::EDT_OPENGL , core::dimension2d<s32>(winwidth,winheight),32, false, true, false);
if (!device) return 1;
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* env = device->getGUIEnvironment();
IGUISkin* skin = env->getSkin();
camera= smgr->addCameraSceneNode();
device->getCursorControl()->setVisible(false);
smgr->addLightSceneNode(NULL, core::vector3df(1200,-100,400), video::SColorf(1.0f,1.0f,1.0f,1.0f),1300.0f);
scene::IAnimatedMeshSceneNode* anms = smgr->addAnimatedMeshSceneNode(smgr->getMesh("model/characters/test/polyik.b3d"));
if (anms)
{
anms->setMaterialTexture(0, driver->getTexture("media/image/textures/test/giuliocesare.jpg"));
anms->setMaterialFlag(video::EMF_LIGHTING, false);
anms->setFrameLoop(0, 24);
}
throatcutter = smgr->addSphereSceneNode();
throatcutter->setPosition(core::vector3df(0,0,30));
throatcutter->setMaterialFlag(video::EMF_LIGHTING, false);
int lastFPS = -1;
curid=0;
while(device->run())
{
u32 time = device->getTimer()->getTime();
write(env,0,&curid,txt,stringa[0],&oldTime,&lifeTime);
write(env,1,&curid,txt,stringa[1],&oldTime,&lifeTime);
write(env,2,&curid,txt,stringa[2],&oldTime,&lifeTime);
/*write(env,0,&curid,stringa[0],&oldTime,&lifeTime);
write(env,1,&curid,stringa[1],&oldTime,&lifeTime);
write(env,2,&curid,stringa[2],&oldTime,&lifeTime);*/
// stopwrite(env,3,&curid,txt);
if (GetAsyncKeyState(VK_UP)) {
pos = anms->getPosition();
pos.Y += 2.0f;
anms->setPosition(pos);
}
if (GetAsyncKeyState(VK_DOWN)) {
pos = anms->getPosition();
pos.Y -= 2.0f;
anms->setPosition(pos);
}
if (GetAsyncKeyState(VK_ESCAPE)) {
if(!menus(device, driver->createScreenShot())) device->closeDevice();
}
if (GetAsyncKeyState(0x57)) distance--;
if (GetAsyncKeyState(0x53)) distance++;
if (GetAsyncKeyState('E')) distance--;
//if (GetAsyncKeyState('S')) distance++;
cameratoobject(camera,anms,distance);
driver->beginScene(true, true, video::SColor(255,113,113,133));
// gravity(anms,9.8);
camcord=camera->getPosition();
camera->setPosition(camcord);
env->drawAll();
smgr->drawAll();
device->getGUIEnvironment()->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw tmp(L"Movement Example - Irrlicht Engine [");
tmp += driver->getName();
tmp += L"] fps: ";
tmp += fps;
device->setWindowCaption(tmp.c_str());
lastFPS = fps;
}
}
device->drop();
return 0;
}
int menus(IrrlichtDevice* device, IImage *sfondo){
video::IVideoDriver* dri = device->getVideoDriver();
video::ITexture *menu = dri->getTexture("media/image/menu/menu.png");
video::ITexture *back = dri->addTexture("back", sfondo);
while(device->run()){
dri->beginScene(true, true, video::SColor(255,113,113,133));
dri->draw2DImage(back,position2d<s32>(0,0),rect<s32>(0,0,1024,768),NULL,video::SColor(255,255,255,255),true);
dri->draw2DImage(menu,position2d<s32>(0,0),rect<s32>(0,0,1024,768),NULL,video::SColor(255,255,255,255),true);
dri->endScene();
if (GetAsyncKeyState('Q')) return 0;
if (GetAsyncKeyState('C')) break;
}
return 1;
}
void write(IGUIEnvironment* env, int id, int* curid, IGUIStaticText* txt, const wchar_t* stringa, s32* oldTime, s32* lifeTime){
if((id==*curid)&&(*lifeTime > 0)){
*lifeTime -= GetTickCount() - *oldTime;
*oldTime = GetTickCount();
return;
}
if((*curid!=id)&&(*lifeTime<=0)){
*curid=id;
if(txt) txt->remove();
*lifeTime = 3000;
int winwidth=1024,winheight=768,xsxmarg=0,xdxmarg=0,ymarg;
core::dimension2d<s32>::dimension2d sxmarg;
IGUISkin* skin = env->getSkin();
IGUIFont* font = env->getFont("media/font/fonthaettenschweiler.bmp");
if (font)
skin->setFont(font);
sxmarg=font->getDimension(stringa);
xsxmarg=(winwidth/2)-(((sxmarg.Width)/2));
xdxmarg=(winwidth/2)+(((sxmarg.Width)/2));
ymarg=(winheight*80)/100;
txt = env->addStaticText(stringa,rect<int>(xsxmarg,ymarg,xdxmarg+3,(ymarg+(sxmarg.Height))), true);
}
return;
}
void write(IGUIEnvironment* env, int id, int* curid, const wchar_t* stringa, s32* oldTime, s32* lifeTime){
static IGUIStaticText* txt;
if((id==*curid)&&(*lifeTime > 0)){
*lifeTime -= GetTickCount() - *oldTime;
*oldTime = GetTickCount();
return;
}
if((*curid!=id)&&(*lifeTime<=0)){
*curid=id;
if(txt) txt->remove();
*lifeTime = 3000;
int winwidth=1024,winheight=768,xsxmarg=0,xdxmarg=0,ymarg;
core::dimension2d<s32>::dimension2d sxmarg;
IGUISkin* skin = env->getSkin();
IGUIFont* font = env->getFont("media/font/fonthaettenschweiler.bmp");
if (font)
skin->setFont(font);
sxmarg=font->getDimension(stringa);
xsxmarg=(winwidth/2)-(((sxmarg.Width)/2));
xdxmarg=(winwidth/2)+(((sxmarg.Width)/2));
ymarg=(winheight*80)/100;
txt = env->addStaticText(stringa,rect<int>(xsxmarg,ymarg,xdxmarg+3,(ymarg+(sxmarg.Height))), true);
}
return;
}
/*void stopwrite(IGUIEnvironment* env, int id, int* curid, IGUIStaticText* txt){
if(txt) txt->remove();
return;
}*/
unfortunately the link doesn't work, so I miss the media files and "utils.h" what gives me errors about the cameratoobject...
but I'll see if I can find the error...
edit: I don't get this error message (remove is not a type) it compiles fine after removing the line with cameratoobject...
but it doesn't delete the old texts, it just puts a new one over the old text...
but I'll see if I can find the error...
edit: I don't get this error message (remove is not a type) it compiles fine after removing the line with cameratoobject...
but it doesn't delete the old texts, it just puts a new one over the old text...
Last edited by Acki on Fri Apr 25, 2008 6:27 pm, edited 1 time in total.
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Remember to initialise your pointers to NULL as your compiler may not do this for you and it may be initialised with a random value and so in your 'write' function your static IGUIStaticText* may have a random value so then if (txt) may return true and cause a crash when you try and reference the invalid pointer
-
- Posts: 89
- Joined: Tue Nov 06, 2007 4:49 pm
void write(IGUIEnvironment* env, int id, int* curid, IGUIStaticText*& txt, const wchar_t* stringa, s32* oldTime, s32* lifeTime, bool* onoff)
look at the prototype and you'll understand
i'm trying to fix the stopwrite function... i create it cause the string get in loop...
the problem it's that don't show the last string... when i fix it i'll post you ASAP!!!
look at the prototype and you'll understand
i'm trying to fix the stopwrite function... i create it cause the string get in loop...
the problem it's that don't show the last string... when i fix it i'll post you ASAP!!!
ok, the error is that you pass the IGUIStaticText pointer but you don't return it, so in your main loop it's still NULL (or 0) !!!
the simplest way is to pass a pointer to the pointer:
prototype:
callings:
function:
the simplest way is to pass a pointer to the pointer:
prototype:
Code: Select all
void write(IGUIEnvironment*, int, int*, IGUIStaticText**, const wchar_t*, s32*, s32*);
Code: Select all
write(env,0,&curid,&txt,stringa[0],&oldTime,&lifeTime);
write(env,1,&curid,&txt,stringa[1],&oldTime,&lifeTime);
write(env,2,&curid,&txt,stringa[2],&oldTime,&lifeTime);
Code: Select all
void write(IGUIEnvironment* env, int id, int* curid, IGUIStaticText** txt, const wchar_t* stringa, s32* oldTime, s32* lifeTime){
if((id==*curid)&&(*lifeTime > 0)){
*lifeTime -= GetTickCount() - *oldTime;
*oldTime = GetTickCount();
return;
}
if((*curid!=id)&&(*lifeTime<=0)){
*curid=id;
if(*txt) (*txt)->remove();
*lifeTime = 3000;
int winwidth=1024,winheight=768,xsxmarg=0,xdxmarg=0,ymarg;
core::dimension2d<s32>::dimension2d sxmarg;
IGUISkin* skin = env->getSkin();
IGUIFont* font = env->getFont("media/font/fonthaettenschweiler.bmp");
if (font)
skin->setFont(font);
sxmarg=font->getDimension(stringa);
xsxmarg=(winwidth/2)-(((sxmarg.Width)/2));
xdxmarg=(winwidth/2)+(((sxmarg.Width)/2));
ymarg=(winheight*80)/100;
*txt = env->addStaticText(stringa,rect<int>(xsxmarg,ymarg,xdxmarg+3,(ymarg+(sxmarg.Height))), true);
}
return;
}
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
-
- Posts: 89
- Joined: Tue Nov 06, 2007 4:49 pm
and the compiler say ERROOOORAcki wrote:ok, the error is that you pass the IGUIStaticText pointer but you don't return it, so in your main loop it's still NULL (or 0) !!!
the simplest way is to pass a pointer to the pointer:
prototype:callings:Code: Select all
void write(IGUIEnvironment*, int, int*, IGUIStaticText**, const wchar_t*, s32*, s32*);
function:Code: Select all
write(env,0,&curid,&txt,stringa[0],&oldTime,&lifeTime); write(env,1,&curid,&txt,stringa[1],&oldTime,&lifeTime); write(env,2,&curid,&txt,stringa[2],&oldTime,&lifeTime);
Code: Select all
void write(IGUIEnvironment* env, int id, int* curid, IGUIStaticText** txt, const wchar_t* stringa, s32* oldTime, s32* lifeTime){ if((id==*curid)&&(*lifeTime > 0)){ *lifeTime -= GetTickCount() - *oldTime; *oldTime = GetTickCount(); return; } if((*curid!=id)&&(*lifeTime<=0)){ *curid=id; if(*txt) (*txt)->remove(); *lifeTime = 3000; int winwidth=1024,winheight=768,xsxmarg=0,xdxmarg=0,ymarg; core::dimension2d<s32>::dimension2d sxmarg; IGUISkin* skin = env->getSkin(); IGUIFont* font = env->getFont("media/font/fonthaettenschweiler.bmp"); if (font) skin->setFont(font); sxmarg=font->getDimension(stringa); xsxmarg=(winwidth/2)-(((sxmarg.Width)/2)); xdxmarg=(winwidth/2)+(((sxmarg.Width)/2)); ymarg=(winheight*80)/100; *txt = env->addStaticText(stringa,rect<int>(xsxmarg,ymarg,xdxmarg+3,(ymarg+(sxmarg.Height))), true); } return; }
in the previous post i want to tell that now work!!
i'm tryin to interrupt the string loop and as soon as possible i post to you the entire project with the write function and the stop write function when the function stopwrite decides to get working XD
(about 2 hours... (i hope))
-
- Posts: 89
- Joined: Tue Nov 06, 2007 4:49 pm
done T.T i'm so happyyyyy
here is the project:
http://www.demosrv.altervista.org/BFH.rar (copy in the address bar... server provider antispam restriction)
let's start with the declaration and the initialization of the variables:
write function:
prototype:
callings:
implementation:
stopwrite function:
pototype:
calling:
implementation:
thanks to everyone who help and heared (read XD) me!!! i hope you'll enjoy this code!!!
here is the project:
http://www.demosrv.altervista.org/BFH.rar (copy in the address bar... server provider antispam restriction)
let's start with the declaration and the initialization of the variables:
Code: Select all
u32 time = 0;
IGUIStaticText* txt=0;
wchar_t stringa[][120] = {
L"na stringa",
L"questa è una stringa per verificare il corretto funzionamento dell'algoritmo di centratura del testo...",
L"questa è una stringa per verificare il funzionamento del testo temporizzato"
};
s32 lifeTime=0, oldTime=GetTickCount();
bool onoff=true;
int curid=-1
}
prototype:
Code: Select all
void write(IGUIEnvironment*, int, int*, IGUIStaticText*&, const wchar_t*, s32*, s32*, bool*);
Code: Select all
write(env,0,&curid,txt,stringa[0],&oldTime,&lifeTime,&onoff);
write(env,1,&curid,txt,stringa[1],&oldTime,&lifeTime,&onoff);
write(env,2,&curid,txt,stringa[2],&oldTime,&lifeTime,&onoff);
Code: Select all
void write(IGUIEnvironment* env, int id, int* curid, IGUIStaticText*& txt, const wchar_t* stringa, s32* oldTime, s32* lifeTime, bool* onoff){
if (!*onoff) return;
if((id==*curid)&&(*lifeTime > 0)){
*lifeTime -= GetTickCount() - *oldTime;
*oldTime = GetTickCount();
return;
}
if((*curid!=id)&&(*lifeTime<=0)){
*curid=id;
if(txt) txt->remove();
*lifeTime = 3000;
int winwidth=1024,winheight=768,xsxmarg=0,xdxmarg=0,ymarg;
core::dimension2d<s32>::dimension2d sxmarg;
IGUISkin* skin = env->getSkin();
IGUIFont* font = env->getFont("media/font/fonthaettenschweiler.bmp");
if (font)
skin->setFont(font);
sxmarg=font->getDimension(stringa);
xsxmarg=(winwidth/2)-(((sxmarg.Width)/2));
xdxmarg=(winwidth/2)+(((sxmarg.Width)/2));
ymarg=(winheight*80)/100;
txt = env->addStaticText(stringa,rect<int>(xsxmarg,ymarg,xdxmarg+3,(ymarg+(sxmarg.Height))), true);
}
return;
}
pototype:
Code: Select all
void stopwrite(IGUIEnvironment*, int, int*, IGUIStaticText*&, s32* lifeTime, bool*);
Code: Select all
stopwrite(env,3,&curid,txt,&lifeTime,&onoff);
Code: Select all
void stopwrite(IGUIEnvironment* env, int id, int* curid, IGUIStaticText*& txt, s32* lifeTime, bool* onoff){
if (!*onoff) return;
if(*lifeTime <= 0){
*onoff=false;
if(txt) txt->remove();
}
return;
}