Easy 2D Scrooling Help Plz?
BlitzMax Forums/BlitzMax Beginners Area/Easy 2D Scrooling Help Plz?
| ||
Hi, I have a black map(space 10.000 x 10.000) and 2 Objects, the first one(A) beginning on left side on the map and the second(B) on the right side. Like This: ---------------------------------------------------- |A................................................B| |..................................................| |..................................................| |..................................................| |..................................................| |..................................................| |..................................................| |..................................................| |..................................................| |..................................................| |..................................................| |..................................................| |..................................................| ---------------------------------------------------- Now when i move my object A (A.x = A.X+1) everything is ok!! the coords of B are X = 1000 and Y = 0 How i copy the viewport of my object A is the problem. I try: SetViewPort SetOrign But some thing is wrong. Help me and thank's |
| ||
The viewport limits the drawable portion of the screen to a subset of the screen, it doesn't move a larger-than-the-screen image around. For what you're trying to do, people would typically use a tile-system: you'd have to figure out which part of your map is visible, and draw only draw those portions (off-set to the actual screen coordinates) |
| ||
If you use SetOrigin to change the origin, you would then have to draw/copy from 0,0 to width,height and NOT from the A object's X/Y coord. Otherwise, if you keep the origin at 0,0, then you'd want to draw copy from the object's X,Y to X+width,Y+height. I don't think Viewport is going to help you much - it confines the drawing to a smaller section of the screen. It sounds like you want to scroll a game world larger than the screen? |
| ||
Better use something like:type TTiles field x:float, y:float method Draw(wx:float, wy:float) 'wx and wy are starting points of world - local coordinates get added here 'add optional checks wether draw etc. is needed (wx+x +imgwidth>0 and wx+x < screenwidth, same for y and height) DrawOval(wx + x, wy+y, 2,2) end Method End Type global worldX:float = 0.0 global worldY:float = 0.0 global testtile:TTiles = new TTiles testtile.x = 10 testtile.y = 5 repeat cls testtile.draw(worldX, worldY) if keyhit(KEY_LEFT) then worldX :-1 if keyhit(KEY_RIGHT) then worldX :+1 if keyhit(KEY_UP) then worldY :-1 if keyhit(KEY_DOWN) then worldY :+1 flip until AppTerminate() Code is not tested, but will show the principles. bye MB |
| ||
If your new to programming, I'd suggest taking a peek at mappy:- http://www.tilemap.co.uk/mappy.php Then have a looksy at Gmans BlitzMax Mappy module, which is nicely located here:- http://www.gprogs.com/viewtopic.php?id=26 First scroller I ever made was with mappy (Blitz2D), learnt a lot too! :) Dabz |