I try to do a simple thing: use a bitmap as background and put the hour on top of the bitmap I’m using the example code of the SDK to try to figure it out.
I'm able to draw only the background without time also to draw the time without background but I can't do both, display the background and time together.
I have two questions about the code:
1) How do I overlap the time over the bitmap?
2) How do I specify x,y position for the time?
I’m using the following code to try to show time and bitmap:
using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
using Toybox.System as Sys;
using Toybox.Lang as Lang;
class View extends Ui.WatchFace {
var background;
//! Load your resources here
function onLayout(dc) {
setLayout(Rez.Layouts.WatchFace(dc));
//Load my background
background=Ui.loadResource(Rez.Drawables.background);
}
//! Called when this View is brought to the foreground. Restore
//! the state of this View and prepare it to be shown. This includes
//! loading resources into memory.
function onShow() {
}
//! Update the view
function onUpdate(dc) {
//Draw Background
dc.drawBitmap(7, 25, background);
// Get and show the current time
var clockTime = Sys.getClockTime();
var timeString = Lang.format("$1$:$2$", [clockTime.hour, clockTime.min.format("%.2d")]);
var view = View.findDrawableById("TimeLabel");
view.setText(timeString);
// Call the parent onUpdate function to redraw the layout
View.onUpdate(dc);
}
//! Called when this View is removed from the screen. Save the
//! state of this View here. This includes freeing resources from
//! memory.
function onHide() {
}
//! The user has just looked at their watch. Timers and animations may be started here.
function onExitSleep() {
}
//! Terminate any active timers and prepare for slow updates.
function onEnterSleep() {
}
}
Thanks!!!