game-engine

Can constant key input move a sprite constantly?

我只是一个虾纸丫 提交于 2019-12-01 11:40:05
If I want to move a sprite based on key input in pygame, is there anyway to write code so if I hold down a key, the sprite will keep moving in that direction until I release the key? I've tried this and either the program crashes or I have to repeatedly tap the keys to move the sprite in the intended direction. The OP wants keystate polling, not KEYDOWN events. This example shows using both key events, and key polling. You use one for 'on key press' and the other for 'while held down'. import pygame from pygame.locals import * done = False player.pos = Rect(0,0,10,10) while not done: for event

Can constant key input move a sprite constantly?

大城市里の小女人 提交于 2019-12-01 10:17:53
问题 If I want to move a sprite based on key input in pygame, is there anyway to write code so if I hold down a key, the sprite will keep moving in that direction until I release the key? I've tried this and either the program crashes or I have to repeatedly tap the keys to move the sprite in the intended direction. 回答1: The OP wants keystate polling, not KEYDOWN events. This example shows using both key events, and key polling. You use one for 'on key press' and the other for 'while held down'.

Best way to detect the touched object (moving) from collection in libgdx

好久不见. 提交于 2019-12-01 08:40:16
This is my first attempt in game development. I just started experimenting libgdx and understanding the different aspects of game programming. I looked at the sample projects, i can understand the overall architecture of the libgdx game. But to get hold of the basics of game dynamics, i started playing with low level stuff like how to draw simple shapes, how to move them, how to handle collision like that. So i planned to write a dead simple android game(Its not even a game for sure). This is the idea 1. Create random shapes and make it fly (move) 2. When user touches the shape, it ll explode

Best way to detect the touched object (moving) from collection in libgdx

喜欢而已 提交于 2019-12-01 06:11:00
问题 This is my first attempt in game development. I just started experimenting libgdx and understanding the different aspects of game programming. I looked at the sample projects, i can understand the overall architecture of the libgdx game. But to get hold of the basics of game dynamics, i started playing with low level stuff like how to draw simple shapes, how to move them, how to handle collision like that. So i planned to write a dead simple android game(Its not even a game for sure). This is

Libgdx - How to draw filled rectangle in the right place in scene2d?

ε祈祈猫儿з 提交于 2019-11-30 14:49:00
问题 I am using scene2d. Here is my code: group.addActor(new Actor() { @Override public Actor hit(float arg0, float arg1) {return null;} @Override public void draw(SpriteBatch batch, float arg1) { batch.end(); shapeRenderer.begin(ShapeType.FilledRectangle); shapeRenderer.setColor(Color.RED); shapeRenderer.filledRect(0, 0, 300, 20); shapeRenderer.end(); batch.begin(); } }); The problem is that it draws this rectangular relative to screen (x = 0, y = 0), but I need it to be drawn relative to my

Efficiency of method call in for loop condition

为君一笑 提交于 2019-11-30 13:11:11
I am writing a game engine, in which a set of objects held in a ArrayList are iterated over using a for loop. Obviously, efficiency is rather important, and so I was wondering about the efficiency of the loop. for (String extension : assetLoader.getSupportedExtensions()) { // do stuff with the extension here } Where getSupportedExtension() returns an ArrayList of String s. What I'm wondering is if the method is called every time the loop iterates over a new extension. If so, would it be more efficient to do something like: ArrayList<String> supportedExtensions = ((IAssetLoader<?>) loader)

NSTimer vs CACurrentMediaTime()

喜夏-厌秋 提交于 2019-11-29 23:04:20
So I'm amidst my first iOS game and am struggling with how to go about the best way to integrate object movement. The game relies heavily on fast moving objects and constant, fast user input changes. As such, I'm trying to have object integration and the constraint solver run as quickly and accurately as possible (to minimize user input change in between successive game loop calls). More specifically, I'm unsure of the capabilities of the NSTimer class and CACurrentMediaTime() function. It's hard to test empirically because I'm not sure which have the larger error. For example, using an

What are the “gotchas” when developing an iPhone Game? [closed]

谁都会走 提交于 2019-11-29 20:02:10
Am used to developing business and reference apps. Now I have to do an iPhone game. What tips can you share to help me with: understanding the scope of the project defining the deliverables specifying the game play and other parameters estimating the development effort testing the game A big question, I know. Thanks! The main difference between business apps and games, especially on mobile devices, is the importance of performance. An app that puts up a form and waits for user input probably isn't doing anything in the meantime. A game loop, on the other hand is going all the time and probably

Efficiency of method call in for loop condition

六眼飞鱼酱① 提交于 2019-11-29 18:35:13
问题 I am writing a game engine, in which a set of objects held in a ArrayList are iterated over using a for loop. Obviously, efficiency is rather important, and so I was wondering about the efficiency of the loop. for (String extension : assetLoader.getSupportedExtensions()) { // do stuff with the extension here } Where getSupportedExtension() returns an ArrayList of String s. What I'm wondering is if the method is called every time the loop iterates over a new extension. If so, would it be more

Weird Exception when Livewallpaper is set in Android

拟墨画扇 提交于 2019-11-29 15:30:18
04-24 13:30:59.312: VERBOSE/RenderScript(6044): RS Thread exited 04-24 13:30:59.320: ERROR/libEGL(6044): call to OpenGL ES API with no current context (logged once per thread) 04-24 13:30:59.335: WARN/WallpaperService(6044): Ignoring updateSurface: destroyed 04-24 13:30:59.335: WARN/WindowManager(108): Window android.view.IWindow$Stub$Proxy@408968d0 is already added 04-24 13:30:59.355: DEBUG/dalvikvm(6083): GC_EXTERNAL_ALLOC freed 23K, 52% free 2598K/5379K, external 1625K/2137K, paused 55ms 04-24 13:30:59.425: DEBUG/GLWallpaperService(6083): onSurfaceDestroyed() 04-24 13:30:59.496: WARN