how to make a game tutorial as farmville game tutorial to teach the user to play the game. i have recently involve in make that kind of game tutorial for its user by actionscript 3, can anyone give me a guide to do it? any help is appreciated~
A common way to do this is similar to the "achievements system" many games employ, which utilises the a system similar to the Observer design pattern.
You'd set up a globally-accesible receiver object, with a function to receive a data packet of some sort.
Then, every function that should effect the tutorial info being shown would message this receiver object, and tell it of it's performed action.
So, say for instance, that you have a message box up to tell the player to "Chop down 10 trees".
You could then have a Receiver object with a function like TutorialMessage(var Action:String, var Parameter:object):void
When they perform the "Chop down tree" action, then end of the chopDownTree() function would contain a call to the receiver object's messaging function Receiver.TutorialMessage("TreeChoppedDown", 1) (ie, Chopped down 1 tree).
That receiver would then, essentially, run a massive switch case to determine the nature of the action, and interpret would to do based on your logic. In this case, it would add the value of Parameter to some counter variable, and when it reached 10, would display the next tutorial message.
Related
I made a small application in Akka that has a hierarchy of actors (there is an ActorA that has several ActorB actors, and these ActorB actors have several ActorC actors). Now I'd like to add a small UI. This UI doesn't have any buttons, but just some labels that are modified when the ActorC actors receive certain messages from other actors. The problem that I have is that I must create a label for each ActorC actor, but the number (of ActorC actors) is not always the same, so I must create the ActorC actors in the first place, and then I must create the labels. I searched for tutorials on Scala Swing, but i just found old documentation or simple examples that are not useful in my case (something like press a button to do something). I even saw that several people used Java Swing in their Akka applications. I found a tool called Kamon, but i need to create an interface, not just monitoring my actors. Is there someone that can help me?
Swing is deprecated in favor of JavaFX. That said, JavaFX allows you to create a "rich client" application. It sounds like too heavy of a solution for what you want.
Perhaps a simple web UI? Have you looked at playframework.com? Your interface would just be some web pages that can talk to the actors. Play and Akka work well together, and it's pretty easy to get started with Play using available tutorials and templates.
There are two aspects to your design. The first aspect is the communication between your UI and your working actors. The second is the operation of your UI.
A scenario might be that your UI starts up and fires up a Swing EDT thread to display your status window. An actor is also created and it reaches out to your Actor A and says "ready to go". Actor A forwards the message to all Actor Bs, which forward it to the Actor Cs. Each Actor C then registers itself with the UI by sending a message "I am here" and "this is my status".
def receive = {
...
case ReadyToGo =>
myMonitor = sender
sender ! "ready"
}
The UI-Actor takes each of the registration messages and maps it to a label, creating it if needed. As each Actor C changes its state, it sends a new message to UI-Actor, saying "I am still here" and "this is my status".
The UI-Actor is the go-between the Akka world and the UI. This is the tricky part, since the UI-Actor runs on a different thread than the Swing event-dispatch-thread. It must put a task on the Swing queue for processing by the Swing thread in a thread-safe manner. Some rough code:
// assume labelMap is a map from ActorRef to Label, ordered by insertion
def receive = {
case IAmHere(status) =>
val actorC = sender
if ( ! (labelMap contains actorA) ) {
addStatusLabel(actorC, status)
}
case IAmStillHere(status) =>
updateStatusLabel(actorC, status)
}
def addStatusLabel(actorC: ActorRef, status: String) = {
Swing.onEDT {
labelMap(actorC) = new Label(status)
// recalculate the panel size
// repaint
}
}
def updateStatusLabel(actorC: ActorRef, status: String) = {
Swing.onEDT {
labelMap(actorC).text = status
// repaint
}
}
I leave it up to you to lay out the UI, the container, whether statuses are Strings or not, how to handle Actor Cs that go missing, etc.
MVVMCross
Windows Store
Android
I have a VM that browses a hierarchy (BrowseVm) and supports forward navigation via
ShowViewModel<LeafDetailVM>
to a leaf detail ViewModel (LeafDetailVM).
When the user is on the LeafDetail View they should be able to say "I want this one" and they will be returned to the View that initiated BrowseVm.
I cannot simply Forward Navigate to the Initiator because that would leave me with an invalid back stack. I cannot have the BrowseVM view as a NoHistory page as I need it be in the back stack to support going back from the LeafDetail view.
My plan is to have the initiator start BrowseVm with a GUID. BrowseVm will pass that GUID onto LeafDetailVM.
In the "I want this one" command I will raise a Message, containing the GUID, that both BrowseVM and the initiator are subscribed to. Then I will close LeafDetailVM.
When BrowseVM receives the notification of the message it will compare the GUID and if it matches it will close itself.
When the initiator receives the notification it will deal with the now chosen data.
Does this make sense? Have I missed a much simpler way of doing this?
This is similar to How to pass a parameter from a viewmodel to its parent viewmodel but that does not deal with the back stack.
Thanks
I suggest you try stop mentally coupling how the views work on a platform to the view-models.
With the custom presenter mechanism in MvvmCross, in the app (platform specific code) you can handle navigation to a certain view-model in different ways, including closing views, modify backstack, etc.
You can interpret navigation to a view-model in whatever way you want \ need.
You can for example pass from view-model some parameters in the ShowViewModel request which the view-presenter (IMvxViewPresenter) can interpret in different ways in the Show() to display a view-model.
In your case, you can actually navigate to initiator VM passing the selected info. In the view presenter, you can modify the backstack in the way you need.
On Android, make sure you read and know about all LaunchMode flags, for example LaunchMode.SingleTask which allows you bring the initiator activity to front without creating a new one.
It's not clear to me, is BrowseVm a parent view-model to the LeafDetailVM?
More info would be needed to understand exactly your scenario.
In order to get the keyboard state we can listen to "keydown" event but is it possible to interrogate the keyboard without an event? Something like window.keyState.shiftkey?
In 2018 I'm investigating the same thing: (re-)initialisation on acquisition of focus.
Initialisation (determination of system state) is required when the application starts. It is required every time the application recovers focus after losing it to another application, because state like NumLock can change while the application does not have focus.
As the question notes, this information can be obtains from event objects.
There doesn't appear to be any way to request this information.
This requires a change to browsers. In my opinion a low impact solution
for this and parallel situations is a general mechanism for requesting a "null event" of a specified type, eg
var ke = window.requestEvent("keyboard");
var me = window.requestEvent("mouse");
var te = window.requestEvent("haptic");
Since a keyboard/mouse/touch event is not actually occurring, the field that would otherwise quantify the event (key code, mouse position etc) should be null.
This API should not be a breaking change for event handlers, since it doesn't actually trigger an event, it's a function that returns an event object. It's completely new so there is no legacy code, and it can be extended without change simply by defining more event class strings. No new data structures are defined.
If I knew how to submit a change request to the pertinent browser standards committee, this seems to me like a very tight, robust, compatible solution to several problems. I'm recording this here as a sort of message in a bottle, in the hope that one day it will be seen by someone who can act on it.
Thanks for your reply for my question: Is this a bug of Box API v2 when getting events
This is a new problem related to this. The problem is that I cannot reliably use the next_stream_position I got from previous calls to track events.
Given this scenario:
Given the following two GET HTTP queries:
1. GET https://api.box.com/2.0/events?stream_position=1336039062458
This one returns the JSON file which contains one file entry of myfile.pdf and the next stream position = 1336039062934
2. GET https://api.box.com/2.0/events?stream_position=1336039062934
This call uses the stream position I got from the first call. However, it returns the JSON contains the exactly same file entry of myfile.pdf with the first call.
I think if the first call gives a stream position, it should be used as a mark for that exact time (say: TIme A). If I use that stream position in subsequent queries, no events before "Time A" should be returned.
Is this a bug? Or did I use the API in the wrong way?
Many thanks.
Box’s /events endpoint is focused on delivering to you a highly reliable list of all the events relevant to your Box account. Events are registered against a time-sequenced list we call the stream_position. When you hit the /events API and pass in a stream_position we respond to you with the events that happened slightly before that stream position, up to the current stream_position, or the chunk_size, whichever is lesser. Due to timing lag and our preference to make sure you don’t miss some event, you may receive duplicate events when you call the /events API. You may also receive events that look like they are ‘before’ events that you’ve already received. Our philosophy is that it is better for you to know what has happened, than to be in the dark and miss something important.
Box events currently give you a window roughly 5 seconds into the past, so that you don't miss some event.
We have considered just delaying the events we send you by about 5 seconds and de-duplicating the events on our side, but at this point we've turned the dial more towards real-time. Let us know if you'd prefer a fully de-duped stream, that was slower.
For now, (in beta) if you write your client to check for duplicate events, and discard them, that will be best. We are about to add an event_id to the payload so you can de-duplicate on that. Until then, you'll have to look at a bunch of fields, depending on the event type... It's probably more challenging that it is worth.
In order to help you be able to figure out if an event is a duplicate, we have now added to each event an event_id that will be unique. It is our intention that the event_id will allow you to de-duplicate the responses you receive from subsequent GET /events calls.
You can see this reflected in the updated documentation here, including example payloads.
I'm trying to make a simple video chat using Flex framework and red5 server. It's an application with 2 video displays. With connection to the server more or less figured out. However, I do not understand how to transfer user1 stream to user2.
Here is functions i use to transfer webcam image to the server and to get the stream.
public function appendStream(connection:NetConnection):void {
myNetStream = new NetStream (connection);
myNetStream.attachAudio(cameraVideo.getMic());
myNetStream.attachCamera(cameraVideo.getCam());
myNetStream.publish("videochat" , "live");
}
public function getStream(connection:NetConnection):Video {
guestNetStream = new NetStream(connection);
video2.attachNetStream (guestNetStream);
guestNetStream.play("videochat");
return video2;
}
As you can see, i am getting my own stream.
Is it possible to solve the problem by flex, or I need programming on the server side?
You dont need separate rooms, simply use unique stream names for each client. The ez way is to create your steam names ahead of time and pass them to your swf via flashvars; that way you dont have to pair them with some other complicated scheme.
For a bit more background in red5, a room is a type of scope and a scope can contain other scopes which includes broadcast scopes, shared object scopes, and rooms. There is no limit on the number of these scopes other than the amount of RAM on the server itself.
You need to have two "rooms" instead of one "videochat". User1 must publish to "videochat1" and stream from "videochat2". Vice versa for user2.
And please remove Flex mention here since there's nothing related to Flex UI framework here