I am trying to create a 2D tile map engine that works sort of like a tiled ScrollView - objective-c

I already have a function that can return a tile for a given position. I am trying to make it so that when I scroll around it will load new tiles on the fly. I am having trouble figuring out how to attack the problem. I am sure that someone must have done this before and I would prefer to not reinvent the wheel on this.
Can anyone point me to a tutorial or some example code?
If not, can perhaps help me figure out how to do this?
I am using Kobold2D and the map is not going to be static, it will be generated on the fly, Minecraft style.

CATiledLayer is perfect for this. However, I do not know if this will play well with Cocos2d.

Related

Draggable MapKit Annotations

I am working with MapKit on MacOS and trying to enable a draggable annotation that uses a custom image. I can successfully get the annotation to be draggable but it requires the user to be quite accurate with where they click and drag as the annotation image is larger than a conventional pin. Is there a simple way to expand the area so that any part of the image is draggable? Otherwise I imagine I will have to use some kind of NSGesture on the view to manually set the dragstate, but was hoping there might be an easier way!
Okay, I never managed to sort this to my satisfaction using Annotations. I’m not saying it can’t be done, maybe someone else can comment and leave pointers to help. But I eventually achieved what I wanted using overlays instead. So if someone stumbles on this question and has the same issue, you can make it work with a custom overlay rather than an annotation and you implement the dragging using a NSPanGestureRecognizer with translation for the movement.

Improve perfomance of my threejs

I have some issues about my model. Is is an easy model buy I can not make It work well...
I upload my project here: http://webgl.drapps.info
I have a car model with some pieces that change material when mouse is over them. I use threex.domevent.js library with "on" function. My model is loaded by json files.
Issue 1
when mouse is out of canvas, threejs detects that mouse is over a piece of my model, but this is not true, and that piece change its material (triggering mouseOver event).
Furthermore, I tried to get better mouseover event because even when mouse is really over a piece, that event doesn't trigger.
Issue 2
This is about TrackballControls. Is there any way to control rotation of my world? I mean: rotation only in one axis, rotation only for 180 degrees, etc... Is there any tutorial or article to learn how to rotate and translate camera?
Thanks for everything, I will so please to anybody who wants answer this... because I am a little lost
Thanks
Sorry, but you are out of luck.
Question 1. Yikes! You are using threex.js which is a third-party app that hasn't been updated in almost a year, so I can't help you with that.
You are also using an older version of three.js. Please update to the current version.
If you still have problems, post a new question with a simple demo -- not your entire project. Better yet, Google your question first.
Question 2. TrackballControls is not part of the library -- it is part of the examples -- so it is not officially supported. If you are not happy with it, you will have to hack the code yourself.
This question has come up a lot. Google it. To the best of my knowledge, there is not a good solution.
Personally, I would use OrbitControls in your case -- it keeps the scene right-side-up, and you can constrain the maximum polar angle, keeping the camera "above ground".
The best examples/tutorials are the official three.js examples, which will work with the current version of the library.
I can't help with issue 1.
Issue2:
I am also working on a project to visualize vehicles and needed to be able to rotate. I also tried Trackballcontrolls but it did not suit my needs.
What I ended up doing was creating a a master Object3d and then instead of adding objects/models to the scene, I added them to the master Object3d. That way to rotate everything in the scene, I just had to rotate the master object.
To actually do the rotation I just used the code from one of the cube examples.

java3d simple way to translate object

I am making my first program using Java3D. I have setup some transformGroups that I now need to move in calculated directions. When I looked this up, I found interpolators and alpha objects and waveforms and couldn't understand a word of it. I have done this in the past in OpenGL using simple vectors and frame refreshment. Is there a similar simple way in Java3d? Thanks.
There's no reason you couldn't do it with vectors and frame refresh in Java3D as well.
A simple way would be to attach a behavior to the scenegraph with a WakeupOnElapsedFrames(0) condition, and then have it update the needed transform every frame.
As its simplest, that is was the interpolators are doing for you. Once you get that working, it will probably make more sense as to how you could do it with interpolators.

Create mock 3D "space" with forwards and backwards navigation

In iOS, I'd like to have a series of items in "space" similar to the way Time Machine works. The "space" would be navigated by a scroll bar like feature on the side of the page. So if the person scrolls up, it would essentially zoom in in the space and objects that were further away will be closer to the reference point. If one zooms out, then those objects will fade into the back and whatever is behind the frame of refrence will come into view. Kind of like this.
I'm open to a variety of solutions. I imagine there's a relatively easy solution within openGL, I just don't know where to begin.
Check out Nick Lockwood's iCarousel on github. It's a very good component. The example code he provides uses a custom carousel style very much like what you describe. You should get there with just a few tweaks.
As you said, in OpenGL(ES) is relatively easy to accomplish what you ask, however it may not be equally easy to explain it to someone that is not confident with OpenGL :)
First of all, I may suggest you to take a look at The Red Book, the reference guide to OpenGL, or at the OpenGL Wiki.
To begin, you may do some practice using GLUT; it will help you taking confidence with OpenGL, providing some high-level API that will let you skip the boring side of setting up an OpenGL context, letting you go directly to the drawing part.
OpenGL ES is a subset of OpenGL, so essentially has the same structure. Once you understood how to use OpenGL shouldn't be so difficult to use OpenGL ES. Of course Apple documentation is a very important resource.
Now that you know a lot of stuff about OpenGL you should be able to easily understand how your program should be structured.
You may, for example, keep your view point fixed and translate the world (or viceversa). There is not (of course) a universal solution, especially because the only thing that matters is the final result.
Another solution (maybe equally good, it depends on your needs), may be to simply scale up and down images (representing the objects of your world) to simulate the movement through the object itself.
For example you may use an array to store all of your images and use a slider to set (increase/decrease) the dimension of your image. Once the image becomes too large for the display you may gradually decrease alpha, so that the image behind will slowly appear. Take a look at UIImageView reference, it contains all the API's you need for it.
This may lead you to the loss of 3-dimensionality, but it's probably a simpler/faster solution than learn OpenGL.

Zoom-able/ resizable grid with Objective-C

Hi i'm thinking about making midi step sequencer and I need to make a note grid/matrix that resizes/ adapts when you zoom. I've been searching for different ways of doing this but cant figure out a way that works well.
I thought about drawing cell objects made with (NSRect) but I couldn't figure out how to get the right interaction when resizing.
This is my first "biggish" OBJ-c project so please don't kill me, im still battling with the frameworks and the syntax is so foreign to me.
You could use Core Animation layers to create your grid.
Take a look at Apple's Geek Game Board sample code project:
http://developer.apple.com/library/mac/#samplecode/GeekGameBoard/Introduction/Intro.html
The code shows a way to display different kinds of card/board games using CALayer.
The Checkers game looks to be the closest to the grid you want to create.