不使用游戏引擎开发简单游戏?

发布于 2024-09-17 20:37:49 字数 393 浏览 3 评论 0原文

我正在尝试开发一个简单的足球游戏,包括点球,其中我必须为从球员到球门柱制作动画......之前我一直在使用简单的动画使用计时器添加到球图像的轴,以便它从一个点移动到另一个点..但我没有得到预期的结果,因为动画不是那么流畅...所以我正在考虑使用游戏引擎...由于我是一个新程序员,我对游戏引擎一无所知,也找不到任何有关box2d或花栗鼠或麻雀等引擎的适当文档 >..我还考虑使用 UIView 动画 而不是早期的动画,因为我认为这样可以实现更好的动画,而无需在游戏引擎上摸索......我要去没有这个问题,所以如果有人能对我的这个问题有所了解,那就太好了???

I am trying to develop a simple soccer game including penalty kicks in which i have to animate a ball from player to the goal post...earlier i have been using simple animations using a timer to add to the axis of ball image so that it moves from 1 point to another..but i did not have the desired result as animations were not that smooth...So i was thinking of using a Game Engine...Since i am a New Programmer i have no idea about game engine and neither can i find any proper documentation regarding engines like box2d or chipmunks or sparrow..i was also thinking of using UIView animations instead of the earlier animations as i think that can achieve far better animations without scratching my head trying to work on a game engine....I am going no where with this so it would be really great if someone can put some light on this issue of mine???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你在看孤独的风景 2024-09-24 20:37:49

使用UIView动画,如:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3]; // or whatever time
object.center=CGPointMake(object.center.x+2, object.center.y+4);
// or whatever
[UIView commitAnimations];

您还应该使用具有相同间隔的NSTimer,以便您可以顺利地调用动画。

NSTimer *timer=[NSTimer scheduledTimerWithTimeInterval:0.3 target: self 
selector:@selector(animation) userInfo: nil repeats: YES];

然后,实现该方法:

- (void)animation {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3]; // or whatever time
    object.center=CGPointMake(object.center.x+5, object.center.y+7);
    // or whatever
    [UIView commitAnimations];    
}

这应该适用于任何简单的游戏。

Use UIView animations, like in:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3]; // or whatever time
object.center=CGPointMake(object.center.x+2, object.center.y+4);
// or whatever
[UIView commitAnimations];

You should also use an NSTimer with the same interval so that you can call animations smoothly.

NSTimer *timer=[NSTimer scheduledTimerWithTimeInterval:0.3 target: self 
selector:@selector(animation) userInfo: nil repeats: YES];

Then, implement the method:

- (void)animation {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3]; // or whatever time
    object.center=CGPointMake(object.center.x+5, object.center.y+7);
    // or whatever
    [UIView commitAnimations];    
}

This should do for ANY simple game.

风蛊 2024-09-24 20:37:49

当您用 cocos2d 标记问题时,我猜您正在使用或计划使用它。动画 CCSprites 很容易,例如在这个游戏 https://github.com/ haqu/tweejump

在您的 onEnter 实现中,只需调用
[self ScheduleUpdate]

这将定期调用 update: ,您可以在其中进行绘图,

- (void)update:(ccTime)dt {
    ball_pos.x += ball_velocity.x * dt;
    ball_pos.y += ball_velocity.y * dt;
    ball_velocity.x += ball_acc.x * dt;
    ball_velocity.y += ball_acc.y * dt;

    //game logic goes here (collision, goal, ...)

    ball.position = ball_position;
}

这将处理球的平滑运动。 ball_posball_velocityball_accvvCertex2F

您甚至可能不需要处理加速度,只需在有人击球时给球一个脉冲(即提高速度)。

您可能还需要一些阻尼来减慢球的速度。你可以通过降低每一步的速度来做到这一点

As you tagged the question with cocos2d, I guess you're using it, or planning to. Animating CCSprites is easy as you can see e.g. in this game https://github.com/haqu/tweejump.

In your onEnter implementation, just call
[self scheduleUpdate]

this will call routinely the update: where you can do your drawing

- (void)update:(ccTime)dt {
    ball_pos.x += ball_velocity.x * dt;
    ball_pos.y += ball_velocity.y * dt;
    ball_velocity.x += ball_acc.x * dt;
    ball_velocity.y += ball_acc.y * dt;

    //game logic goes here (collision, goal, ...)

    ball.position = ball_position;
}

That'll handle smooth movement of the ball. ball_pos, ball_velocity and ball_acc being vvCertex2F.

You probably don't even have to deal with acceleration, and only give an impulse to the ball when someone hit it (i.e. bump the velocity).

You probably also want some damping to slow the ball down. you do it by reducing the velocity at every step

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文