-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR enables scene specific input APIs that only fire handlers when the scene is active! This is very useful if you have a lot of handlers to manage and don't want to keep track of engine level subscriptions. ```typescript class SceneWithInput extends ex.Scene { onInitialize(engine: ex.Engine<any>): void { this.input.pointers.on('down', () => { console.log('pointer down from scene1'); }); } } class OtherSceneWithInput extends ex.Scene { onInitialize(engine: ex.Engine<any>): void { this.input.pointers.on('down', () => { console.log('pointer down from scene2'); }); } } ``` https://github.com/excaliburjs/Excalibur/assets/612071/b6759145-d45b-4212-92a6-d0a4f8ff990b
- Loading branch information
Showing
10 changed files
with
177 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Scene Input</title> | ||
</head> | ||
<body> | ||
<script src="../../lib/excalibur.js"></script> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/// <reference path='../../lib/excalibur.d.ts' /> | ||
|
||
const font = new ex.Font({ | ||
size: 48, | ||
family: 'sans-serif', | ||
baseAlign: ex.BaseAlign.Top | ||
}); | ||
|
||
class SceneWithInput extends ex.Scene { | ||
onInitialize(engine: ex.Engine<any>): void { | ||
this.add(new ex.Label({ | ||
pos: ex.vec(200, 200), | ||
text: 'Scene 1', | ||
font | ||
})); | ||
|
||
this.add(new ex.Actor({ | ||
pos: ex.vec(400, 400), | ||
width: 200, | ||
height: 200, | ||
color: ex.Color.Red | ||
})); | ||
|
||
this.input.pointers.on('down', () => { | ||
console.log('pointer down from scene1'); | ||
}); | ||
} | ||
} | ||
class OtherSceneWithInput extends ex.Scene { | ||
onInitialize(engine: ex.Engine<any>): void { | ||
this.add(new ex.Label({ | ||
pos: ex.vec(200, 200), | ||
text: 'Scene 2', | ||
font | ||
})); | ||
|
||
this.add(new ex.Actor({ | ||
pos: ex.vec(400, 400), | ||
width: 200, | ||
height: 200, | ||
color: ex.Color.Violet | ||
})); | ||
|
||
this.input.pointers.on('down', () => { | ||
console.log('pointer down from scene2'); | ||
}); | ||
} | ||
} | ||
|
||
var engineWithInput = new ex.Engine({ | ||
width: 800, | ||
height: 800, | ||
scenes: { | ||
scene1: { scene: SceneWithInput, transitions: {in: new ex.CrossFade({duration: 1000, blockInput: true})}}, | ||
scene2: { scene: OtherSceneWithInput, transitions: {in: new ex.CrossFade({duration: 1000, blockInput: true})}} | ||
} | ||
}); | ||
|
||
engineWithInput.input.pointers.on('down', () => { | ||
console.log('pointer down from engine'); | ||
}); | ||
|
||
engineWithInput.input.keyboard.on('press', e => { | ||
if (e.key === ex.Keys.Space) { | ||
engineWithInput.currentSceneName === 'scene1' ? engineWithInput.goto('scene2') : engineWithInput.goto('scene1'); | ||
} | ||
}) | ||
|
||
engineWithInput.start('scene1'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.