This is my simplified code:
function PreloadSounds()
{
createjs.Sound.addEventListener("fileload", eSoundLoad);
createjs.Sound.alternateExtensions = ["mp3"];
createjs.Sound.registerSound({id:"knock",src:sndurl+"knock.mp3"});
}
function eSoundLoad(event) {
sndKnock = createjs.Sound.createInstance(event.src);
}
I would like to know if there is any event that is fired after a sound is totally played...
Thanks!
Related
I am creating a custom renderer, that needs to display whatever I have rendered in my Vulkan engine. For this I have a VulkanSurfaceView, which inherits from MetalKit.MTKView on iOS, and from Android.Views.SurfaceView and ISurfaceHolderCallback on Android.
For iOS I can simply do this, which will draw a new frame continually, as long as the view is in focus:
public class VulkanSurfaceView : MTKView, IVulkanAppHost
{
...
public override void Draw()
{
Renderer.Tick();
base.Draw();
}
}
However, on Android I have to do this, where I call Invalidate() from within the OnDraw method, else it is only called once. I think this code smells a bit, and I am not sure, if this is the "good" way of doing it. Is my solution okay? If not, does anyone have a better idea?
public class VulkanSurfaceView : SurfaceView, ISurfaceHolderCallback, IVulkanAppHost
{
...
protected override void OnDraw(Canvas? canvas)
{
Renderer.Tick();
base.OnDraw(canvas);
Invalidate();
}
}
Did you try calling setWillNotDraw(false) in your surfaceCreated method ?
Refer the link
Thank you to #ToolmakerSteve.
I created a Timer where I call Invalidate() if a new frame has been requested (by me via a simple bool). For anyone interested I do it like so:
protected override void OnDraw(Canvas? canvas) // Just to show the updated OnDraw-method
{
Renderer.Tick();
base.OnDraw(canvas);
}
public void SurfaceCreated(ISurfaceHolder holder)
{
TickTimer = new System.Threading.Timer(state =>
{
AndroidApplication.SynchronizationContext.Send(_ => { if (NewFrameRequested) Invalidate(); }, state);
try { TickTimer.Change(0, Timeout.Infinite); } catch (ObjectDisposedException) { }
}, null, 0, Timeout.Infinite);
}
For now it is very simple, but it works and will probably grow. The reason for my initial bad framerate with this method was a misunderstanding of the "dueTime" of the Timer (see Timer Class), which I though was the framerate sought. This is actually the time between frames, which seems obvious now.
As #Bhargavi also kindly mentioned you need to set "setWillNotDraw(false)" if OnDraw is not being called when invalidating the view.
I'm quite a newbie with annyang. I'm trying to add a Greensock Timeline in a annyang command, but it is not working. I am wondering if it is not possible or if I'm doing something wrong.
This is the code were it is about:
var tlcrocodile = new TimelineLite({paused:true});
if (annyang) {
var commands = {
'hello': function() {
tlcrocodile.to(".crocodile_1", 0.3 , {x:+40} , 0);
}
};
annyang.addCommands(commands);
annyang.start();
}
Hopefully someone can help me. Thanks in advance!
Ilse
It seems like your TimelineLite instance never play because you instantiate it as paused but you never call play() on it.
Try instantiating it directly inside the hello command, when you need it to play.
And add a console log to make sure your command was really triggered.
if (annyang) {
var commands = {
'hello': function() {
console.log('Hello command executed.');
new TimelineLite().to(".crocodile_1", 0.3 , {x:+40} , 0);
}
};
annyang.addCommands(commands);
annyang.start();
}
I need to send email to multiple user in every day.
My code is like this.
It works as well, but I have misunderstood.
foreach($advisors as $advisor) {
$receivers = [];
foreach($advisor->clients as $client) {
array_push($receivers, $client);
}
array_push($receivers, $advisor);
if (count($receivers) > 0) {
Notification::send($receivers, new DailyEmail($advisor));
}
}
before I code like below.
foreach($advisors as $advisor) {
$receivers = [];
foreach($advisor->clients as $client) {
array_push($receivers, $client);
}
if (count($receivers) > 0) {
Notification::send($receivers, new DailyEmail($advisor));
}
Notification::send($advisor, new DailyEmail($advisor));
}
but if I code like this, only one user got email.
I can't understand, why this works different.
If you can explain about this, please.
The "old" code was firing the Notification::send event twice, once for the receivers and once for the advisor.
Your "new" code only fires it once for the receivers, thus the advisor is not getting an email notification.
Now i may be understanding your code wrong for lack of more information, but if you want to send the notification to the $advisor->clients you dont need to loop them over and make a new array, in fact Notification::send expects a collection
Just do:
foreach($advisors as $advisor) {
if (count($advisor->clients) > 0) {
Notification::send($advisor->clients, new DailyEmail($advisor));
}
}
I'm making a simple matching game and would like a count down timer. Is there a way to set off an event every dt? I found some code using threads, but seems a lot more complicated for what I need.
Something like this should work:
TimerTask countdown = new TimerTask() {
public void run() {
synchronized(UiApplication.getEventLock()) {
//do the stuff to the UI, ie change the counter
}
}
};
Timer timer = new Timer();
timer.scheduleAtFixedRate(countdown, 0, dt);
I didn't test this, so I may have a typo in there, but this is the basic idea. Take a look at the TimerTask and Timer documentation for more info.
I was wondering if anyone was aware of an example that shows multiple listeners to the YUI DDProxy, DD, or DDTarget onDragDrop event. Currently I have a hacked up example going. I'm using the http://developer.yahoo.com/yui/examples/datatable/dt_ddrows.html'>DataTable Reorder Rows example. I've modified it into several js classes. One object they override DDProxy for handles the onDragDrop event but it seems that if it's handled here then nothing else catches the event. Check the snip:
YAHOO.extend(YAHOO.example.DDRows, YAHOO.util.DDProxy, {
//snip
onDragDrop: function(e, id) {
if (id == "right-function-pane") {
alert("In the right drop place");
YAHOO.util.DragDropMgr.refreshCache();
}
}
In a class that does the creation of DDRows, I want to listen to the event here as well. Some actions are more appropriate in some places. I want to listen to the event in both places. Here's what I'm doing in class that builds the above:
onDropHandler: function(e, id) {
DragDropTable.myDataTable.deleteRow(YAHOO.util.DragDropMgr.dragCurrent.id);
},
rowInitializer: function() {
var i, id, myDDRow,
allRows = DragDropTable.myDataTable.getTbodyEl().rows;
for (i = 0; i < allRows.length; i++) {
id = allRows[i].id;
// Clean up any existing Drag instances
if (DragDropTable.myDTDrags[id]) {
DragDropTable.myDTDrags[id].unreg();
delete DragDropTable.myDTDrags[id];
}
// Create a Drag instance for each row
myDDRow = new YAHOO.example.DDRows(id);
myDDRow.srcData = DragDropTable.myDataTable.getRecord(id).getData();
myDDRow.onDragDrop = DragDropTable.onDropHandler;
DragDropTable.myDTDrags[id] = myDDRow;
}
}
It seems like if one is listening the other isn't working. I haven't found the syntax for allowing events to continue to bubble or to have multiple subscriptions to onDragDrop. Does anyone have the correct syntax?
Thanks
Josh Robinson