Tutorial Platform not appearing

edited January 2020 in Help request

Hey guys, I'm having trouble with the tutorial. For some reason the platform isnt working. The hero appears fine though. The box.png is inside /data/texture, any help is appreciated. :*

/**
 * @file spookyparty.cpp
 * @date 11-Jan-2020
 */

#include "orx.h"
using namespace std;

/*
 * This is a basic code template to quickly and easily get started with a project or tutorial.
 */

 int initiated = 0;

/** Init function, it is called when all orx's modules have been initialized
 */
orxSTATUS orxFASTCALL Init()
{
    // Display a small hint in console
    orxLOG("\n* This template project creates a viewport/camera couple and an object"
    "\n* You can play with the config parameters in ../data/config/spookyparty.ini"
    "\n* After changing them, relaunch the executable to see the changes.");

    // Create the viewport
    orxViewport_CreateFromConfig("Viewport");


    // Done!
    return orxSTATUS_SUCCESS;
}

/** Run function, it is called every clock cycle
 */
orxSTATUS orxFASTCALL Run()
{
    orxSTATUS eResult = orxSTATUS_SUCCESS;

    // Should quit?
    if(orxInput_IsActive("Quit"))
    {
        // Update result
        eResult = orxSTATUS_FAILURE;
    }

    // Done!
    if(initiated==false){
        orxOBJECT *heroObject = orxObject_CreateFromConfig("HeroObject");
        // Create platform
        orxObject_CreateFromConfig("PlatformObject");

        initiated = true;
    }


    return eResult;
}

/** Exit function, it is called before exiting from orx
 */
void orxFASTCALL Exit()
{
    // Let Orx clean all our mess automatically. :)
}

/** Bootstrap function, it is called before config is initialized, allowing for early resource storage definitions
 */
orxSTATUS orxFASTCALL Bootstrap()
{
    // Add a config storage to find the initial config file
    orxResource_AddStorage(orxCONFIG_KZ_RESOURCE_GROUP, "../data/config", orxFALSE);

    // Return orxSTATUS_FAILURE to prevent orx from loading the default config file
    return orxSTATUS_SUCCESS;
}

/** Main function
 */
int main(int argc, char **argv)
{
    // Set the bootstrap function to provide at least one resource storage before loading any config files
    orxConfig_SetBootstrap(Bootstrap);

    // Execute our game
    orx_Execute(argc, argv, Init, Run, Exit);

    // Done!
    return EXIT_SUCCESS;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
config INI file
; spookyparty - Template basic config file

[Display]
ScreenWidth     = @MainCamera.FrustumWidth
ScreenHeight    = @MainCamera.FrustumHeight
Title           = spookyparty
FullScreen      = false
Smoothing       = false
VSync           = false
ShowFPS         = true

[Viewport]
Camera            = MainCamera
BackgroundColor   = (0, 180, 255)

[MainCamera]
FrustumWidth    = 800
FrustumHeight   = 600
FrustumFar      = 2.0
FrustumNear     = 0.0
Position        = (0.0, 0.0, -1.0) ; Objects with -1 <= Z <= 1 will be visible

[Resource]
Texture         = ../data/texture
Sound           = ../data/sound

[Input]
SetList         = MainInput

[MainInput]
KEY_ESCAPE      = Quit

[FadeIn]
SlotList        = @
Type            = alpha
Curve           = smooth
StartTime       = 0
EndTime         = 1.5
StartValue      = -1
EndValue        = 0

[HeroObject]
Graphic      = HeroGraphic
Position     = (-350, 100, 0)
Scale        = 2
AnimationSet = HeroAnimationSet

[HeroGraphic]
Texture        = soldier_full.png
TextureOrigin  = (0,0,0)
TextureSize    = (32,32,0)

[HeroAnimationSet]
Texture   = soldier_full.png
FrameSize = (32, 32, 0)
HeroRun   = 6 ; or -1 would be fine too.
StartAnim = HeroRun

[HeroRun]
KeyDuration = 0.1

[PlatformGraphic]
Texture = box.png

[PlatformObject]
Graphic  = PlatformGraphic
Position = (100, 170, 90)
Scale    = (40, 2, 0)

Comments

  • Hi Sacked, welcome here. I wrote the beginner's tutorial so I should be able to help you out ok.

    A couple of things to note in your code:

    if(initiated==false){
        orxOBJECT *heroObject = orxObject_CreateFromConfig("HeroObject");
        // Create platform
        orxObject_CreateFromConfig("PlatformObject");
    
        initiated = true;
    }
    

    This needs to be moved out of the Run() function as this executes every frame and is likely to eventually crash after creating many thousands of objects. Move it to the Init() function.

    And then you shouldn't need to use the initiated check or variable.

    For general issues, you can check the logs next to your .exe for information on problems too.

    If you get totally stuck, feel free to zip up your work in progress and I can test what you have made.

    Let me know how you go.

  • edited January 2020
    Hi @sacked and welcome here.

    As @sausage said, moving your object creations to the `Init` function is cleaner and you won't need the boolean value to prevent object duplication as you're currently doing.

    That being said, your problem comes from the fact your platform object is likely outside of the camera's frustum: the camera's position is (0, 0, -1), its FrustumNear is 0 and FrustumFar is 2, which means it can only "see" objects with Z coordinate between -1 and 1.
    However your `PlatformObject` has a Z coordinate of 90, which is much bigger than 1.

    Seeing its position to (100, 170, 0) should fix your issue.
  • Ah yes, I put that initialization in just for testing, I must have left it in by accident. The scaling fixed it, thanks for the help.

  • My pleasure. Don't hesitate if you have any other questions.
Sign In or Register to comment.