Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
0
Members

[Noob] Is there basic UI component ?

A topic by bali33 created Jan 28, 2016 Views: 630 Replies: 2
Viewing posts 1 to 3

Hello,

I just discovered Superpowers and it sounds like a great solution to create HTML 5 games. I was wondering what about UI components ? I know that usually using the DOM is recommended but I'd like to know it there is basic UI component like Button or similar behavior. It would be great to be able to create UI inside the canvas especially when it comes to drag & drop - I already had to manage UI in the DOM with draggable asset from the DOM to the Canvas and it was a real pain in the ass.

if not Button component exist, is it possible to detect/listen mouse event on a specific sprite ?

Thanks

Moderator

Hello! There is no proper ui component in Superpowers. But you can manage to do it like so:

let camera = Sup.getActor("Camera").camera;
let mousePosition = Sup.Input.getMousePosition();
let ray = new Sup.Math.Ray().setFromCamera(camera, mousePosition);
let result = ray.intersectActor(Sup.getActor("Button"));
if (result.length > 0) {
  // Hovering the button

  if (Sup.Input.wasMouseButtonJustPressed(0)) {
    // Just clicked on the button
  }

} else {
  // Not hovering the button
}

Hope it helps!

Ok - thanks for the answer !