Mojo: Moving view, but keeping objects fixed?

Monkey Forums/Monkey Programming/Mojo: Moving view, but keeping objects fixed?

DeltaWolf7(Posted 2013) [#1]
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


ElectricBoogaloo(Posted 2013) [#2]
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.


Paul - Taiphoz(Posted 2013) [#3]
hope this helps.. I find a visual explanation is often easier to grasp if your having trouble with it.




ElectricBoogaloo(Posted 2013) [#4]
Platdude Error. Redo from Start.
Your Platdude has a short neck.
-=-=-
Upon closer inspection, that's an optical illusion caused by his oversized hands..


Paul - Taiphoz(Posted 2013) [#5]
lol, I could never draw him as well as you :)


DeltaWolf7(Posted 2013) [#6]
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.


Paul - Taiphoz(Posted 2013) [#7]
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 ?


DeltaWolf7(Posted 2013) [#8]
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.


SLotman(Posted 2013) [#9]
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 :)


therevills(Posted 2013) [#10]
Sorry couldn't help myself, heres a quick example:

http://www.therevillsgames.com/monkey/scrolling/MonkeyGame.html




Xaron(Posted 2013) [#11]
Hey therevills, he can't jump! ;)


therevills(Posted 2013) [#12]
LOL! I know... I was only showing the scrolling part...

I didn't want to add collisions etc. to confuse the issue.


ElectricBoogaloo(Posted 2013) [#13]
*sigh*

...Spheres should be blue, floors are red.. <Alan Partridge>Stop Getting Platdude Wrong!!</Alan Partridge>


Xaron(Posted 2013) [#14]
Haha, nice one!


DeltaWolf7(Posted 2013) [#15]
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.


Paul - Taiphoz(Posted 2013) [#16]
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


ElectricBoogaloo(Posted 2013) [#17]
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!)


DeltaWolf7(Posted 2013) [#18]
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


therevills(Posted 2013) [#19]
<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



DeltaWolf7(Posted 2013) [#20]
You make a very good point. Thank you for pointing this out.


ziggy(Posted 2013) [#21]
Have you considered translating the transformation matrix as it was a camera? That could do it too