Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

165 Neutral


  • Rank
  1. I've been getting bogged down by being referred to THE BEST GAME LOOPS EVER which are extremely accurate yet way over the top for what I need. Honestly for what I'm doing it just needs to be a super simple, rigid grid-based movement with somewhat smooth motion when moving between tiles (interpolation).   I was just getting the gist of your frames class, so ignore anything I've said about my own game loop since I don't really know much about them and my implementation is broken anyway. How can I set it up so that it uses frames instead of time? I really just want a game tick which is x length of time, so then I can base everything off of the tick. So like, walking one tile could take 4 ticks, running takes 2 ticks, fade to black when transitioning somewhere could take 10 ticks, auto-regen health starts after idling for 5 ticks.. Basically a solid variable which I can use to control how long everything is taking, which works alongside your nice little class. I would cry happy tears.   I really appreciate the help you're offering by the way, it means a lot. I hope I'm being clear with what I want to achieve so you don't end up explaining things that I have 'no interest in'.
  2. Yeah I think I get the concept now, you're really helping me out. I also like and understand your idea of doing it backwards, since you're always going to end exactly at the destination and any leftover decimal value would be lost at the start / during the movement instead of being left at the end right?   I'm not 100% comfortable with handling time yet, and knowing exactly how fast my program is running. I think if I make a clock then do dt = clock.restart() (which also returns the current elapsed time) in my game loop then I'll know how fast my loop runs? Bah.
  3. So if I understand exactly what's going here..     The values aren't identical but is the theory correct? The player moves left 32px to the targetTile, then move back to the original position -4px, then back etc, to give the effect that the whole time the sprite was just moving at a steady -4px rate? Interpolation is where I get lost off but your walkthrough just now may have made it clear what's going on, with the whole wavey pattern thing.
  4. I think I understand all but one part of the function: sprite.y = tileYPosToScreenYPos(tileY); sprite.x = tileXPosToScreenXPos(tileX);What exactly are these functions doing? Also, FRAMES_FOR_SINGLE_TILE_MOTION would be the number of frames for a single animation cycle and STEPPING_FRAME_DISTANCE would be the width of a tile (16px)?
  5. Sorry for the confusion, you're correct. I just tried to think of some example where the direction would basically choose an operator and an axis (+/-, y/x) and not necessarily hold its own value like your example seems to. Khatharr thanks a ton for posting that class. I'll read over it a few times to make sure I understand.
  6. I have a couple of questions which would help clarify, if you could answer them. I'm really new to this.   So I could just make a Vector2i offset(50, 50) right? endPos = player.pos + offset? This bit confused me. All I'm doing at the minute is:if(keypress == down) player.y += move if(keypress == left) player.x -= move .. kinda thing. I'm not really sure what values for direction you're thinking of here, sorry. See above. I can see how moveVector = distance / duration would work though.
  7. I read the dewitters article and that one other article people always suggest multiple times but a lot of it goes over my head. They explain how the loops work, but since I've never done game loops before, I'm not sure what each variable is supposed to represent. Eg. Skip ticks. It confuses me, so does interpolation.   I'll look that up now, thanks for the suggestion (:
  8. I want to code something similar to how the animate function works with jQuery:   var duration = 500, moveY = "50px", moveX = "70px"; $("#someBox").animate({top: moveY, left: moveX}, duration);   Here I have a box or container which would move right 70px and down 50px, and that animation would take 500 milliseconds. Now to make this relevant to my game, I'm attempting to make Pokémon style, grid-locked movement:   - Press right --- Player loses control --- Character runs through one animation cycle --- Moves right one tile (eg. 16px) --- Happens over 0.5 seconds --- Character stops, player gains control   Right now I can make it so that the character moves in a direction for X amount of time, but it doesn't explicitly move a set amount of pixels per say.. I have a float for moveSpeed and it's just playerPos.x += moveSpeed for the amount of time. I also tried doing playerPos.x += GRID_SIZE, which guarantees that he moves the exact amount of space, but it just teleports and doesn't animate in a transitional movement. It's important that the player sticks strictly to the grid and is never off-centre.   In short, I'd like to make this function:   player.move(direction, distance, duration);   I'm also having trouble with limiting my game loop / making things happen at regular intervals, so this is likely making my problem much harder. Anyway I hope this is clear enough. If not, I'd be happy to try and explain further. Thanks in advance.  
  9. GKANG

    Want improve the flow of my game

    It's hard to say without seeing any code or knowing what exactly you have going into the functions. As a guess though, you could make an Actor class, so each object of that class could be a monster or party member. Then you'd just send in the object by reference to the functions and you have all of those stats / items / etc in just one argument.   I'm not sure what else you'd be sending in?..
  10. GKANG

    So. That Calculus Thing.

    Guys you're all being super helpful. Thanks for the wealth of advice, I've got a much clearer idea of where I'm headed now.
  11. GKANG

    So. That Calculus Thing.

    My main problem is that I'm not sure specifically what I should be learning. I don't want to spend months wasting my time learning "useless math" that I won't really need specifically when programming. I'll definitely check out that link that came early on in this thread though, sounds good.
  12. So here I am, starting to make games in 2D to learn the ropes. However, I feel like I'm kind of stuck because whenever I buy a book / try to learn something like OpenGL I'm always greeted with a lovely equation that is completely alien to me. Now I know that math is pretty much essential to program in 3D and even 2D, but like, HOW essential? Would you guys recommend that I just go head on into math at the same time as programming? I mean, I'm at basic algebra level right now and it aint cutting it. Thoughts?
  13. GKANG

    I often have to go back and revise topics

    This happened with me when I learnt stuff but didn't actually program with it. I tend to read programming books on the bus when I go to school, but unless I actually make use of what I learnt when I get back after work at night, I'll forget a good portion of it. Although I'm guessing your problem was more to do with syntax, not forgetting how the features actually work in the first place?
  14. I made thread after about an hour of trying to figure this out, then I figure it out within 2 minutes of posting. I said it's probably that the files aren't being loaded, well, they weren't. Incorrect filenames.
  15. I'm trying to make an Actor class, where in the constructor I send in a file location for the bitmap. Then I want to use a GetSprite() function to return the BITMAP and use it in the blit() function to draw it to the screen. I get no errors, but the program crashes immediately. I think this is because the image isn't being put into the address where the BITMAP *Sprite points to, but maybe not I dunno. My function call was something like: Actor Guy("image.bmp"); I ended up changing my approach since this ended up just not working, and decided to instead send in an enum. With the enum (eg. INVADER), I was going to use a switch statement in my constructor to assign the correct image there, meaning that there were no mistakes when sending in a file location when creating the object. Here's the code: [source lang="cpp"]class Actor { public: Actor(int a, int b, TEAM Type) : HP(a), Speed(b) { switch(Type) { case INVADER: Sprite = load_bitmap("invader.bmp", 0); break; case PLAYER : Sprite = load_bitmap("player.bmp", 0); break; } } void Move() { PosX += Speed; } void Draw() { blit(Sprite, screen, 0, 0, 0, 0, ScreenHeight, ScreenWidth); } private: BITMAP *Sprite; int PosX, PosY, HP, Speed; };[/source] This just doesn't work, though. If I comment out the call to Draw() in my main loop the program runs and exits fine. When I try to Draw though, it crashes just like before. What's going on, I'm kinda lost.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!