User Tag List

Results 1 to 5 of 5

Thread: Spreading a value based on X,Y coordinates

  1. #1
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCiOS Export Module
    Ramses's Avatar
    Join Date
    Jul 2006
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Spreading a value based on X,Y coordinates

    I'm looking for an quick method to spread a sequential alterable value based on the object's position. For example - the object that is closest to the top of the screen stores 0 in an alterable value, the next one down is 1, next is 2, etc.

    Right now I'm using a fastloop that has an object scan across the screen checking for overlapping objects and then numbering them. It works well on the pc, however, the project is for the iphone and this method is too sluggish for it (way too many fastloops). I'm wondering if there's another less processor intensive way to do this (using only the objects available for iOS export).

  2. #2
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    UltimateWalrus's Avatar
    Join Date
    Jul 2006
    Posts
    824
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Spreading a value based on X,Y coordinates

    Using a fastloop, enter the objects' Y positions into an array along with their fixed values. Then use fastloops to do a bubble sort on the array. Once the bubble sort is done, do a final fastloop that goes through the array and assigns the objects incremental alterable values (retrieving them from their fixed value).

    This should be blindingly fast especially compared to how you're doing it now. If you wanted it even faster, and your play area isn't too huge, you could try some kind of radix sort (using the index of the array as the y position, storing only fixed values, and using the array's other index to store lists of objects that may have the same y position). This is probably how I would do it, actually, although it's a little harder to understand than a bubble sort. This solution would easily be able to handle thousands of objects, the only problem is that it would take up a lot of memory if your play area is large. It would still be fast, though.

  3. #3
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCiOS Export Module
    Ramses's Avatar
    Join Date
    Jul 2006
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Spreading a value based on X,Y coordinates

    Cool. Actually, it's looking like I might not need to do any sorting as I've decided to change things around a little. That said, I messed around with a bubble sort, and although the test I put together was sloppy and basic I can see how useful it would be. Thanks for introducing me to the world of sorting algorithms! The radix sort looks interesting...

  4. #4
    Clicker Multimedia Fusion 2SWF Export Module
    Jacob's Avatar
    Join Date
    Jul 2007
    Location
    Second pixel to the right
    Posts
    3,208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Spreading a value based on X,Y coordinates

    While the discussion is on sorting algorithms, a binary search algorithm works great for collisions. Imagine you are moving at speed 'v'. When you hit an obstacle, move backwards by v/2. If you are still overlapping an obstacle, move backwards again by v/4, else move forwards by v/4. If you are overlapping an obstacle now, move backwards by v/8, else forward by v/8. Repeat this process with v/16, v/32, etc doubling each time. This way instead of pulling yourself out of an obstacle if you're moving at 100px/frame which could take up to 100 loops to do, you can do it in 7 because 2^7 > 100. It's a much more efficent way to handle collisions

  5. #5
    Clicker Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleXNA Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    gkinfinity's Avatar
    Join Date
    May 2011
    Location
    USA
    Posts
    284
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: Spreading a value based on X,Y coordinates

    That's the method I used for drawing the laser in the game I've been working on for the last month actually. It worked really well.

Similar Threads

  1. Replies: 4
    Last Post: 8th June 2012, 12:50 AM
  2. Spreading out a laser
    By N64Mario in forum Multimedia Fusion 2 - Technical Support
    Replies: 6
    Last Post: 13th June 2010, 08:23 AM
  3. Spreading the word
    By Fanotherpg in forum SWF/Flash Export Module Version 2.0
    Replies: 0
    Last Post: 8th March 2010, 02:29 PM
  4. Spreading Values Over New Objects
    By variant in forum Multimedia Fusion 2 - Technical Support
    Replies: 10
    Last Post: 29th November 2009, 04:26 AM
  5. Spreading Values
    By stAtrill in forum The Games Factory 2 - Technical Support
    Replies: 1
    Last Post: 29th January 2007, 04:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •