Path: chuka.playstation.co.uk!news From: "Martin Keates" Newsgroups: scee.yaroze.freetalk.english Subject: Re: negative scrolling on homebrew map routine - need help!! Date: Thu, 15 Mar 2001 00:49:08 -0000 Organization: PlayStation Net Yaroze (SCEE) Lines: 48 Message-ID: <98p3er$rms1@www.netyaroze-europe.com> References: <3AAF7BB2.B427AED3@harbinger.com> NNTP-Posting-Host: modem-211.aluminum.dialup.pol.co.uk X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 > offsetX = (X scroll position (in pixels) / block size X (also in pixels) > ) % background size X (number of blocks going across the map, in this > case 80); So this is equivalent to: offsetX= (x/16)%80; ? This should give ... -2, -1, 0, 0, 1, 2 ... and wrap around ok for both positive and negative numbers (for x values (-48,-33), (-32,-17), (-16,-1), (0,15), (16,31), (32, 47)). > However, If the scroll value is in the range of -blocksize to > (-blocksize * 16) (i.e. in the range of -16 to -256), the offset of the > map comes out in the range of positive 15 - 0! (I need it to be in the > range of 79 to 64). Any negative scroll numbers NOT in this range work > fine!!! This shouldn't happen. > This is mathematically correct (well according to Windows calculator No it isn't (which makes me think maybe I've misunderstood the problem). > having to resort to a large number of complex, error-prone IF > statements? I kinda like the simplicity of the maths as it seems to > work for most cases... (if I reset my scroll positions, that would work Nothing wrong with a few IF statements... You could use: offsetx= (x/16)%80; if (x<0) offsetx += 80 - 1; This fixes the negative offsets being 1 too large. offsetx will be in the range (-79,0) when x is negative. Adding 80-1 puts it in the range (0, 79). (I've put "80 - 1" because 80 is a variable). x needs to be at least a short. offsetx can be a char or larger (as long as background size stays under 128). The block size and background size variables should be ok as chars as well, but you're probably safer with shorts or ints (which are probably the same thing on the yaroze anyway). As for reseting scroll positions - this would work too. You could keep independent coords for each layer for doing parallax. Martin.