Mojo: Moving view, but keeping objects fixed?
Monkey Forums/Monkey Programming/Mojo: Moving view, but keeping objects fixed?
| ||
Hi, I have up and running a world based on the mojo example for the tileset. The guy moves around and the world stays still.. So I went and added another item (bomb) to the world and it spawned where it should, now my problem is that the spawn point is based on the location on screen and when the player moves the screen over, the bomb move over, retaining its position. How would one go about working out its location relative to where it spawned, rather than the screen? In others words, how can I get objects to stay, even when the screen is moved? Ideas appreciated, Craig |
| ||
You need to scroll your objects based on the current scrolling offset. Where you DrawImage() your object, offset it's X and Y co-ordinates the same amount as you're offsetting the tilemap. |
| ||
hope this helps.. I find a visual explanation is often easier to grasp if your having trouble with it.![]() |
| ||
Platdude Error. Redo from Start. Your Platdude has a short neck. -=-=- Upon closer inspection, that's an optical illusion caused by his oversized hands.. |
| ||
lol, I could never draw him as well as you :) |
| ||
Hi, Thanks for the ideas. I kind on understand what I should do, just not getting it working. I managed to get them to partly stay, but they get offset more and more and the render repeats. Using the example here which uses the same method I am, how would you add in the function? http://www.monkeycoder.co.nz/Community/posts.php?topic=5078 I have added my test in to the Draw of the level class. The last test I did was like this. For Local entity:Entity = Eachin Entities If entity entity.Draw(xPos + TileHeight, yPos + TileWidth) Endif Next Not even sure if this is the right way to do really. |
| ||
Would be easier if we could see your whole code, but from the looks of it your not drawing or adding the offset for x or y, I assume tileHeight is static ? |
| ||
Hi, I will upload it tonight for you to look at. Its all a learning curve for me, so maybe others will find it helpful to have the source. Will be home about six GMT. |
| ||
You should store everything in map/world coordinates. Forget about the screen! For ex: your map is 20 tiles of 64x64 - so your map has a width of 1280px. Place your objects in the interval [0...1279]. When rendering, get player position (also inside the map/world), and draw everything near the player (for example, draw everything from player-50px to player+750px) The image drawn by Taiphoz shows exactly that :) |
| ||
Sorry couldn't help myself, heres a quick example: http://www.therevillsgames.com/monkey/scrolling/MonkeyGame.html |
| ||
Hey therevills, he can't jump! ;) |
| ||
LOL! I know... I was only showing the scrolling part... I didn't want to add collisions etc. to confuse the issue. |
| ||
*sigh* ...Spheres should be blue, floors are red.. <Alan Partridge>Stop Getting Platdude Wrong!!</Alan Partridge> |
| ||
Haha, nice one! |
| ||
Not home yet, but saw the email about this post. Should mention, that its a top down game I'm going for, don't know if this matters much. Like the old rockfall or boulder dash, etc. |
| ||
oh therevills you have incurred the wrath of the platdude god lol :) James your just jealous that mine and therevills are better than yours :P |
| ||
I seriously wish I could get touchscreen controls working with JNKPlat mechanics. Sucks that I can't.. ...and trust me, I've been trying!!! DeltaWolf, just be sure to keep track of a single set of ScrollX and ScrollY variables, and use that to offset all your drawing functions.. (Except the GUI, and stuff!) |
| ||
Looking like good stuff. Thank you very much for all the info. I haven't cracked it yet, but as promised.. http://code.google.com/p/deltas-monkey-games/source/browse/#svn%2Ftrunk All my learning monsters are uploading to here. The one referred to in this discussion is the rockfall evolution game. Please have look and tell me how bad I did.. The basic idea comes from things I found on the forum and a video on YouTube. Please mention anything, that I might be doing wrong, that way I can learn. Word of warning, during my learning, I have been commenting.. (NOTHING).. Good luck ;-p |
| ||
<Alan Partridge>Stop Getting Platdude Wrong!!</Alan Partridge> You know its a "thing" now dont you, Jay! We all must now draw Platdude wrong ;) Please mention anything, that I might be doing wrong, that way I can learn. For your Rockfall Evolution project I see that every time you call New on a gold object you will be reloading the image... this "okay" if you only every have one object, but if you are going to have multiple you will keep loading the image again and again. Your code: Method New() Picture = LoadImage("gold.png", 32, 32, 1) End Suggested: Method CreateGold:Void() Local img:Image = LoadImage("gold.png", 32, 32, 1) For Local i:Int = 0 To 10 New Gold(img) Next End ... Class Gold Extends Entity Method New(image:Image) Picture = image End End |
| ||
You make a very good point. Thank you for pointing this out. |
| ||
Have you considered translating the transformation matrix as it was a camera? That could do it too |