Setting a Custom Background

edited May 2012 in Help request
How exactly would I set up a custom background for my project. As in, a .png file as my background? I've done some testing and it hasn't worked so I'm not really sure how to do it. :)

Comments

  • edited May 2012
    You can do that by creating an object that you attach to your camera, as far as possible from it but still in its frustum.

    Here's a config example:
    [MyBackgroundGraphic]
    Texture = path/to/texture
    Pivot = center
    
    [MyBackground]
    Graphic = MyBackgroundGraphic
    ParentCamera = MyCamera
    UseParentSpace = both; Use the parent space to define both scale and position
    Scale = 1; Makes sure the background is scaled to exactly cover the camera size
    Position = (0, 0, 1); Put it as far from the camera as possible but still visible
    
  • edited May 2012
    Ok, thanks! Do I need to declare anything in a C/C++ file?
  • edited May 2012
    It's an object like any other so you need to create it! :)

    Either as a child of another object through the ChildList property or simply in code with orxObject_CreateFromConfig("MyBackground");
  • edited May 2012
    [strike]I tried it and I just get a black background. Everything works perfectly but I only have a black colored background.[/strike]

    Nevermind. :-)
  • edited May 2012
    Out of curiosity, what was the issue? :)
    (Can be helpful to someone having a similar problem later on.)
  • edited May 2012
    I think it was that I named the things in the [] differently. Like one was MyBackgroundGraphic and one was Galaxy. Then instead of the correct background image it was just a black background. I'm pretty sure that was the problem.
  • edited May 2012
    Ah ok, in that case you should have an error message in the log when running in debug mode.
  • edited May 2012
    Yes, I did. I was wondering, I've been editing Grey's tutorials lately to see what I can do and I was thinking about getting boxes to spawn randomly. How would I do that?
  • edited May 2012
    It depends what you mean by randomly. Random location or random timing?
  • edited May 2012
    Both if possible, but mostly timing. :)
  • edited May 2012
    For config attributes, read the top comments in the CreationTemplate.ini file, it'll tell you how to use ~ or # in order to get random values.

    For delaying and create things randomly over time, it's just code logic, not really something related to orx. :)

    You can either set a variable with a random amount of time to wait, decrement it with the frame DT and when it is less than or equal to 0 you spawn a new object and reinit that variable with a random delay.
    You can also use orxClock_AddTimer() if you don't want to handle the delay manually.
  • edited May 2012
    Where can I find the CreationTemplate.ini file?
  • edited May 2012
    code/bin

    It's also explained here: http://orx-project.org/wiki/en/orx/config/syntax
  • edited May 2012
    I'm trying to use a random float value to spawn a box. I used

    orxFLOAT fSpawnFloat = orxConfig_GetFloat("SpawnFloat");

    and I have it declared in my .ini file, however I'm not sure what to do after that. I was thinking about creating an if statement so that whenever SpawnFloat == 1 a box is spawned. But I'm not sure what to call SpawnFloat in the if statement, as SpawnFloat doesn't work.

    CODE:
    EDIT: Ok, I got that to work by doing this:
    if(orxFLOAT fSpawnFloat = 1)
    		orxBOOL bSpawnBox = true;
    

    But when I run it I trigger a breakpoint and these messages appear.
    FirstProject_d.exe has triggered a breakpoint
    
    Unhandled exception at 0x1001a03e (orxd.dll) in FirstProject_d.exe: 0xC0000005: Access violation reading location 0x00000020.
    

    Oh, and here's the code from the .ini file too. :)
    [PhysicsInput@SoldierInput] ;=================
    SpawnBox               = false
    SpawnFloat			 = 1 ~ 25
    

    Darn it! I even tried getting rid of SpawnFloat and using a for statement and that didn't work either.
    for(int Timer = 70; Timer > 2; Timer--)
    	{
    		orxBOOL bSpawnBox = true;
    	}
    
  • edited May 2012
    You should get rid of bSpawnBox, and not make PhysicsInput based on SoldierInput.

    In your .ini :
    [PhysicsInput]
    SpawnU32  = 1 ~ 25
    

    In your code
    orxConfig_SelectSection("PhysicsInput");
    orxU32 SpawnU32 = orxConfig_GetU32("SpawnU32");
    orxU32 i;
    
    for(i = 0; i < SpawnU32; i++)
    {
    	orxObject_CreateFromConfig("Objectyouwant");
    }
    

    Your loop isn't related to a clock, it just sets bSpawnBox to true 68 times for the same object. There's also tutorial on spawners if you want to create objects over time. The executable is in trunk/tutorial/bin.
  • edited May 2012
    Thanks Grumly, it worked! Is it possible for me to make SpawnU32 a float value? I think the boxes are spawning a little too fast. :)

    Sorry, I tend to post before I think, I figured it out, woops. :P
  • edited May 2012
    They're all spawning during the same frame, the u32 parameter tells how many objects are created not the delay. If you want to add delay you have to use the clock. Try the clock tutorial or the spawners one for something automatic.
  • edited May 2012
    ChaoticCactus wrote:
    if(orxFLOAT fSpawnFloat = 1)
    		orxBOOL bSpawnBox = true;
    

    Just some precisions but here it's not doing what you think it is doing.

    You declare a variable inside the if statement, this variable will be limited to the scope of the if (not availabe outside).
    Then you set its value to one and that's what is going to be tested, which means this test will always be true.
    Lastly, you didn't put any curly braces after the if so only 1 line of code is conditional to the result of the if, and that line is the declaration of the bSpawnBox variable, set to true, and not accessible later on.

    So basically, the whole code isn't doing anything that will have any impact at all on anything else and will probably be completely removed by the compiler in an optimization pass (ie. non-debug).
    But when I run it I trigger a breakpoint and these messages appear.
    FirstProject_d.exe has triggered a breakpoint
    Unhandled exception at 0x1001a03e (orxd.dll) in FirstProject_d.exe: 0xC0000005: Access violation reading location 0x00000020.
    

    That probably means you've dereferenced a pointer which value was 0x20 (32). That's definitely not a valid memory address, hence the access violation.

    As Grumly suggested, spawners are probably a good bet if you need to time creation of objects. The new timeline module can also be used for that, but I wouldn't try it till you get more familiar with C++ code and orx. :)
  • edited June 2012
    Ok, thank you Iarwain, one last question! :) How exactly do I declare

    [code]

    orxDLLAPI orxBOOL orxFASTCALL orxKeyboard_IsKeyPressed(orxKEYBOARD_KEY_LEFT)
    [/code]

    I tried it and it's underlined in red and says that the constant orxKEYBOARD_KEY_LEFT is not a type name. How do I fix that?

    Again, I'm sorry for having SO many questions. =","BBCode
  • edited June 2012
    No worries! :)

    Mmh, what are you trying to do exactly? I have to admit I'm not sure...

    Here in the facts you're re-declaring a function of orx. A re-declaration of functions is not something allowed in C/C++.

    In your redeclaration you don't specify a type for the first argument of the function, that's why the compiler is trying to interpret orxKEYBOARD_KEY_LEFT as a type (like orxU32, orxFLOAT, etc...), which doesn't make much sense and he's letting you know about it. :)
  • edited June 2012
    I was actually thinking about using it to move the character on the screen.

    Ok, that makes sense, how would I fix it in that case?
  • edited June 2012
    In grey's tutorial 4, there's a part that handles key presses

    in your ini file you have
    [SoldierInput] ;==============================
    KEY_LEFT             = GoLeft
    KEY_RIGHT            = GoRight
    

    in the code there's a part that says
    case orxINPUT_EVENT_ON:
    {
    	if( orxInput_IsActive( "SpawnBox" ) )
    	orxObject_CreateFromConfig( "DynamicBox" );
    	break;
    }
    
    So you edit the tutorial and you change it to
    case orxINPUT_EVENT_ON: 
    { 
    	if( orxInput_IsActive( "GoRight" ) )
    	{
    		orxVECTOR speed = { orx2F(100.0f), orx2F(0.0f), orx2F(0.0f) };
    		orxOBJECT *yourobject = GetObjectByName( "Character" );
    		orxObject_SetSpeed( yourobject, &speed);
    	}
    	break;
    }
    
    To go left you'd set the speed to { orx2F(-100.0f), orx2F(0.0f), orx2F(0.0f) };
  • edited June 2012
    OH! Thanks again Grumly, I was overthinking it way too much. Thank you!

    EDIT: Just noticed something, whenever I click LEFT or RIGHT just for a second, the movement doesn't stop until I click the other direction. Is there something like orxInput_IsNotActive()?
  • edited June 2012
    That's a really basic question there. You should read C tutorials to get the basics because it'll only get more complex as you go deeper into your project.

    In the code
    if( orxInput_IsActive( "SpawnBox" ) )
    is the same as
    if( orxInput_IsActive( "SpawnBox" ) == orxTRUE )
    
    so if you want to know when it's not active, you either write
    if( !orxInput_IsActive( "SpawnBox" ) )
    (thought I'm not sure it works)
    or
    if( orxInput_IsActive( "SpawnBox" ) == orxFALSE )
    
  • edited June 2012
    Aw man, over thinking it AGAIN. Believe it or not I know this stuff, it's just at the VERY back of my head I guess. :P Thanks AGAIN grumly, :)

    Wait, how would I get the guy to stop moving though? Setting the speed to 0 doesn't work, it just makes things REALLY glitchy.
  • edited June 2012
    You can set the speed in a case orxINPUT_EVENT_OFF.

    edit: forgot to mention "else" to know if it's false.
  • edited June 2012
    I just came up with another question, but I don't feel like making a whole new thread since it would just take up space. :P

    Anyway, in the beginning of Grey's third tutorial, I can't find anything that sets the position of the position of the soldier, how would I do that?
  • edited June 2012
    In tutorial 4, it's orxObject_SetPosition

    If you want to know which functions to use you can right click a similar function and click go to declaration. For example if you right click orxObject_GetName and go to its definition, it brings you to orxObject.h where orxObject_SetPosition is also declared.

    There's also the documentation on this site. For this function you'd go to modules and orxObject.
  • edited June 2012
    What is a correct second parameter (I think that's the right word? :P) for orxObject_SetPosition.
  • edited June 2012
    It's the address of an orxVECTOR. If you search for orxObject_SetPosition in the forum or the site you'll find useful examples. Like :
    orxVECTOR tilePos;
    tilePos.fX = (80 * x) ;
    tilePos.fY = 160;
    tilePos.fZ = 0;
    orxObject_SetPosition(tile, &tilePos);
    
    or
    orxVECTOR pos;
    orxObject_GetPosition(player, &pos);
    pos.fX = -pos.fX;
    orxObject_SetPosition(player, &pos);
    

    edit: if you right click the function name it'll bring you to the declaration of the function where you can see what parameters you can put in.
  • edited June 2012
  • @iarwain said:
    No worries! :)

    Mmh, what are you trying to do exactly? I have to admit I'm not sure...

    Here in the facts you're re-declaring a function of orx. A re-declaration of functions is not something allowed in C/C++.

    In your redeclaration you don't specify a type for the first argument of the function, that's why the compiler is trying to interpret orxKEYBOARD_KEY_LEFT as a type (like orxU32, orxFLOAT, etc...), which doesn't make much sense and he's letting you know about it. :)

    What is the error message that the compiler gives when you redeclare a function without specifying the type of the first argument?

Sign In or Register to comment.