I just got back into XNA and i started creating a map editor. The game will be a 2D editor that will contain both a Animation, Map, Level, entity, and crafting editor. So far it's going pretty swell right now; but, I think i am missing some key things within the editor
Here let me explain the game I'm trying to make:
I really want to figure out how to craft a particle editor
I also want to know how to use farseer phsyics engine (tried getting started on XNATutorial.com, but it's not working correctly).
Thank you in advance for any help you can give me, I'm just trying to see what would be the best things to enter into the game for a 2D action platformer.
To craft a particle editor decide on what you want to be able to do first, then come back with more specific problems, or questions.
Maybe you want to be able to design a particle template. This could define a particle's appearence and behavour.
Then you'd edit a particle emitter template. This would define what particle template to spawn, and what initial properties a particle instance would have.
Then you'd create a particle emitter object in your editor. You could maybe override specific properties in the particle emitter templates.
You could event have a particle emitter template that was a list of particle emitters to spawn, so you could emit different particles from a single editor object.
This would allow you to create lets say a fire-outside particle template, which was a yellow circle, a fire-inside particle template which was a red partcile, with a shorter life than for former. You'd then define 2 particle emitters, one for each one. Giving spawned particles upwards, but slightly random directions. Then create a multi-emitter called Fire or something. Then in the level editor you'd just have to place your Fire emitter and in-game you'd get a nice fire effect.
Posting a specific problem you have with setting up the physics engine would help.
The overall idea is that you have your game object representation, and you need to create and link them to the physics objects so you can simulate those objects and then update your game objects (for rendering and game logic).
So, when you load your level you'd loop through every physical object and create an equivalent in your physics engine, being sure you can link your game object to the physical one later. Obviously you'd need to keep both systems in sync by adding/removing physical objects as the game progressed and game objects where created/destroyed.
Then in your game loop you'd run your game logic, which might update their positions directly. Then update the physics objects so their position was the equivalent to the game object's. Then run a physics update. Then update your game object's positions according to the physical object's positions.
Related
tl;dr
In a program that calls a function onEnterFrame on each frame, how do you store and mutate state? For instance if you are making a level editor or a painting program where keeping track of state and making small incremental changes are tempting / enticing / inviting. What is the most performany way to handle such a thing with minimal global state mutations?
long version:
In a interactive program that accepts input from the user, like mouse clicks and key strokes, we may need to keep track of the state of the data model. For instance:
Are some elements selected?
Is the mouse cursor hovering over an element, which one?
How long is the mouse button held down? Is this a click or a drag?
We also, sometimes need make small changes to a large model:
In a level editor, we may need to add one wall to an existing large set of prefabs. You don't want to recreate the set, no?
Read Prof Frisby's mostly-adequate-guide so far, there are many functional solutions to issues that deal with extracting a piece of data from some source of input, performing computation on that data and passing the result to some output.
Sometimes an app let's the user interact and perform a sequence of mutations on data. For instance, what if a program let's the user draw (like Paint) on a canvas and we need to store the state of the painting as well as the actions that led to that state (for undo and logging/debugging purposes)?
What state is acceptable to store and what should we absolutely avoid?
Currently my conclusions is that we should never store state that we only need temporarily, we should pass it to the function that needs it directly.
But what if there are several functions that need a specific computation? Like the case in which we check if the mouse's cursor is hovering over a specific area, why would we want to recompute that?
Are there ways to further minimize mutations of global state?
Storing state isn't the problem. It is mutating global state that is the problem. There are solutions to handling this. One that comes to mind is the State Monad. However, I am not sure this is ideal for undoing operations. But it is a place to start.
If you just want to look at the problem as an initial state and a set of operations then you can think of the operations as a List that can be traversed (with the head being the latest operation). Undoing a set of n operations could be accomplished by traversing the first n elements of the list and cons-ing the inverse of these operations to the list.
That way you don't modify global state at all.
Ok I have an object and a big square as well as other stuff in a room. I need the object which is obj_dot to randomly spawn but only within the big square (which is obj_paper) every time the room restarts.
Your question lacks detailed information on the setup of your sprites/objects, therefore this answer might not suit you 100% but hopefully it will provide you with a general idea of how to go about resolving this issue.
You probably want to put something like this within the create event for an object that is created on the room creation. I'm going to assume obj_paper is created on room creation (hence is recreated on room restart).
In the create event for obj_paper, type the following using GML.
//Assuming the sprite for obj_paper has it's x & y positioned in the center of the sprite
instance_create(irandom_range(x-sprite_width/2,x+sprite_width/2),irandom_range(y-sprite_height/2,y+sprite_width/2),obj_dot);
That should do the trick nicely.
I am designing a game that includes a world map widget; this widget has 100+ region widgets as its children. There is also a separate information panel widget. When I click on a region, I want that information to be sent and displayed on the information panel. My thoughts so far give me 2 options:
Connect each of the 100+ regions to the information panel. This seems ugly to me as I feel like the information panel should only know about the world map widget, not its internal workings (such as children).
Connect each of the 100+ regions to the map widget, and then have the map
send another signal to be picked up by other widgets in the game such as the information panel. This seems nicer as far as having independent widgets goes, but requires 2 signals instead of 1.
Is one of these methods preferable to the other? Or is there another solution I am missing entirely?
I used to work for a company which made its own geospatial information system (GIS) product and we had this exact use case using Qt as well.
From my experience we would use option #2 as it encapsulated the details and relationships between the information panel (i.e. a view) and the world map (i.e. a model).
In the future maybe your world map will contain more than selectable regions and the information panel may not want to have to start knowing about all of the different entities in your world map to display them. So yes while #2 results in some additional signals it can be better from an encapsulation and expansion standpoint.
For example connect the information panel to a signal from your world map regarding a selected entity rather than a region. Sure a region is an entity and using region directly could work but again in the future maybe your world map will have selectable buildings, markers, vehicles, etc...
i.e.
connect( mapWidget, SIGNAL( selectedEntityChanged( MapEntity* ) ),
infoPanel, SLOT( onSelectedEntityChanged( MapEntity* ) ) );
This way your information panel could be designed to generically display information about an entity, again from which a region is derived. If you want to add say a vehicle to your map and make it so the information panel can display it, all you'll have to do is derive your vehicle from entity and you'll be good to go.
Great question welcome to StackOverflow!
Remember that each QObject comes with a property system - a general purpose, Python-like key-value store. The keys are strings, and the values are variants. Since QWidget is a QObject, you can leverage that. Just by itself this makes QSignalMapper quite redundant.
You can also use the undocumented, but slightly faster userData mechanism - it uses integer keys instead of string keys. The unique key ids are obtained through registerUserData(), with semantics otherwise identical to QEvent::registerEventType.
I am trying to build a map based query interface for my website and I am having difficulty finding a starting point besides http://developer.google.com. I assume this is a rather simple task but I feel as though I am on a wild goose chase. Anyway the problem is the existing site places people into a category based on their address (primarily the zip code), this is not working out because of odd shapes and user density so I would like to solve the problem by creating custom zones.
I am not looking for a proprietary solution because I would really like to accomplish this on my own, I just need some better places to start or better suggestions for searches.
I understand that I will need to create a map with my predetermined polygons.
I understand how to create a map with polygons via js.
I do not understand how data will request which zone it is within and how it will return it as a hash I can store. eg. user=>####, zone=>####, section=>#####
http://blog.appdelegateinc.com./point-in-polygon-checking-with-google-maps.html
has some JS you can add to give the ability to test whether a point is within a polygon (sample: http://blog.appdelegateinc.com./static/samples/point_in_polygon.html ) using this approach: http://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm
I think as you place the markers, you'll hold them in an array (of objects)...then loop through, doing some sort of reduction of which polygons to test, testing those that remain, if inPoly, set marker.zone and marker.section to whatever suits your needs
What I'm trying to do is have a 3 state tree expansion.
I have three different icons for "expand" "collapse" "semi-expanded" which I want to use to show a partially populated tree control with all nodes initialized to semi-expanded state and then on clicking the "semi-expanded" icon it gets data from server and populates the tree and open that branch with "expanded" icon.
I tried looking for it but couldn't find anything close to it except the 3-state checkbox but don't know how to use it on 3 state icon when tree would only maintain 2 states.
Thanks in advance.
I think what you are looking for is called a lazy-loading tree. There are lots of examples your can google for, but here is a great example.
As far as the visual part of your request goes (3 different icons to show that state of the branch or node) - you could easily handle that with a custom renderer, by looking at a flag on the node for it's load status.
Does that help?
A 3-State tree control is a bit uncommon and might therefore be a bit confusing; consider that even simple 3-state checkboxes are relatively rare and users may not be accustomed to them. Maybe that's why you didn't find such a tree control.
Thus, maybe you should consider using an alternate design that doesn't require 3-state controls.
For example, the node could start in collapsed node. If the user expands it, and there is no data yet, show a single sub node with the text "retrieving data..." (and a progress wheel or other progress indicator, if you can) and start data retrieval. When the data arrives, replace this sub node with the actual data.