Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8017989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:00:09+00:00 2026-06-04T21:00:09+00:00

I wrote a demo application that works perfectly on the simulator, but when I

  • 0

I wrote a demo application that works perfectly on the simulator, but when I put it on an actual device, the dice skip around. Here is a video as an example. After I restart the app, the animations are fine. The errors happened about 1 minute of repeatadly hitting the roll button.

http://youtu.be/N1k1QPa1brg

The code is all live at:

https://github.com/rnystrom/MartionDemo

How I make the animation in the dice object:

CCAnimation *anim = [CCAnimation animationWithFrames:frames delay:delay];
if(self.sprite){
    // Animate the sprite
    [self.sprite runAction:[CCAnimate actionWithAnimation:anim restoreOriginalFrame:NO]];
}

The rolling function:

-(void)roll
{
    // Array that contains the new positions of dice
    // Predetermine the position, check if that will be on top of other dice
    NSMutableArray* checkPos = [NSMutableArray array];

    for(Dice* d in rollDiceArray){
        [d resetPosition];    

        // Select a random position within bounds
        NSInteger x = arc4random() % 600 + 50;
        NSInteger y = arc4random() % 600 + 150;
        CGPoint location = CGPointMake(x, y);

        // Check if die will touch other dice
        while (! [self checkPositionWithPoint:location array:checkPos]) {
            // If position overlaps another die, get a new position
            // PROBLEM: This is O(infinity)!
            x = arc4random() % 600 + 50;
            y = arc4random() % 600 + 150;
            location = CGPointMake(x, y);
        }

        // If position does not overlap, add it to array of positions to be checked
        [checkPos addObject:[NSArray arrayWithObjects:[NSNumber numberWithInteger:x], [NSNumber numberWithInteger:y], nil]];

        // Animate the dice to a position
        // Addition in the switch is for some randomness and correcting the animation's timing offset
        NSInteger numberFrames;
        float frameRate;
        float mod = (float)(arc4random() % 60) / 100;
        switch (d.fileNum) {
            case 0:
                numberFrames = kRayFrames;
                frameRate = numberFrames/24 + mod;
                break;
            case 1:
                numberFrames = kRayFrames;
                frameRate = numberFrames/24 + mod - 0.4;
                break;
            case 2:
                numberFrames = kTankFrames;
                frameRate = numberFrames/24 + mod + 0.2;
                break;
            case 3:
                numberFrames = kChickenFrames;
                frameRate = numberFrames/24 + mod;
                break;
            case 4:
                numberFrames = kCowFrames;
                frameRate = numberFrames/24 + mod + 0.2;
                break;
            case 5:
                numberFrames = kHumanFrames;
                frameRate = numberFrames/24;
                break;
            default:
                break;
        }

        id action = [CCMoveTo actionWithDuration:frameRate position:location];
        id ease = [CCEaseOut actionWithAction:action rate:4.0];
        [d.sprite runAction:ease];
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:00:11+00:00Added an answer on June 4, 2026 at 9:00 pm

    This turned out to be a performSelector:afterDelay: issue. I resolved it by adding some padding time to my delay so things did not happen simultaneously.

    I also put in a block so that action can only be made after the animations were finished. There seems to be some sort of issue when interrupting a CCMoveTo-esque animation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a simple Tkinter based Python application that reads text from a serial
I have a small demo executable wrote in C++ that depends only on one
I wrote a program that forks some processes with fork(). I want to kill
I wrote a routine to remove pounds and ids from sharepoint fields that worked
I wrote an application using ASP.NET MVC, in this application I have an Index
I wrote a C program in Linux that mallocs memory, ran it in a
I wrote a trigger that updates local table and similar table on linked server.
I need to knock up a very quick prototype/proof of concept application to demo
I'd like to be able to write an application in HTML5 that is similar
i have been working on a small demo and i wrote a function which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.