damienmarchandfr's Forum Posts

  • 5 posts
  • Hi,

    I see my error. The event listener must be in OnBeforeProjectStart function.

    async function OnBeforeProjectStart(runtime)
    {
    	runtime.addEventListener("tick", () => Tick(runtime));
    	runtime.layout.addEventListener("afterlayoutstart",()=> OnAfterLayoutStart(runtime))
    }
    
    async function OnAfterLayoutStart(runtime){
    	console.log('layout started')
    }
    

    Happy to find the answer. I hope it will help somebody :)

  • Hi,

    Thank you for your answer el3um4s

    I understand and made the changes.

    What I do not understand is that the event "beforelayoutstart" is never triggered.

    import CarSprite from './CarSprite.js'
    import CheckpointSprite from './CheckpointSprite.js'
    
    
    let carsSpriteInstances = []
    let checkPointsInstances = []
    let startPointInstance = null
    
    
    runOnStartup(async runtime =>
    {
    	runtime.objects.CarSprite.setInstanceClass(CarSprite);
    	runtime.objects.CheckpointSprite.setInstanceClass(CheckpointSprite);
    
    	runtime.addEventListener("beforeprojectstart", () => OnBeforeProjectStart(runtime));
    	runtime.addEventListener("beforelayoutstart",()=> OnBeforeLayoutStart(runtime));
    });
    
    async function OnBeforeProjectStart(runtime)
    {
    	runtime.addEventListener("tick", () => Tick(runtime));
    }
    
    async function OnBeforeLayoutStart(runtime){
    	// Never executed
    	console.log('Layout')
    	debugger
    	
    	// Get all checpoints instances
    	checkPointsInstances = runtime.objects.CheckpointSprite.getAllInstances()
    	// Get all car sprite
    	carsSpriteInstances = runtime.objects.CarSprite.getAllInstances()
    	// Get start point instance
    	startPointInstance = runtime.objects.StartSprite.getAllInstances()[0];
    	
    	
    	// Init each checkpoint
    	for(let i = 0; i < checkPointsInstances.length; i++){
    		checkPointsInstances[i].setIndex(i+1)
    	}
    
    	// Init each car
    	for(let i = 0; i< carsSpriteInstances.length;i++){	
    		carsSpriteInstances[i].init(checkPointsInstances)
    	}
    
    }
    
    
    function Tick(runtime)
    {
    	for(let i = 0; i< carsSpriteInstances.length;i++){
    		// Car.Tick must be call every Tick
    		carsSpriteInstances[i].Tick({
    			checkPointsInstances,
    			startPointInstance
    		})	
    	}
    }

    Thanks for your help.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you for your answer Ashley

    I added a button to change the layout if someone wants to test.

    When the game start. On the first layout the is no error but it's not the case when a new layout is loaded.

    A Google drive link to the project :

    drive.google.com/file/d/19gbCGAFGdRM_7_LxuIbXZU-vEpOS-ttd/view

    Thanks.

  • Hi.

    I have an error when I change the layout in my game.

    When I start my game with the first layout, all is working fine, but when I change

    the layout with :

    runtime.goToLayout('2')

    I have a lot of errors in my console.

    The layout displays well...

    I don't know how to give you more details.

    Thx for your help.

  • Hi,

    I'm starting using Scripting in construct 3 and I'm a little lost.

    I made a Player class and want to manage events in my class.

    Is it possible to access an event in my class like this?

    this.on('collision',callback) or somthing like that ?

    I don't want to use overlapping because I just want to be triggered one time.

    Excuse my English and thx for your help. :)

    Tagged:

  • 5 posts