-
-
Save RblSb/ea9b13a24bfdb9ae0bbd7a0826d498de to your computer and use it in GitHub Desktop.
meh button
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
package game.gui; | |
import kha.graphics2.Graphics; | |
import kha.Canvas; | |
import kha.Assets; | |
import kha.input.KeyCode; | |
import khm.Screen; | |
class SoundScreen extends Screen { | |
var buttons:Array<Button>; | |
public function init():Void { | |
final on = Assets.images.gui_sound_on; | |
final off = Assets.images.gui_sound_off; | |
final y = Screen.h / 2 - on.height / 2; | |
final x = Screen.w / 4 - off.width / 2; | |
final x2 = Screen.w / 2 + Screen.w / 4 - on.width / 2; | |
buttons = [ | |
new Button({x: x, y: y, imageId: "gui_sound_off", keys: [Q]}), | |
new Button({x: x2, y: y, imageId: "gui_sound_on", keys: [E]}) | |
]; | |
} | |
function newGame():Void { | |
var game = new game.Game(); | |
game.show(); | |
game.init(); | |
} | |
override function onResize():Void { | |
init(); | |
} | |
override function onMouseDown(p:Pointer):Void { | |
if (Button.onDown(this, buttons, p)) return; | |
} | |
override function onMouseUp(p:Pointer):Void { | |
if (Button.onUp(this, buttons, p)) return; | |
} | |
override function onMouseMove(p:Pointer):Void { | |
if (Button.onMove(this, buttons, p)) return; | |
} | |
override function onKeyDown(key:KeyCode):Void { | |
if (key == Q) { | |
Music.isEnabled = false; | |
newGame(); | |
} else if (key == E || key == Return || key == Space) { | |
Music.isEnabled = true; | |
newGame(); | |
} | |
} | |
override function onRender(canvas:Canvas):Void { | |
final g = canvas.g2; | |
g.begin(0xFF2D0B09); | |
drawBG(g); | |
for (button in buttons) button.render(g); | |
g.end(); | |
} | |
function drawBG(g:Graphics):Void { | |
g.color = 0xFFFFFFFF; | |
final head = Assets.images.gui_menu_back_1; | |
var offY = head.height; | |
g.drawScaledImage(head, 0, 0, Screen.w, head.height); | |
final bottom = Assets.images.gui_menu_back_2; | |
var bottomY = Screen.h - bottom.height; | |
if (bottomY < head.height) bottomY = head.height; | |
g.drawScaledImage(bottom, 0, bottomY, Screen.w, bottom.height); | |
final logo = Assets.images.gui_menu_pict; | |
g.drawImage(logo, Screen.w / 2 - logo.width / 2, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment